comparison piecrust/commands/builtin/baking.py @ 3:f485ba500df3

Gigantic change to basically make PieCrust 2 vaguely functional. - Serving works, with debug window. - Baking works, multi-threading, with dependency handling. - Various things not implemented yet.
author Ludovic Chabant <ludovic@chabant.com>
date Sun, 10 Aug 2014 23:43:16 -0700
parents
children 2f717f961996
comparison
equal deleted inserted replaced
2:40fa08b261b9 3:f485ba500df3
1 import os.path
2 import logging
3 import hashlib
4 from piecrust.baking.baker import Baker
5 from piecrust.baking.records import BakeRecord
6 from piecrust.commands.base import ChefCommand
7
8
9 logger = logging.getLogger(__name__)
10
11
12 class BakeCommand(ChefCommand):
13 def __init__(self):
14 super(BakeCommand, self).__init__()
15 self.name = 'bake'
16 self.description = "Bakes your website into static HTML files."
17
18 def setupParser(self, parser, app):
19 parser.add_argument('-o', '--output',
20 help="The directory to put all the baked HTML files into "
21 "(defaults to `_counter`)")
22 parser.add_argument('-f', '--force',
23 help="Force re-baking the entire website.",
24 action='store_true')
25 parser.add_argument('--portable',
26 help="Uses relative paths for all URLs.",
27 action='store_true')
28 parser.add_argument('--no-assets',
29 help="Don't process assets (only pages).",
30 action='store_true')
31
32 def run(self, ctx):
33 baker = Baker(
34 ctx.app,
35 out_dir=ctx.args.output,
36 force=ctx.args.force,
37 portable=ctx.args.portable,
38 no_assets=ctx.args.no_assets)
39 if ctx.args.portable:
40 # Disable pretty URLs because there's likely not going to be
41 # a web server to handle serving default documents.
42 ctx.app.config.set('site/pretty_urls', False)
43
44 baker.bake()
45
46
47 class ShowRecordCommand(ChefCommand):
48 def __init__(self):
49 super(ShowRecordCommand, self).__init__()
50 self.name = 'showrecord'
51 self.description = "Shows the bake record for a given output directory."
52
53 def setupParser(self, parser, app):
54 parser.add_argument('output',
55 help="The output directory for which to show the bake record "
56 "(defaults to `_counter`)",
57 nargs='?')
58
59 def run(self, ctx):
60 out_dir = ctx.args.output or os.path.join(ctx.app.root_dir, '_counter')
61 record_cache = ctx.app.cache.getCache('bake_r')
62 record_name = hashlib.md5(out_dir).hexdigest() + '.record'
63 if not record_cache.has(record_name):
64 raise Exception("No record has been created for this output path. "
65 "Did you bake there yet?")
66
67 record = BakeRecord.load(record_cache.getCachePath(record_name))
68 logging.info("Bake record for: %s" % record.out_dir)
69 logging.info("Last baked: %s" % record.bake_time)
70 logging.info("Entries:")
71 for entry in record.entries:
72 logging.info(" - ")
73 logging.info(" path: %s" % entry.path)
74 logging.info(" source: %s" % entry.source_name)
75 logging.info(" config: %s" % entry.config)
76 logging.info(" base URL: %s" % entry.uri)
77 logging.info(" outputs: %s" % entry.out_paths)
78