comparison piecrust/commands/builtin/baking.py @ 92:0dd43c5f5484

More options for the `showrecord` command.
author Ludovic Chabant <ludovic@chabant.com>
date Fri, 05 Sep 2014 00:42:28 -0700
parents efd0d3bacc9e
children 133845647083
comparison
equal deleted inserted replaced
91:e88e330eb8dc 92:0dd43c5f5484
1 import os.path 1 import os.path
2 import logging 2 import logging
3 import hashlib 3 import hashlib
4 import fnmatch
5 import datetime
4 from piecrust.baking.baker import Baker 6 from piecrust.baking.baker import Baker
5 from piecrust.baking.records import BakeRecord 7 from piecrust.baking.records import BakeRecord
6 from piecrust.commands.base import ChefCommand 8 from piecrust.commands.base import ChefCommand
7 9
8 10
57 super(ShowRecordCommand, self).__init__() 59 super(ShowRecordCommand, self).__init__()
58 self.name = 'showrecord' 60 self.name = 'showrecord'
59 self.description = "Shows the bake record for a given output directory." 61 self.description = "Shows the bake record for a given output directory."
60 62
61 def setupParser(self, parser, app): 63 def setupParser(self, parser, app):
62 parser.add_argument('output', 64 parser.add_argument('-o', '--output',
63 help="The output directory for which to show the bake record " 65 help="The output directory for which to show the bake record "
64 "(defaults to `_counter`)", 66 "(defaults to `_counter`)",
65 nargs='?') 67 nargs='?')
68 parser.add_argument('-p', '--path',
69 help="A pattern that will be used to filter the relative path "
70 "of entries to show.")
66 71
67 def run(self, ctx): 72 def run(self, ctx):
68 out_dir = ctx.args.output or os.path.join(ctx.app.root_dir, '_counter') 73 out_dir = ctx.args.output or os.path.join(ctx.app.root_dir, '_counter')
69 record_cache = ctx.app.cache.getCache('baker') 74 record_cache = ctx.app.cache.getCache('baker')
70 record_name = hashlib.md5(out_dir.encode('utf8')).hexdigest() + '.record' 75 record_name = hashlib.md5(out_dir.encode('utf8')).hexdigest() + '.record'
71 if not record_cache.has(record_name): 76 if not record_cache.has(record_name):
72 raise Exception("No record has been created for this output path. " 77 raise Exception("No record has been created for this output path. "
73 "Did you bake there yet?") 78 "Did you bake there yet?")
74 79
80 pattern = None
81 if ctx.args.path:
82 pattern = '*%s*' % ctx.args.path.strip('*')
83
75 record = BakeRecord.load(record_cache.getCachePath(record_name)) 84 record = BakeRecord.load(record_cache.getCachePath(record_name))
76 logging.info("Bake record for: %s" % record.out_dir) 85 logging.info("Bake record for: %s" % record.out_dir)
77 logging.info("Last baked: %s" % record.bake_time) 86 logging.info("Last baked: %s" %
87 datetime.datetime.fromtimestamp(record.bake_time))
78 logging.info("Entries:") 88 logging.info("Entries:")
79 for entry in record.entries: 89 for entry in record.entries:
90 if pattern:
91 rel_path = os.path.relpath(entry.path, ctx.app.root_dir)
92 if not fnmatch.fnmatch(entry.rel_path, pattern):
93 continue
80 logging.info(" - ") 94 logging.info(" - ")
81 logging.info(" path: %s" % entry.path) 95 logging.info(" path: %s" % entry.path)
82 logging.info(" source: %s" % entry.source_name) 96 logging.info(" spec: %s:%s" % (entry.source_name, entry.rel_path))
83 logging.info(" config: %s" % entry.config) 97 logging.info(" taxonomy: %s:%s" % (entry.taxonomy_name, entry.taxonomy_term))
84 logging.info(" base URL: %s" % entry.uri) 98 logging.info(" config: %s" % entry.config)
85 logging.info(" outputs: %s" % entry.out_paths) 99 logging.info(" out URLs: %s" % entry.out_uris)
100 logging.info(" out paths: %s" % entry.out_paths)
101 logging.info(" used srcs: %s" % entry.used_source_names)
86 102