Mercurial > piecrust2
comparison piecrust/commands/builtin/baking.py @ 194:5d8351cb32d8
showrecord: Also show the pipeline record.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sun, 11 Jan 2015 23:04:23 -0800 |
parents | c2acf5f31936 |
children | aaf08277b96d |
comparison
equal
deleted
inserted
replaced
193:c2acf5f31936 | 194:5d8351cb32d8 |
---|---|
7 from piecrust.baking.baker import Baker | 7 from piecrust.baking.baker import Baker |
8 from piecrust.baking.records import BakeRecord | 8 from piecrust.baking.records import BakeRecord |
9 from piecrust.chefutil import format_timed | 9 from piecrust.chefutil import format_timed |
10 from piecrust.commands.base import ChefCommand | 10 from piecrust.commands.base import ChefCommand |
11 from piecrust.processing.base import ProcessorPipeline | 11 from piecrust.processing.base import ProcessorPipeline |
12 from piecrust.processing.records import ( | |
13 ProcessorPipelineRecord, FLAG_OVERRIDEN) | |
12 | 14 |
13 | 15 |
14 logger = logging.getLogger(__name__) | 16 logger = logging.getLogger(__name__) |
15 | 17 |
16 | 18 |
110 help="A pattern that will be used to filter the relative path " | 112 help="A pattern that will be used to filter the relative path " |
111 "of entries to show.") | 113 "of entries to show.") |
112 | 114 |
113 def run(self, ctx): | 115 def run(self, ctx): |
114 out_dir = ctx.args.output or os.path.join(ctx.app.root_dir, '_counter') | 116 out_dir = ctx.args.output or os.path.join(ctx.app.root_dir, '_counter') |
115 record_cache = ctx.app.cache.getCache('baker') | 117 record_name = (hashlib.md5(out_dir.encode('utf8')).hexdigest() + |
116 record_name = hashlib.md5(out_dir.encode('utf8')).hexdigest() + '.record' | 118 '.record') |
117 if not record_cache.has(record_name): | |
118 raise Exception("No record has been created for this output path. " | |
119 "Did you bake there yet?") | |
120 | 119 |
121 pattern = None | 120 pattern = None |
122 if ctx.args.path: | 121 if ctx.args.path: |
123 pattern = '*%s*' % ctx.args.path.strip('*') | 122 pattern = '*%s*' % ctx.args.path.strip('*') |
123 | |
124 record_cache = ctx.app.cache.getCache('baker') | |
125 if not record_cache.has(record_name): | |
126 raise Exception("No record has been created for this output path. " | |
127 "Did you bake there yet?") | |
124 | 128 |
125 record = BakeRecord.load(record_cache.getCachePath(record_name)) | 129 record = BakeRecord.load(record_cache.getCachePath(record_name)) |
126 logging.info("Bake record for: %s" % record.out_dir) | 130 logging.info("Bake record for: %s" % record.out_dir) |
127 logging.info("Last baked: %s" % | 131 logging.info("Last baked: %s" % |
128 datetime.datetime.fromtimestamp(record.bake_time)) | 132 datetime.datetime.fromtimestamp(record.bake_time)) |
143 for p in entry.out_paths]) | 147 for p in entry.out_paths]) |
144 logging.info(" used srcs: %s" % entry.used_source_names) | 148 logging.info(" used srcs: %s" % entry.used_source_names) |
145 if entry.errors: | 149 if entry.errors: |
146 logging.error(" errors: %s" % entry.errors) | 150 logging.error(" errors: %s" % entry.errors) |
147 | 151 |
152 record_cache = ctx.app.cache.getCache('proc') | |
153 if not record_cache.has(record_name): | |
154 return | |
155 | |
156 record = ProcessorPipelineRecord.load( | |
157 record_cache.getCachePath(record_name)) | |
158 logging.info("") | |
159 logging.info("Processing record for: %s" % record.out_dir) | |
160 logging.info("Last baked: %s" % | |
161 datetime.datetime.fromtimestamp(record.process_time)) | |
162 logging.info("Entries:") | |
163 for entry in record.entries: | |
164 if pattern: | |
165 if not fnmatch.fnmatch(entry.rel_input, pattern): | |
166 continue | |
167 flags = '' | |
168 if entry.flags & FLAG_OVERRIDEN: | |
169 flags += 'overriden' | |
170 logger.info(" - ") | |
171 logger.info(" path: %s" % entry.rel_input) | |
172 logger.info(" out paths: %s" % entry.rel_outputs) | |
173 logger.info(" flags: %s" % flags) | |
174 logger.info(" proc tree: %s" % format_proc_tree( | |
175 entry.proc_tree, 14*' ')) | |
176 if entry.errors: | |
177 logger.error(" errors: %s" % entry.errors) | |
178 | |
179 | |
180 def format_proc_tree(tree, margin='', level=0): | |
181 name, children = tree | |
182 res = '%s%s%s' % (margin if level > 0 else '', level * ' ', name) | |
183 if children: | |
184 for c in children: | |
185 res += format_proc_tree(c, margin, level + 1) | |
186 return res | |
187 |