comparison piecrust/records.py @ 3:f485ba500df3

Gigantic change to basically make PieCrust 2 vaguely functional. - Serving works, with debug window. - Baking works, multi-threading, with dependency handling. - Various things not implemented yet.
author Ludovic Chabant <ludovic@chabant.com>
date Sun, 10 Aug 2014 23:43:16 -0700
parents
children 474c9882decf
comparison
equal deleted inserted replaced
2:40fa08b261b9 3:f485ba500df3
1 import os
2 import os.path
3 import logging
4 from piecrust import APP_VERSION
5 from piecrust.events import Event
6
7 try:
8 import cPickle as pickle
9 except ImportError:
10 import pickle
11
12
13 logger = logging.getLogger(__name__)
14
15
16 class Record(object):
17 VERSION = 1
18
19 def __init__(self):
20 self.app_version = None
21 self.record_version = None
22 self.entries = []
23 self.entry_added = Event()
24
25 def isVersionMatch(self):
26 return (self.app_version == APP_VERSION and
27 self.record_version == self.VERSION)
28
29 def addEntry(self, entry):
30 self.entries.append(entry)
31 self.entry_added.fire(entry)
32
33 def save(self, path):
34 path_dir = os.path.dirname(path)
35 if not os.path.isdir(path_dir):
36 os.makedirs(path_dir, 0755)
37
38 with open(path, 'w') as fp:
39 pickle.dump(self, fp, pickle.HIGHEST_PROTOCOL)
40
41 def __getstate__(self):
42 odict = self.__dict__.copy()
43 del odict['entry_added']
44 return odict
45
46 @staticmethod
47 def load(path):
48 logger.debug("Loading bake record from: %s" % path)
49 with open(path, 'r') as fp:
50 return pickle.load(fp)
51