annotate piecrust/commands/builtin/baking.py @ 199:aaf08277b96d

bake: Remove `--portable` option until it's (maybe) implemented.
author Ludovic Chabant <ludovic@chabant.com>
date Tue, 13 Jan 2015 20:41:44 -0800
parents 5d8351cb32d8
children 0c9de41689bb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
121
300eb1c2cb14 Fix stupid bug.
Ludovic Chabant <ludovic@chabant.com>
parents: 120
diff changeset
1 import time
3
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
2 import os.path
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
3 import logging
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
4 import hashlib
92
0dd43c5f5484 More options for the `showrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 45
diff changeset
5 import fnmatch
0dd43c5f5484 More options for the `showrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 45
diff changeset
6 import datetime
3
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
7 from piecrust.baking.baker import Baker
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
8 from piecrust.baking.records import BakeRecord
120
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 92
diff changeset
9 from piecrust.chefutil import format_timed
3
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
10 from piecrust.commands.base import ChefCommand
120
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 92
diff changeset
11 from piecrust.processing.base import ProcessorPipeline
194
5d8351cb32d8 showrecord: Also show the pipeline record.
Ludovic Chabant <ludovic@chabant.com>
parents: 193
diff changeset
12 from piecrust.processing.records import (
5d8351cb32d8 showrecord: Also show the pipeline record.
Ludovic Chabant <ludovic@chabant.com>
parents: 193
diff changeset
13 ProcessorPipelineRecord, FLAG_OVERRIDEN)
3
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
14
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
15
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
16 logger = logging.getLogger(__name__)
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
17
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
18
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
19 class BakeCommand(ChefCommand):
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
20 def __init__(self):
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
21 super(BakeCommand, self).__init__()
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
22 self.name = 'bake'
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
23 self.description = "Bakes your website into static HTML files."
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
24
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
25 def setupParser(self, parser, app):
192
4c0ab0b044fe cosmetic: Fix some PEP8 issues.
Ludovic Chabant <ludovic@chabant.com>
parents: 127
diff changeset
26 parser.add_argument(
4c0ab0b044fe cosmetic: Fix some PEP8 issues.
Ludovic Chabant <ludovic@chabant.com>
parents: 127
diff changeset
27 '-o', '--output',
3
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
28 help="The directory to put all the baked HTML files into "
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
29 "(defaults to `_counter`)")
192
4c0ab0b044fe cosmetic: Fix some PEP8 issues.
Ludovic Chabant <ludovic@chabant.com>
parents: 127
diff changeset
30 parser.add_argument(
4c0ab0b044fe cosmetic: Fix some PEP8 issues.
Ludovic Chabant <ludovic@chabant.com>
parents: 127
diff changeset
31 '-f', '--force',
3
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
32 help="Force re-baking the entire website.",
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
33 action='store_true')
192
4c0ab0b044fe cosmetic: Fix some PEP8 issues.
Ludovic Chabant <ludovic@chabant.com>
parents: 127
diff changeset
34 parser.add_argument(
4c0ab0b044fe cosmetic: Fix some PEP8 issues.
Ludovic Chabant <ludovic@chabant.com>
parents: 127
diff changeset
35 '--no-assets',
3
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
36 help="Don't process assets (only pages).",
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
37 action='store_true')
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
38
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
39 def run(self, ctx):
127
bc63dc20baa0 Fix how we pass the out directory to the baking modules.
Ludovic Chabant <ludovic@chabant.com>
parents: 121
diff changeset
40 out_dir = (ctx.args.output or
bc63dc20baa0 Fix how we pass the out directory to the baking modules.
Ludovic Chabant <ludovic@chabant.com>
parents: 121
diff changeset
41 os.path.join(ctx.app.root_dir, '_counter'))
bc63dc20baa0 Fix how we pass the out directory to the baking modules.
Ludovic Chabant <ludovic@chabant.com>
parents: 121
diff changeset
42
121
300eb1c2cb14 Fix stupid bug.
Ludovic Chabant <ludovic@chabant.com>
parents: 120
diff changeset
43 start_time = time.clock()
39
2f717f961996 Better error reporting and cache validation.
Ludovic Chabant <ludovic@chabant.com>
parents: 3
diff changeset
44 try:
120
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 92
diff changeset
45 # Bake the site sources.
127
bc63dc20baa0 Fix how we pass the out directory to the baking modules.
Ludovic Chabant <ludovic@chabant.com>
parents: 121
diff changeset
46 self._bakeSources(ctx, out_dir)
120
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 92
diff changeset
47
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 92
diff changeset
48 # Bake the assets.
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 92
diff changeset
49 if not ctx.args.no_assets:
127
bc63dc20baa0 Fix how we pass the out directory to the baking modules.
Ludovic Chabant <ludovic@chabant.com>
parents: 121
diff changeset
50 self._bakeAssets(ctx, out_dir)
120
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 92
diff changeset
51
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 92
diff changeset
52 # All done.
192
4c0ab0b044fe cosmetic: Fix some PEP8 issues.
Ludovic Chabant <ludovic@chabant.com>
parents: 127
diff changeset
53 logger.info('-------------------------')
4c0ab0b044fe cosmetic: Fix some PEP8 issues.
Ludovic Chabant <ludovic@chabant.com>
parents: 127
diff changeset
54 logger.info(format_timed(start_time, 'done baking'))
39
2f717f961996 Better error reporting and cache validation.
Ludovic Chabant <ludovic@chabant.com>
parents: 3
diff changeset
55 return 0
2f717f961996 Better error reporting and cache validation.
Ludovic Chabant <ludovic@chabant.com>
parents: 3
diff changeset
56 except Exception as ex:
43
f14889d6b067 Proper debug logging.
Ludovic Chabant <ludovic@chabant.com>
parents: 39
diff changeset
57 if ctx.app.debug:
f14889d6b067 Proper debug logging.
Ludovic Chabant <ludovic@chabant.com>
parents: 39
diff changeset
58 logger.exception(ex)
f14889d6b067 Proper debug logging.
Ludovic Chabant <ludovic@chabant.com>
parents: 39
diff changeset
59 else:
f14889d6b067 Proper debug logging.
Ludovic Chabant <ludovic@chabant.com>
parents: 39
diff changeset
60 logger.error(str(ex))
39
2f717f961996 Better error reporting and cache validation.
Ludovic Chabant <ludovic@chabant.com>
parents: 3
diff changeset
61 return 1
3
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
62
127
bc63dc20baa0 Fix how we pass the out directory to the baking modules.
Ludovic Chabant <ludovic@chabant.com>
parents: 121
diff changeset
63 def _bakeSources(self, ctx, out_dir):
120
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 92
diff changeset
64 num_workers = ctx.app.config.get('baker/workers') or 4
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 92
diff changeset
65 baker = Baker(
127
bc63dc20baa0 Fix how we pass the out directory to the baking modules.
Ludovic Chabant <ludovic@chabant.com>
parents: 121
diff changeset
66 ctx.app, out_dir,
120
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 92
diff changeset
67 force=ctx.args.force,
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 92
diff changeset
68 no_assets=ctx.args.no_assets,
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 92
diff changeset
69 num_workers=num_workers)
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 92
diff changeset
70 baker.bake()
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 92
diff changeset
71
127
bc63dc20baa0 Fix how we pass the out directory to the baking modules.
Ludovic Chabant <ludovic@chabant.com>
parents: 121
diff changeset
72 def _bakeAssets(self, ctx, out_dir):
120
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 92
diff changeset
73 mounts = ctx.app.assets_dirs
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 92
diff changeset
74 baker_params = ctx.app.config.get('baker') or {}
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 92
diff changeset
75 skip_patterns = baker_params.get('skip_patterns')
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 92
diff changeset
76 force_patterns = baker_params.get('force_patterns')
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 92
diff changeset
77 num_workers = ctx.app.config.get('baker/workers') or 4
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 92
diff changeset
78 proc = ProcessorPipeline(
127
bc63dc20baa0 Fix how we pass the out directory to the baking modules.
Ludovic Chabant <ludovic@chabant.com>
parents: 121
diff changeset
79 ctx.app, mounts, out_dir,
120
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 92
diff changeset
80 force=ctx.args.force,
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 92
diff changeset
81 skip_patterns=skip_patterns,
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 92
diff changeset
82 force_patterns=force_patterns,
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 92
diff changeset
83 num_workers=num_workers)
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 92
diff changeset
84 proc.run()
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 92
diff changeset
85
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 92
diff changeset
86
3
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
87 class ShowRecordCommand(ChefCommand):
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
88 def __init__(self):
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
89 super(ShowRecordCommand, self).__init__()
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
90 self.name = 'showrecord'
192
4c0ab0b044fe cosmetic: Fix some PEP8 issues.
Ludovic Chabant <ludovic@chabant.com>
parents: 127
diff changeset
91 self.description = ("Shows the bake record for a given output "
4c0ab0b044fe cosmetic: Fix some PEP8 issues.
Ludovic Chabant <ludovic@chabant.com>
parents: 127
diff changeset
92 "directory.")
3
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
93
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
94 def setupParser(self, parser, app):
192
4c0ab0b044fe cosmetic: Fix some PEP8 issues.
Ludovic Chabant <ludovic@chabant.com>
parents: 127
diff changeset
95 parser.add_argument(
4c0ab0b044fe cosmetic: Fix some PEP8 issues.
Ludovic Chabant <ludovic@chabant.com>
parents: 127
diff changeset
96 '-o', '--output',
3
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
97 help="The output directory for which to show the bake record "
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
98 "(defaults to `_counter`)",
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
99 nargs='?')
192
4c0ab0b044fe cosmetic: Fix some PEP8 issues.
Ludovic Chabant <ludovic@chabant.com>
parents: 127
diff changeset
100 parser.add_argument(
4c0ab0b044fe cosmetic: Fix some PEP8 issues.
Ludovic Chabant <ludovic@chabant.com>
parents: 127
diff changeset
101 '-p', '--path',
92
0dd43c5f5484 More options for the `showrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 45
diff changeset
102 help="A pattern that will be used to filter the relative path "
0dd43c5f5484 More options for the `showrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 45
diff changeset
103 "of entries to show.")
3
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
104
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
105 def run(self, ctx):
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
106 out_dir = ctx.args.output or os.path.join(ctx.app.root_dir, '_counter')
194
5d8351cb32d8 showrecord: Also show the pipeline record.
Ludovic Chabant <ludovic@chabant.com>
parents: 193
diff changeset
107 record_name = (hashlib.md5(out_dir.encode('utf8')).hexdigest() +
5d8351cb32d8 showrecord: Also show the pipeline record.
Ludovic Chabant <ludovic@chabant.com>
parents: 193
diff changeset
108 '.record')
3
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
109
92
0dd43c5f5484 More options for the `showrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 45
diff changeset
110 pattern = None
0dd43c5f5484 More options for the `showrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 45
diff changeset
111 if ctx.args.path:
0dd43c5f5484 More options for the `showrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 45
diff changeset
112 pattern = '*%s*' % ctx.args.path.strip('*')
0dd43c5f5484 More options for the `showrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 45
diff changeset
113
194
5d8351cb32d8 showrecord: Also show the pipeline record.
Ludovic Chabant <ludovic@chabant.com>
parents: 193
diff changeset
114 record_cache = ctx.app.cache.getCache('baker')
5d8351cb32d8 showrecord: Also show the pipeline record.
Ludovic Chabant <ludovic@chabant.com>
parents: 193
diff changeset
115 if not record_cache.has(record_name):
5d8351cb32d8 showrecord: Also show the pipeline record.
Ludovic Chabant <ludovic@chabant.com>
parents: 193
diff changeset
116 raise Exception("No record has been created for this output path. "
5d8351cb32d8 showrecord: Also show the pipeline record.
Ludovic Chabant <ludovic@chabant.com>
parents: 193
diff changeset
117 "Did you bake there yet?")
5d8351cb32d8 showrecord: Also show the pipeline record.
Ludovic Chabant <ludovic@chabant.com>
parents: 193
diff changeset
118
3
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
119 record = BakeRecord.load(record_cache.getCachePath(record_name))
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
120 logging.info("Bake record for: %s" % record.out_dir)
92
0dd43c5f5484 More options for the `showrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 45
diff changeset
121 logging.info("Last baked: %s" %
192
4c0ab0b044fe cosmetic: Fix some PEP8 issues.
Ludovic Chabant <ludovic@chabant.com>
parents: 127
diff changeset
122 datetime.datetime.fromtimestamp(record.bake_time))
3
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
123 logging.info("Entries:")
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
124 for entry in record.entries:
92
0dd43c5f5484 More options for the `showrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 45
diff changeset
125 if pattern:
0dd43c5f5484 More options for the `showrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 45
diff changeset
126 if not fnmatch.fnmatch(entry.rel_path, pattern):
0dd43c5f5484 More options for the `showrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 45
diff changeset
127 continue
3
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
128 logging.info(" - ")
192
4c0ab0b044fe cosmetic: Fix some PEP8 issues.
Ludovic Chabant <ludovic@chabant.com>
parents: 127
diff changeset
129 logging.info(" path: %s" % entry.rel_path)
4c0ab0b044fe cosmetic: Fix some PEP8 issues.
Ludovic Chabant <ludovic@chabant.com>
parents: 127
diff changeset
130 logging.info(" spec: %s:%s" % (entry.source_name,
4c0ab0b044fe cosmetic: Fix some PEP8 issues.
Ludovic Chabant <ludovic@chabant.com>
parents: 127
diff changeset
131 entry.rel_path))
4c0ab0b044fe cosmetic: Fix some PEP8 issues.
Ludovic Chabant <ludovic@chabant.com>
parents: 127
diff changeset
132 logging.info(" taxonomy: %s:%s" % (entry.taxonomy_name,
4c0ab0b044fe cosmetic: Fix some PEP8 issues.
Ludovic Chabant <ludovic@chabant.com>
parents: 127
diff changeset
133 entry.taxonomy_term))
92
0dd43c5f5484 More options for the `showrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 45
diff changeset
134 logging.info(" config: %s" % entry.config)
0dd43c5f5484 More options for the `showrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 45
diff changeset
135 logging.info(" out URLs: %s" % entry.out_uris)
193
c2acf5f31936 showrecord: Show relative paths.
Ludovic Chabant <ludovic@chabant.com>
parents: 192
diff changeset
136 logging.info(" out paths: %s" % [os.path.relpath(p, out_dir)
c2acf5f31936 showrecord: Show relative paths.
Ludovic Chabant <ludovic@chabant.com>
parents: 192
diff changeset
137 for p in entry.out_paths])
92
0dd43c5f5484 More options for the `showrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 45
diff changeset
138 logging.info(" used srcs: %s" % entry.used_source_names)
120
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 92
diff changeset
139 if entry.errors:
133845647083 Better error management and removal support in baking/processing.
Ludovic Chabant <ludovic@chabant.com>
parents: 92
diff changeset
140 logging.error(" errors: %s" % entry.errors)
3
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
141
194
5d8351cb32d8 showrecord: Also show the pipeline record.
Ludovic Chabant <ludovic@chabant.com>
parents: 193
diff changeset
142 record_cache = ctx.app.cache.getCache('proc')
5d8351cb32d8 showrecord: Also show the pipeline record.
Ludovic Chabant <ludovic@chabant.com>
parents: 193
diff changeset
143 if not record_cache.has(record_name):
5d8351cb32d8 showrecord: Also show the pipeline record.
Ludovic Chabant <ludovic@chabant.com>
parents: 193
diff changeset
144 return
5d8351cb32d8 showrecord: Also show the pipeline record.
Ludovic Chabant <ludovic@chabant.com>
parents: 193
diff changeset
145
5d8351cb32d8 showrecord: Also show the pipeline record.
Ludovic Chabant <ludovic@chabant.com>
parents: 193
diff changeset
146 record = ProcessorPipelineRecord.load(
5d8351cb32d8 showrecord: Also show the pipeline record.
Ludovic Chabant <ludovic@chabant.com>
parents: 193
diff changeset
147 record_cache.getCachePath(record_name))
5d8351cb32d8 showrecord: Also show the pipeline record.
Ludovic Chabant <ludovic@chabant.com>
parents: 193
diff changeset
148 logging.info("")
5d8351cb32d8 showrecord: Also show the pipeline record.
Ludovic Chabant <ludovic@chabant.com>
parents: 193
diff changeset
149 logging.info("Processing record for: %s" % record.out_dir)
5d8351cb32d8 showrecord: Also show the pipeline record.
Ludovic Chabant <ludovic@chabant.com>
parents: 193
diff changeset
150 logging.info("Last baked: %s" %
5d8351cb32d8 showrecord: Also show the pipeline record.
Ludovic Chabant <ludovic@chabant.com>
parents: 193
diff changeset
151 datetime.datetime.fromtimestamp(record.process_time))
5d8351cb32d8 showrecord: Also show the pipeline record.
Ludovic Chabant <ludovic@chabant.com>
parents: 193
diff changeset
152 logging.info("Entries:")
5d8351cb32d8 showrecord: Also show the pipeline record.
Ludovic Chabant <ludovic@chabant.com>
parents: 193
diff changeset
153 for entry in record.entries:
5d8351cb32d8 showrecord: Also show the pipeline record.
Ludovic Chabant <ludovic@chabant.com>
parents: 193
diff changeset
154 if pattern:
5d8351cb32d8 showrecord: Also show the pipeline record.
Ludovic Chabant <ludovic@chabant.com>
parents: 193
diff changeset
155 if not fnmatch.fnmatch(entry.rel_input, pattern):
5d8351cb32d8 showrecord: Also show the pipeline record.
Ludovic Chabant <ludovic@chabant.com>
parents: 193
diff changeset
156 continue
5d8351cb32d8 showrecord: Also show the pipeline record.
Ludovic Chabant <ludovic@chabant.com>
parents: 193
diff changeset
157 flags = ''
5d8351cb32d8 showrecord: Also show the pipeline record.
Ludovic Chabant <ludovic@chabant.com>
parents: 193
diff changeset
158 if entry.flags & FLAG_OVERRIDEN:
5d8351cb32d8 showrecord: Also show the pipeline record.
Ludovic Chabant <ludovic@chabant.com>
parents: 193
diff changeset
159 flags += 'overriden'
5d8351cb32d8 showrecord: Also show the pipeline record.
Ludovic Chabant <ludovic@chabant.com>
parents: 193
diff changeset
160 logger.info(" - ")
5d8351cb32d8 showrecord: Also show the pipeline record.
Ludovic Chabant <ludovic@chabant.com>
parents: 193
diff changeset
161 logger.info(" path: %s" % entry.rel_input)
5d8351cb32d8 showrecord: Also show the pipeline record.
Ludovic Chabant <ludovic@chabant.com>
parents: 193
diff changeset
162 logger.info(" out paths: %s" % entry.rel_outputs)
5d8351cb32d8 showrecord: Also show the pipeline record.
Ludovic Chabant <ludovic@chabant.com>
parents: 193
diff changeset
163 logger.info(" flags: %s" % flags)
5d8351cb32d8 showrecord: Also show the pipeline record.
Ludovic Chabant <ludovic@chabant.com>
parents: 193
diff changeset
164 logger.info(" proc tree: %s" % format_proc_tree(
5d8351cb32d8 showrecord: Also show the pipeline record.
Ludovic Chabant <ludovic@chabant.com>
parents: 193
diff changeset
165 entry.proc_tree, 14*' '))
5d8351cb32d8 showrecord: Also show the pipeline record.
Ludovic Chabant <ludovic@chabant.com>
parents: 193
diff changeset
166 if entry.errors:
5d8351cb32d8 showrecord: Also show the pipeline record.
Ludovic Chabant <ludovic@chabant.com>
parents: 193
diff changeset
167 logger.error(" errors: %s" % entry.errors)
5d8351cb32d8 showrecord: Also show the pipeline record.
Ludovic Chabant <ludovic@chabant.com>
parents: 193
diff changeset
168
5d8351cb32d8 showrecord: Also show the pipeline record.
Ludovic Chabant <ludovic@chabant.com>
parents: 193
diff changeset
169
5d8351cb32d8 showrecord: Also show the pipeline record.
Ludovic Chabant <ludovic@chabant.com>
parents: 193
diff changeset
170 def format_proc_tree(tree, margin='', level=0):
5d8351cb32d8 showrecord: Also show the pipeline record.
Ludovic Chabant <ludovic@chabant.com>
parents: 193
diff changeset
171 name, children = tree
5d8351cb32d8 showrecord: Also show the pipeline record.
Ludovic Chabant <ludovic@chabant.com>
parents: 193
diff changeset
172 res = '%s%s%s' % (margin if level > 0 else '', level * ' ', name)
5d8351cb32d8 showrecord: Also show the pipeline record.
Ludovic Chabant <ludovic@chabant.com>
parents: 193
diff changeset
173 if children:
5d8351cb32d8 showrecord: Also show the pipeline record.
Ludovic Chabant <ludovic@chabant.com>
parents: 193
diff changeset
174 for c in children:
5d8351cb32d8 showrecord: Also show the pipeline record.
Ludovic Chabant <ludovic@chabant.com>
parents: 193
diff changeset
175 res += format_proc_tree(c, margin, level + 1)
5d8351cb32d8 showrecord: Also show the pipeline record.
Ludovic Chabant <ludovic@chabant.com>
parents: 193
diff changeset
176 return res
5d8351cb32d8 showrecord: Also show the pipeline record.
Ludovic Chabant <ludovic@chabant.com>
parents: 193
diff changeset
177