comparison piecrust/commands/builtin/baking.py @ 192:4c0ab0b044fe

cosmetic: Fix some PEP8 issues.
author Ludovic Chabant <ludovic@chabant.com>
date Sun, 11 Jan 2015 23:03:12 -0800
parents bc63dc20baa0
children c2acf5f31936
comparison
equal deleted inserted replaced
191:308d5180bf81 192:4c0ab0b044fe
19 super(BakeCommand, self).__init__() 19 super(BakeCommand, self).__init__()
20 self.name = 'bake' 20 self.name = 'bake'
21 self.description = "Bakes your website into static HTML files." 21 self.description = "Bakes your website into static HTML files."
22 22
23 def setupParser(self, parser, app): 23 def setupParser(self, parser, app):
24 parser.add_argument('-o', '--output', 24 parser.add_argument(
25 '-o', '--output',
25 help="The directory to put all the baked HTML files into " 26 help="The directory to put all the baked HTML files into "
26 "(defaults to `_counter`)") 27 "(defaults to `_counter`)")
27 parser.add_argument('-f', '--force', 28 parser.add_argument(
29 '-f', '--force',
28 help="Force re-baking the entire website.", 30 help="Force re-baking the entire website.",
29 action='store_true') 31 action='store_true')
30 parser.add_argument('--portable', 32 parser.add_argument(
33 '--portable',
31 help="Uses relative paths for all URLs.", 34 help="Uses relative paths for all URLs.",
32 action='store_true') 35 action='store_true')
33 parser.add_argument('--no-assets', 36 parser.add_argument(
37 '--no-assets',
34 help="Don't process assets (only pages).", 38 help="Don't process assets (only pages).",
35 action='store_true') 39 action='store_true')
36 40
37 def run(self, ctx): 41 def run(self, ctx):
38 if ctx.args.portable: 42 if ctx.args.portable:
51 # Bake the assets. 55 # Bake the assets.
52 if not ctx.args.no_assets: 56 if not ctx.args.no_assets:
53 self._bakeAssets(ctx, out_dir) 57 self._bakeAssets(ctx, out_dir)
54 58
55 # All done. 59 # All done.
56 logger.info('-------------------------'); 60 logger.info('-------------------------')
57 logger.info(format_timed(start_time, 'done baking')); 61 logger.info(format_timed(start_time, 'done baking'))
58 return 0 62 return 0
59 except Exception as ex: 63 except Exception as ex:
60 if ctx.app.debug: 64 if ctx.app.debug:
61 logger.exception(ex) 65 logger.exception(ex)
62 else: 66 else:
86 force_patterns=force_patterns, 90 force_patterns=force_patterns,
87 num_workers=num_workers) 91 num_workers=num_workers)
88 proc.run() 92 proc.run()
89 93
90 94
91
92 class ShowRecordCommand(ChefCommand): 95 class ShowRecordCommand(ChefCommand):
93 def __init__(self): 96 def __init__(self):
94 super(ShowRecordCommand, self).__init__() 97 super(ShowRecordCommand, self).__init__()
95 self.name = 'showrecord' 98 self.name = 'showrecord'
96 self.description = "Shows the bake record for a given output directory." 99 self.description = ("Shows the bake record for a given output "
100 "directory.")
97 101
98 def setupParser(self, parser, app): 102 def setupParser(self, parser, app):
99 parser.add_argument('-o', '--output', 103 parser.add_argument(
104 '-o', '--output',
100 help="The output directory for which to show the bake record " 105 help="The output directory for which to show the bake record "
101 "(defaults to `_counter`)", 106 "(defaults to `_counter`)",
102 nargs='?') 107 nargs='?')
103 parser.add_argument('-p', '--path', 108 parser.add_argument(
109 '-p', '--path',
104 help="A pattern that will be used to filter the relative path " 110 help="A pattern that will be used to filter the relative path "
105 "of entries to show.") 111 "of entries to show.")
106 112
107 def run(self, ctx): 113 def run(self, ctx):
108 out_dir = ctx.args.output or os.path.join(ctx.app.root_dir, '_counter') 114 out_dir = ctx.args.output or os.path.join(ctx.app.root_dir, '_counter')
117 pattern = '*%s*' % ctx.args.path.strip('*') 123 pattern = '*%s*' % ctx.args.path.strip('*')
118 124
119 record = BakeRecord.load(record_cache.getCachePath(record_name)) 125 record = BakeRecord.load(record_cache.getCachePath(record_name))
120 logging.info("Bake record for: %s" % record.out_dir) 126 logging.info("Bake record for: %s" % record.out_dir)
121 logging.info("Last baked: %s" % 127 logging.info("Last baked: %s" %
122 datetime.datetime.fromtimestamp(record.bake_time)) 128 datetime.datetime.fromtimestamp(record.bake_time))
123 logging.info("Entries:") 129 logging.info("Entries:")
124 for entry in record.entries: 130 for entry in record.entries:
125 if pattern: 131 if pattern:
126 rel_path = os.path.relpath(entry.path, ctx.app.root_dir)
127 if not fnmatch.fnmatch(entry.rel_path, pattern): 132 if not fnmatch.fnmatch(entry.rel_path, pattern):
128 continue 133 continue
129 logging.info(" - ") 134 logging.info(" - ")
130 logging.info(" path: %s" % entry.path) 135 logging.info(" path: %s" % entry.rel_path)
131 logging.info(" spec: %s:%s" % (entry.source_name, entry.rel_path)) 136 logging.info(" spec: %s:%s" % (entry.source_name,
132 logging.info(" taxonomy: %s:%s" % (entry.taxonomy_name, entry.taxonomy_term)) 137 entry.rel_path))
138 logging.info(" taxonomy: %s:%s" % (entry.taxonomy_name,
139 entry.taxonomy_term))
133 logging.info(" config: %s" % entry.config) 140 logging.info(" config: %s" % entry.config)
134 logging.info(" out URLs: %s" % entry.out_uris) 141 logging.info(" out URLs: %s" % entry.out_uris)
135 logging.info(" out paths: %s" % entry.out_paths) 142 logging.info(" out paths: %s" % entry.out_paths)
136 logging.info(" used srcs: %s" % entry.used_source_names) 143 logging.info(" used srcs: %s" % entry.used_source_names)
137 if entry.errors: 144 if entry.errors: