comparison piecrust/baking/records.py @ 415:0e9a94b7fdfa

bake: Improve bake record information. * Store things in the bake record that require less interaction between the master process and the workers. For instance, don't store the paginator object in the render pass info -- instead, just store whether pagination was used, and whether it had more items. * Simplify information passing between workers and bake passes by saving the rendering info to the JSON cache. This means the "render first sub" job doesn't have to return anything except errors now. * Add more performance counter info.
author Ludovic Chabant <ludovic@chabant.com>
date Sat, 20 Jun 2015 19:23:16 -0700
parents e7b865f8f335
children 61d606fbc313
comparison
equal deleted inserted replaced
414:c4b3a7fd2f87 415:0e9a94b7fdfa
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
30 self.baked_count = {}
30 self.timers = None 31 self.timers = None
31 self.success = True 32 self.success = True
32
33
34 class BakePassInfo(object):
35 def __init__(self):
36 self.used_source_names = set()
37 self.used_taxonomy_terms = set()
38 33
39 34
40 class SubPageBakeInfo(object): 35 class SubPageBakeInfo(object):
41 FLAG_NONE = 0 36 FLAG_NONE = 0
42 FLAG_BAKED = 2**0 37 FLAG_BAKED = 2**0
48 def __init__(self, out_uri, out_path): 43 def __init__(self, out_uri, out_path):
49 self.out_uri = out_uri 44 self.out_uri = out_uri
50 self.out_path = out_path 45 self.out_path = out_path
51 self.flags = self.FLAG_NONE 46 self.flags = self.FLAG_NONE
52 self.errors = [] 47 self.errors = []
53 self.render_passes = {} 48 self.render_info = None
54 49
55 @property 50 @property
56 def was_clean(self): 51 def was_clean(self):
57 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
58 53
62 57
63 @property 58 @property
64 def was_baked_successfully(self): 59 def was_baked_successfully(self):
65 return self.was_baked and len(self.errors) == 0 60 return self.was_baked and len(self.errors) == 0
66 61
67 def collapseRenderPasses(self, other): 62 def anyPass(self, func):
68 for p, pinfo in self.render_passes.items(): 63 assert self.render_info is not None
69 if p not in other.render_passes: 64 for p, pinfo in self.render_info.items():
70 other.render_passes[p] = copy.deepcopy(pinfo) 65 if func(pinfo):
71 66 return True
72 67 return False
73 class PageBakeInfo(object): 68
74 def __init__(self): 69 def copyRenderInfo(self):
75 self.subs = [] 70 assert self.render_info
76 self.assets = [] 71 return copy.deepcopy(self.render_info)
77
78
79 class FirstRenderInfo(object):
80 def __init__(self):
81 self.assets = []
82 self.used_pagination = False
83 self.pagination_has_more = False
84 72
85 73
86 class TaxonomyInfo(object): 74 class TaxonomyInfo(object):
87 def __init__(self, taxonomy_name, source_name, term): 75 def __init__(self, taxonomy_name, source_name, term):
88 self.taxonomy_name = taxonomy_name 76 self.taxonomy_name = taxonomy_name
106 self.path = path 94 self.path = path
107 self.taxonomy_info = taxonomy_info 95 self.taxonomy_info = taxonomy_info
108 self.flags = self.FLAG_NONE 96 self.flags = self.FLAG_NONE
109 self.config = None 97 self.config = None
110 self.errors = [] 98 self.errors = []
111 self.bake_info = None 99 self.subs = []
112 self.first_render_info = None
113 100
114 @property 101 @property
115 def path_mtime(self): 102 def path_mtime(self):
116 return os.path.getmtime(self.path) 103 return os.path.getmtime(self.path)
117 104
119 def was_overriden(self): 106 def was_overriden(self):
120 return (self.flags & self.FLAG_OVERRIDEN) != 0 107 return (self.flags & self.FLAG_OVERRIDEN) != 0
121 108
122 @property 109 @property
123 def num_subs(self): 110 def num_subs(self):
124 if self.bake_info is None: 111 return len(self.subs)
125 return 0
126 return len(self.bake_info.subs)
127 112
128 @property 113 @property
129 def was_any_sub_baked(self): 114 def was_any_sub_baked(self):
130 if self.bake_info is not None: 115 for o in self.subs:
131 for o in self.bake_info.subs: 116 if o.was_baked:
132 if o.was_baked: 117 return True
133 return True
134 return False 118 return False
135 119
136 @property 120 @property
137 def subs(self): 121 def all_assets(self):
138 if self.bake_info is not None: 122 for sub in self.subs:
139 return self.bake_info.subs 123 yield from sub.assets
140 return []
141 124
142 @property 125 @property
143 def has_any_error(self): 126 def has_any_error(self):
144 if len(self.errors) > 0: 127 if len(self.errors) > 0:
145 return True 128 return True
146 if self.bake_info is not None: 129 for o in self.subs:
147 for o in self.bake_info.subs: 130 if len(o.errors) > 0:
148 if len(o.errors) > 0: 131 return True
149 return True
150 return False 132 return False
151 133
152 def getSub(self, sub_index): 134 def getSub(self, sub_index):
153 if self.bake_info is None: 135 return self.subs[sub_index - 1]
154 raise Exception("No bake info available on this entry.")
155 return self.bake_info.subs[sub_index - 1]
156 136
157 def getAllErrors(self): 137 def getAllErrors(self):
158 yield from self.errors 138 yield from self.errors
159 if self.bake_info is not None: 139 for o in self.subs:
160 for o in self.bake_info.subs: 140 yield from o.errors
161 yield from o.errors
162 141
163 def getAllUsedSourceNames(self): 142 def getAllUsedSourceNames(self):
164 res = set() 143 res = set()
165 if self.bake_info is not None: 144 for o in self.subs:
166 for o in self.bake_info.subs: 145 if o.render_info is not None:
167 for p, pinfo in o.render_passes.items(): 146 for p, pinfo in o.render_info.items():
168 res |= pinfo.used_source_names 147 res |= pinfo.used_source_names
169 return res 148 return res
170 149
171 def getAllUsedTaxonomyTerms(self): 150 def getAllUsedTaxonomyTerms(self):
172 res = set() 151 res = set()
173 if self.bake_info is not None: 152 for o in self.subs:
174 for o in self.bake_info.subs: 153 if o.render_info is not None:
175 for p, pinfo in o.render_passes.items(): 154 for p, pinfo in o.render_info.items():
176 res |= pinfo.used_taxonomy_terms 155 res |= pinfo.used_taxonomy_terms
177 return res 156 return res
178 157
179 158
180 class TransitionalBakeRecord(TransitionalRecord): 159 class TransitionalBakeRecord(TransitionalRecord):