Mercurial > piecrust2
comparison piecrust/baking/records.py @ 698:33ab9badfd7a
render: Change how we store render passes info.
Previously we used a dictionary with integers as keys, which doesn't go well
with JSON serialization. Now replace with an array of fixed length with items
that are `None` by default.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Wed, 23 Mar 2016 16:39:22 -0700 |
parents | 9ae9390192da |
children | ab5c6a8ae90a |
comparison
equal
deleted
inserted
replaced
697:9e5393fcfab2 | 698:33ab9badfd7a |
---|---|
19 key += taxonomy_info.term | 19 key += taxonomy_info.term |
20 return hashlib.md5(key.encode('utf8')).hexdigest() | 20 return hashlib.md5(key.encode('utf8')).hexdigest() |
21 | 21 |
22 | 22 |
23 class BakeRecord(Record): | 23 class BakeRecord(Record): |
24 RECORD_VERSION = 17 | 24 RECORD_VERSION = 18 |
25 | 25 |
26 def __init__(self): | 26 def __init__(self): |
27 super(BakeRecord, self).__init__() | 27 super(BakeRecord, self).__init__() |
28 self.out_dir = None | 28 self.out_dir = None |
29 self.bake_time = None | 29 self.bake_time = None |
43 def __init__(self, out_uri, out_path): | 43 def __init__(self, out_uri, out_path): |
44 self.out_uri = out_uri | 44 self.out_uri = out_uri |
45 self.out_path = out_path | 45 self.out_path = out_path |
46 self.flags = self.FLAG_NONE | 46 self.flags = self.FLAG_NONE |
47 self.errors = [] | 47 self.errors = [] |
48 self.render_info = None | 48 self.render_info = [None, None] # Same length as RENDER_PASSES |
49 | 49 |
50 @property | 50 @property |
51 def was_clean(self): | 51 def was_clean(self): |
52 return (self.flags & self.FLAG_BAKED) == 0 and len(self.errors) == 0 | 52 return (self.flags & self.FLAG_BAKED) == 0 and len(self.errors) == 0 |
53 | 53 |
58 @property | 58 @property |
59 def was_baked_successfully(self): | 59 def was_baked_successfully(self): |
60 return self.was_baked and len(self.errors) == 0 | 60 return self.was_baked and len(self.errors) == 0 |
61 | 61 |
62 def anyPass(self, func): | 62 def anyPass(self, func): |
63 assert self.render_info is not None | 63 for pinfo in self.render_info: |
64 for p, pinfo in self.render_info.items(): | 64 if pinfo and func(pinfo): |
65 if func(pinfo): | |
66 return True | 65 return True |
67 return False | 66 return False |
68 | 67 |
69 def copyRenderInfo(self): | 68 def copyRenderInfo(self): |
70 assert self.render_info | |
71 return copy.deepcopy(self.render_info) | 69 return copy.deepcopy(self.render_info) |
72 | 70 |
73 | 71 |
74 class TaxonomyInfo(object): | 72 class TaxonomyInfo(object): |
75 def __init__(self, taxonomy_name, source_name, term): | 73 def __init__(self, taxonomy_name, source_name, term): |
140 yield from o.errors | 138 yield from o.errors |
141 | 139 |
142 def getAllUsedSourceNames(self): | 140 def getAllUsedSourceNames(self): |
143 res = set() | 141 res = set() |
144 for o in self.subs: | 142 for o in self.subs: |
145 if o.render_info is not None: | 143 for pinfo in o.render_info: |
146 for p, pinfo in o.render_info.items(): | 144 if pinfo: |
147 res |= pinfo.used_source_names | 145 res |= pinfo.used_source_names |
148 return res | 146 return res |
149 | 147 |
150 def getAllUsedTaxonomyTerms(self): | 148 def getAllUsedTaxonomyTerms(self): |
151 res = set() | 149 res = set() |
152 for o in self.subs: | 150 for o in self.subs: |
153 if o.render_info is not None: | 151 for pinfo in o.render_info: |
154 for p, pinfo in o.render_info.items(): | 152 if pinfo: |
155 res |= pinfo.used_taxonomy_terms | 153 res |= pinfo.used_taxonomy_terms |
156 return res | 154 return res |
157 | 155 |
158 | 156 |
159 class TransitionalBakeRecord(TransitionalRecord): | 157 class TransitionalBakeRecord(TransitionalRecord): |