Mercurial > piecrust2
comparison piecrust/commands/base.py @ 852:4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
* Everything is a `ContentSource`, including assets directories.
* Most content sources are subclasses of the base file-system source.
* A source is processed by a "pipeline", and there are 2 built-in pipelines,
one for assets and one for pages. The asset pipeline is vaguely functional,
but the page pipeline is completely broken right now.
* Rewrite the baking process as just running appropriate pipelines on each
content item. This should allow for better parallelization.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Wed, 17 May 2017 00:11:48 -0700 |
parents | 3ceeca7bb71c |
children | 07c23be08029 |
comparison
equal
deleted
inserted
replaced
851:2c7e57d80bba | 852:4850f8c21b6e |
---|---|
6 | 6 |
7 logger = logging.getLogger(__name__) | 7 logger = logging.getLogger(__name__) |
8 | 8 |
9 | 9 |
10 class CommandContext(object): | 10 class CommandContext(object): |
11 def __init__(self, app, parser, args): | 11 def __init__(self, appfactory, app, parser, args): |
12 self.appfactory = appfactory | |
12 self.app = app | 13 self.app = app |
13 self.parser = parser | 14 self.parser = parser |
14 self.args = args | 15 self.args = args |
15 self.config_variant = None | |
16 self.config_values = None | |
17 | 16 |
18 | 17 |
19 class ChefCommand(object): | 18 class ChefCommand(object): |
20 def __init__(self): | 19 def __init__(self): |
21 self.name = '__unknown__' | 20 self.name = '__unknown__' |
25 | 24 |
26 def setupParser(self, parser, app): | 25 def setupParser(self, parser, app): |
27 raise NotImplementedError() | 26 raise NotImplementedError() |
28 | 27 |
29 def run(self, ctx): | 28 def run(self, ctx): |
30 raise NotImplementedError("Command '%s' doesn't implement the `run` " | 29 raise NotImplementedError( |
31 "method." % type(self)) | 30 "Command '%s' doesn't implement the `run` " |
31 "method." % type(self)) | |
32 | 32 |
33 def checkedRun(self, ctx): | 33 def checkedRun(self, ctx): |
34 if ctx.app.root_dir is None and self.requires_website: | 34 if ctx.app.root_dir is None and self.requires_website: |
35 raise SiteNotFoundError(theme=ctx.app.theme_site) | 35 raise SiteNotFoundError(theme=ctx.app.theme_site) |
36 return self.run(ctx) | 36 return self.run(ctx) |
81 | 81 |
82 def getTopics(self): | 82 def getTopics(self): |
83 return [(n, d) for (n, d, e) in self._topic_providers] | 83 return [(n, d) for (n, d, e) in self._topic_providers] |
84 | 84 |
85 def setupParser(self, parser, app): | 85 def setupParser(self, parser, app): |
86 parser.add_argument('topic', nargs='?', | 86 parser.add_argument( |
87 help="The command name or topic on which to get help.") | 87 'topic', nargs='?', |
88 help="The command name or topic on which to get help.") | |
88 | 89 |
89 extensions = self.getExtensions(app) | 90 extensions = self.getExtensions(app) |
90 for ext in extensions: | 91 for ext in extensions: |
91 for name, desc in ext.getHelpTopics(): | 92 for name, desc in ext.getHelpTopics(): |
92 self._topic_providers.append((name, desc, ext)) | 93 self._topic_providers.append((name, desc, ext)) |
104 return 0 | 105 return 0 |
105 | 106 |
106 for c in ctx.app.plugin_loader.getCommands(): | 107 for c in ctx.app.plugin_loader.getCommands(): |
107 if c.name == topic: | 108 if c.name == topic: |
108 fake = argparse.ArgumentParser( | 109 fake = argparse.ArgumentParser( |
109 prog='%s %s' % (ctx.parser.prog, c.name), | 110 prog='%s %s' % (ctx.parser.prog, c.name), |
110 description=c.description) | 111 description=c.description) |
111 c.setupParser(fake, ctx.app) | 112 c.setupParser(fake, ctx.app) |
112 fake.print_help() | 113 fake.print_help() |
113 return 0 | 114 return 0 |
114 | 115 |
115 raise Exception("No such command or topic: %s" % topic) | 116 raise Exception("No such command or topic: %s" % topic) |