Mercurial > piecrust2
comparison piecrust/records.py @ 91:e88e330eb8dc
Improvements to incremental baking and cache invalidating.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Fri, 05 Sep 2014 00:42:13 -0700 |
parents | 343d08ef5668 |
children | 133845647083 |
comparison
equal
deleted
inserted
replaced
90:e293f08d954e | 91:e88e330eb8dc |
---|---|
1 import os | 1 import os |
2 import os.path | 2 import os.path |
3 import pickle | |
3 import logging | 4 import logging |
4 from piecrust import APP_VERSION | |
5 from piecrust.events import Event | 5 from piecrust.events import Event |
6 | |
7 try: | |
8 import pickle as pickle | |
9 except ImportError: | |
10 import pickle | |
11 | 6 |
12 | 7 |
13 logger = logging.getLogger(__name__) | 8 logger = logging.getLogger(__name__) |
14 | 9 |
15 | 10 |
16 class Record(object): | 11 class Record(object): |
17 VERSION = 1 | |
18 | |
19 def __init__(self): | 12 def __init__(self): |
20 self.app_version = None | |
21 self.record_version = None | |
22 self.entries = [] | 13 self.entries = [] |
23 self.entry_added = Event() | 14 self.entry_added = Event() |
24 | |
25 def isVersionMatch(self): | |
26 return (self.app_version == APP_VERSION and | |
27 self.record_version == self.VERSION) | |
28 | 15 |
29 def addEntry(self, entry): | 16 def addEntry(self, entry): |
30 self.entries.append(entry) | 17 self.entries.append(entry) |
31 self.entry_added.fire(entry) | 18 self.entry_added.fire(entry) |
32 | 19 |
41 def __getstate__(self): | 28 def __getstate__(self): |
42 odict = self.__dict__.copy() | 29 odict = self.__dict__.copy() |
43 del odict['entry_added'] | 30 del odict['entry_added'] |
44 return odict | 31 return odict |
45 | 32 |
33 def __setstate__(self, state): | |
34 for k, v in state.items(): | |
35 setattr(self, k, v) | |
36 self.entry_added = Event() | |
37 | |
46 @staticmethod | 38 @staticmethod |
47 def load(path): | 39 def load(path): |
48 logger.debug("Loading bake record from: %s" % path) | 40 logger.debug("Loading bake record from: %s" % path) |
49 with open(path, 'rb') as fp: | 41 with open(path, 'rb') as fp: |
50 return pickle.load(fp) | 42 return pickle.load(fp) |