Mercurial > piecrust2
annotate piecrust/commands/builtin/info.py @ 1103:6462c4a87532
routes: Make help topic names consistent.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sat, 17 Feb 2018 16:13:32 -0800 |
parents | 07c23be08029 |
children | 986ecdaa2a36 |
rev | line source |
---|---|
3
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
1 import os.path |
1
aaa8fb7c8918
Re-arranged modules to reduce dependencies to builtin stuff.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
2 import logging |
1099
07c23be08029
help: Add new help topics on routes.
Ludovic Chabant <ludovic@chabant.com>
parents:
879
diff
changeset
|
3 from piecrust.commands.base import ( |
07c23be08029
help: Add new help topics on routes.
Ludovic Chabant <ludovic@chabant.com>
parents:
879
diff
changeset
|
4 ChefCommand, ChefCommandExtension, _ResourcesHelpTopics) |
1
aaa8fb7c8918
Re-arranged modules to reduce dependencies to builtin stuff.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
5 |
aaa8fb7c8918
Re-arranged modules to reduce dependencies to builtin stuff.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
6 |
aaa8fb7c8918
Re-arranged modules to reduce dependencies to builtin stuff.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
7 logger = logging.getLogger(__name__) |
aaa8fb7c8918
Re-arranged modules to reduce dependencies to builtin stuff.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
8 |
aaa8fb7c8918
Re-arranged modules to reduce dependencies to builtin stuff.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
9 |
aaa8fb7c8918
Re-arranged modules to reduce dependencies to builtin stuff.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
10 class RootCommand(ChefCommand): |
aaa8fb7c8918
Re-arranged modules to reduce dependencies to builtin stuff.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
11 def __init__(self): |
aaa8fb7c8918
Re-arranged modules to reduce dependencies to builtin stuff.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
12 super(RootCommand, self).__init__() |
aaa8fb7c8918
Re-arranged modules to reduce dependencies to builtin stuff.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
13 self.name = 'root' |
aaa8fb7c8918
Re-arranged modules to reduce dependencies to builtin stuff.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
14 self.description = "Gets the root directory of the current website." |
aaa8fb7c8918
Re-arranged modules to reduce dependencies to builtin stuff.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
15 |
3
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
16 def setupParser(self, parser, app): |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
17 pass |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
18 |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
19 def run(self, ctx): |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
20 logger.info(ctx.app.root_dir) |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
21 |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
22 |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
23 class ShowConfigCommand(ChefCommand): |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
24 def __init__(self): |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
25 super(ShowConfigCommand, self).__init__() |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
26 self.name = 'showconfig' |
755
f9d926669d7a
chef: Make all the commands descriptions fit in one line.
Ludovic Chabant <ludovic@chabant.com>
parents:
731
diff
changeset
|
27 self.description = ("Shows the website's configuration.") |
3
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
28 |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
29 def setupParser(self, parser, app): |
161
516db87a04d4
cosmetic: pep8 compliance.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
30 parser.add_argument( |
852
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
792
diff
changeset
|
31 'path', |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
792
diff
changeset
|
32 help="The path to a config section or value", |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
792
diff
changeset
|
33 nargs='?') |
3
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
34 |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
35 def run(self, ctx): |
879
58ae026b4c31
chef: Optimize startup time.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
36 import yaml |
58ae026b4c31
chef: Optimize startup time.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
37 from piecrust.configuration import ConfigurationDumper |
58ae026b4c31
chef: Optimize startup time.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
38 |
567
a65f04ddbea2
showconfig: Don't crash when the whole config should be shown.
Ludovic Chabant <ludovic@chabant.com>
parents:
340
diff
changeset
|
39 if ctx.args.path: |
a65f04ddbea2
showconfig: Don't crash when the whole config should be shown.
Ludovic Chabant <ludovic@chabant.com>
parents:
340
diff
changeset
|
40 show = ctx.app.config.get(ctx.args.path) |
a65f04ddbea2
showconfig: Don't crash when the whole config should be shown.
Ludovic Chabant <ludovic@chabant.com>
parents:
340
diff
changeset
|
41 else: |
a65f04ddbea2
showconfig: Don't crash when the whole config should be shown.
Ludovic Chabant <ludovic@chabant.com>
parents:
340
diff
changeset
|
42 show = ctx.app.config.getAll() |
a65f04ddbea2
showconfig: Don't crash when the whole config should be shown.
Ludovic Chabant <ludovic@chabant.com>
parents:
340
diff
changeset
|
43 |
3
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
44 if show is not None: |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
45 if isinstance(show, (dict, list)): |
107
10fc9c8bf682
Better support for times in YAML interop.
Ludovic Chabant <ludovic@chabant.com>
parents:
5
diff
changeset
|
46 out = yaml.dump(show, default_flow_style=False, |
10fc9c8bf682
Better support for times in YAML interop.
Ludovic Chabant <ludovic@chabant.com>
parents:
5
diff
changeset
|
47 Dumper=ConfigurationDumper) |
3
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
48 logger.info(out) |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
49 else: |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
50 logger.info(show) |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
51 elif ctx.args.path: |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
52 logger.error("No such configuration path: %s" % ctx.args.path) |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
53 ctx.result = 1 |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
54 |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
55 |
163
6d23473fab41
sources: Add `chef sources` command to list page sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
162
diff
changeset
|
56 class ShowSourcesCommand(ChefCommand): |
6d23473fab41
sources: Add `chef sources` command to list page sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
162
diff
changeset
|
57 def __init__(self): |
6d23473fab41
sources: Add `chef sources` command to list page sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
162
diff
changeset
|
58 super(ShowSourcesCommand, self).__init__() |
6d23473fab41
sources: Add `chef sources` command to list page sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
162
diff
changeset
|
59 self.name = 'sources' |
6d23473fab41
sources: Add `chef sources` command to list page sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
162
diff
changeset
|
60 self.description = "Shows the sources defined for this website." |
6d23473fab41
sources: Add `chef sources` command to list page sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
162
diff
changeset
|
61 |
6d23473fab41
sources: Add `chef sources` command to list page sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
162
diff
changeset
|
62 def setupParser(self, parser, app): |
6d23473fab41
sources: Add `chef sources` command to list page sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
162
diff
changeset
|
63 pass |
6d23473fab41
sources: Add `chef sources` command to list page sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
162
diff
changeset
|
64 |
6d23473fab41
sources: Add `chef sources` command to list page sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
162
diff
changeset
|
65 def run(self, ctx): |
6d23473fab41
sources: Add `chef sources` command to list page sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
162
diff
changeset
|
66 for src in ctx.app.sources: |
6d23473fab41
sources: Add `chef sources` command to list page sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
162
diff
changeset
|
67 logger.info("%s:" % src.name) |
6d23473fab41
sources: Add `chef sources` command to list page sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
162
diff
changeset
|
68 logger.info(" type: %s" % src.config.get('type')) |
852
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
792
diff
changeset
|
69 logger.debug(" class: %s" % type(src)) |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
792
diff
changeset
|
70 desc = src.describe() |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
792
diff
changeset
|
71 if isinstance(desc, dict): |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
792
diff
changeset
|
72 for k, v in desc.items(): |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
792
diff
changeset
|
73 logger.info(" %s: %s" % (k, v)) |
163
6d23473fab41
sources: Add `chef sources` command to list page sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
162
diff
changeset
|
74 |
6d23473fab41
sources: Add `chef sources` command to list page sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
162
diff
changeset
|
75 |
3
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
76 class ShowRoutesCommand(ChefCommand): |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
77 def __init__(self): |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
78 super(ShowRoutesCommand, self).__init__() |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
79 self.name = 'routes' |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
80 self.description = "Shows the routes defined for this website." |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
81 |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
82 def setupParser(self, parser, app): |
1
aaa8fb7c8918
Re-arranged modules to reduce dependencies to builtin stuff.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
83 pass |
aaa8fb7c8918
Re-arranged modules to reduce dependencies to builtin stuff.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
84 |
1099
07c23be08029
help: Add new help topics on routes.
Ludovic Chabant <ludovic@chabant.com>
parents:
879
diff
changeset
|
85 def provideExtensions(self): |
07c23be08029
help: Add new help topics on routes.
Ludovic Chabant <ludovic@chabant.com>
parents:
879
diff
changeset
|
86 return [RoutesHelpTopic()] |
07c23be08029
help: Add new help topics on routes.
Ludovic Chabant <ludovic@chabant.com>
parents:
879
diff
changeset
|
87 |
1
aaa8fb7c8918
Re-arranged modules to reduce dependencies to builtin stuff.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
88 def run(self, ctx): |
3
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
89 for route in ctx.app.routes: |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
90 logger.info("%s:" % route.uri_pattern) |
711
ab5c6a8ae90a
bake: Replace hard-coded taxonomy support with "generator" system.
Ludovic Chabant <ludovic@chabant.com>
parents:
567
diff
changeset
|
91 logger.info(" source: %s" % (route.source_name or '')) |
168
56d6b17e057b
routes: Show regex patterns for routes.
Ludovic Chabant <ludovic@chabant.com>
parents:
164
diff
changeset
|
92 logger.info(" regex: %s" % route.uri_re.pattern) |
731
dafb7d76c2ba
routes: Show the route template function.
Ludovic Chabant <ludovic@chabant.com>
parents:
711
diff
changeset
|
93 logger.info(" function: %s(%s)" % ( |
787
f6f9a284a5f3
routing: Simplify how route functions are declared and handled.
Ludovic Chabant <ludovic@chabant.com>
parents:
755
diff
changeset
|
94 route.func_name, |
792
58ebf50235a5
routing: Simplify how routes are defined.
Ludovic Chabant <ludovic@chabant.com>
parents:
787
diff
changeset
|
95 ', '.join(route.uri_params))) |
3
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
96 |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
97 |
1099
07c23be08029
help: Add new help topics on routes.
Ludovic Chabant <ludovic@chabant.com>
parents:
879
diff
changeset
|
98 class RoutesHelpTopic(ChefCommandExtension, _ResourcesHelpTopics): |
07c23be08029
help: Add new help topics on routes.
Ludovic Chabant <ludovic@chabant.com>
parents:
879
diff
changeset
|
99 command_name = 'help' |
07c23be08029
help: Add new help topics on routes.
Ludovic Chabant <ludovic@chabant.com>
parents:
879
diff
changeset
|
100 |
07c23be08029
help: Add new help topics on routes.
Ludovic Chabant <ludovic@chabant.com>
parents:
879
diff
changeset
|
101 def getHelpTopics(self): |
07c23be08029
help: Add new help topics on routes.
Ludovic Chabant <ludovic@chabant.com>
parents:
879
diff
changeset
|
102 return [('routes_config', |
07c23be08029
help: Add new help topics on routes.
Ludovic Chabant <ludovic@chabant.com>
parents:
879
diff
changeset
|
103 "Specifying URL routes for your site's content."), |
1103
6462c4a87532
routes: Make help topic names consistent.
Ludovic Chabant <ludovic@chabant.com>
parents:
1099
diff
changeset
|
104 ('routes_params', |
1099
07c23be08029
help: Add new help topics on routes.
Ludovic Chabant <ludovic@chabant.com>
parents:
879
diff
changeset
|
105 "Show the available route parameters.")] |
07c23be08029
help: Add new help topics on routes.
Ludovic Chabant <ludovic@chabant.com>
parents:
879
diff
changeset
|
106 |
07c23be08029
help: Add new help topics on routes.
Ludovic Chabant <ludovic@chabant.com>
parents:
879
diff
changeset
|
107 def getHelpTopic(self, topic, app): |
1103
6462c4a87532
routes: Make help topic names consistent.
Ludovic Chabant <ludovic@chabant.com>
parents:
1099
diff
changeset
|
108 if topic != 'routes_params': |
1099
07c23be08029
help: Add new help topics on routes.
Ludovic Chabant <ludovic@chabant.com>
parents:
879
diff
changeset
|
109 return _ResourcesHelpTopics.getHelpTopic(self, topic, app) |
07c23be08029
help: Add new help topics on routes.
Ludovic Chabant <ludovic@chabant.com>
parents:
879
diff
changeset
|
110 |
07c23be08029
help: Add new help topics on routes.
Ludovic Chabant <ludovic@chabant.com>
parents:
879
diff
changeset
|
111 import textwrap |
07c23be08029
help: Add new help topics on routes.
Ludovic Chabant <ludovic@chabant.com>
parents:
879
diff
changeset
|
112 |
07c23be08029
help: Add new help topics on routes.
Ludovic Chabant <ludovic@chabant.com>
parents:
879
diff
changeset
|
113 help_txt = ( |
07c23be08029
help: Add new help topics on routes.
Ludovic Chabant <ludovic@chabant.com>
parents:
879
diff
changeset
|
114 textwrap.fill( |
07c23be08029
help: Add new help topics on routes.
Ludovic Chabant <ludovic@chabant.com>
parents:
879
diff
changeset
|
115 "Route parameters can be used as placeholders when specifying " |
07c23be08029
help: Add new help topics on routes.
Ludovic Chabant <ludovic@chabant.com>
parents:
879
diff
changeset
|
116 "route URL patterns in your site configuration. See " |
07c23be08029
help: Add new help topics on routes.
Ludovic Chabant <ludovic@chabant.com>
parents:
879
diff
changeset
|
117 "`chef help routes_config` for more information.") + |
07c23be08029
help: Add new help topics on routes.
Ludovic Chabant <ludovic@chabant.com>
parents:
879
diff
changeset
|
118 "\n\n") |
07c23be08029
help: Add new help topics on routes.
Ludovic Chabant <ludovic@chabant.com>
parents:
879
diff
changeset
|
119 if app.root_dir is None: |
07c23be08029
help: Add new help topics on routes.
Ludovic Chabant <ludovic@chabant.com>
parents:
879
diff
changeset
|
120 help_txt += textwrap.fill( |
07c23be08029
help: Add new help topics on routes.
Ludovic Chabant <ludovic@chabant.com>
parents:
879
diff
changeset
|
121 "Running this help command in a PieCrust website would show " |
07c23be08029
help: Add new help topics on routes.
Ludovic Chabant <ludovic@chabant.com>
parents:
879
diff
changeset
|
122 "the route parameters available for your site's sources. " |
07c23be08029
help: Add new help topics on routes.
Ludovic Chabant <ludovic@chabant.com>
parents:
879
diff
changeset
|
123 "However, no PieCrust website has been found in the current " |
07c23be08029
help: Add new help topics on routes.
Ludovic Chabant <ludovic@chabant.com>
parents:
879
diff
changeset
|
124 "working directory. ") |
07c23be08029
help: Add new help topics on routes.
Ludovic Chabant <ludovic@chabant.com>
parents:
879
diff
changeset
|
125 return help_txt |
07c23be08029
help: Add new help topics on routes.
Ludovic Chabant <ludovic@chabant.com>
parents:
879
diff
changeset
|
126 |
07c23be08029
help: Add new help topics on routes.
Ludovic Chabant <ludovic@chabant.com>
parents:
879
diff
changeset
|
127 srcs_by_types = {} |
07c23be08029
help: Add new help topics on routes.
Ludovic Chabant <ludovic@chabant.com>
parents:
879
diff
changeset
|
128 for src in app.sources: |
07c23be08029
help: Add new help topics on routes.
Ludovic Chabant <ludovic@chabant.com>
parents:
879
diff
changeset
|
129 srcs_by_types.setdefault(src.SOURCE_NAME, []).append(src) |
07c23be08029
help: Add new help topics on routes.
Ludovic Chabant <ludovic@chabant.com>
parents:
879
diff
changeset
|
130 |
07c23be08029
help: Add new help topics on routes.
Ludovic Chabant <ludovic@chabant.com>
parents:
879
diff
changeset
|
131 for type_name, srcs in srcs_by_types.items(): |
07c23be08029
help: Add new help topics on routes.
Ludovic Chabant <ludovic@chabant.com>
parents:
879
diff
changeset
|
132 help_txt += textwrap.fill( |
07c23be08029
help: Add new help topics on routes.
Ludovic Chabant <ludovic@chabant.com>
parents:
879
diff
changeset
|
133 "Route parameters for '%s' sources (%s):" % ( |
07c23be08029
help: Add new help topics on routes.
Ludovic Chabant <ludovic@chabant.com>
parents:
879
diff
changeset
|
134 type_name, ', '.join([s.name for s in srcs]))) |
07c23be08029
help: Add new help topics on routes.
Ludovic Chabant <ludovic@chabant.com>
parents:
879
diff
changeset
|
135 help_txt += "\n" |
07c23be08029
help: Add new help topics on routes.
Ludovic Chabant <ludovic@chabant.com>
parents:
879
diff
changeset
|
136 for rp in srcs[0].getSupportedRouteParameters(): |
07c23be08029
help: Add new help topics on routes.
Ludovic Chabant <ludovic@chabant.com>
parents:
879
diff
changeset
|
137 help_txt += " - %s\n" % rp.param_name |
07c23be08029
help: Add new help topics on routes.
Ludovic Chabant <ludovic@chabant.com>
parents:
879
diff
changeset
|
138 help_txt += "\n" |
07c23be08029
help: Add new help topics on routes.
Ludovic Chabant <ludovic@chabant.com>
parents:
879
diff
changeset
|
139 return help_txt |
07c23be08029
help: Add new help topics on routes.
Ludovic Chabant <ludovic@chabant.com>
parents:
879
diff
changeset
|
140 |
07c23be08029
help: Add new help topics on routes.
Ludovic Chabant <ludovic@chabant.com>
parents:
879
diff
changeset
|
141 |
3
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
142 class ShowPathsCommand(ChefCommand): |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
143 def __init__(self): |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
144 super(ShowPathsCommand, self).__init__() |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
145 self.name = 'paths' |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
146 self.description = "Shows the paths that this website is using." |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
147 |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
148 def setupParser(self, parser, app): |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
149 pass |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
150 |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
151 def run(self, ctx): |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
152 app = ctx.app |
307
869a206facd5
internal: Remove mentions of plugins directories and sources.
Ludovic Chabant <ludovic@chabant.com>
parents:
168
diff
changeset
|
153 paths = ['theme_dir', 'templates_dirs', 'cache_dir'] |
3
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
154 for p in paths: |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
155 value = getattr(app, p) |
162
c4b155b08b52
paths: properly format lists of paths.
Ludovic Chabant <ludovic@chabant.com>
parents:
161
diff
changeset
|
156 if isinstance(value, list): |
c4b155b08b52
paths: properly format lists of paths.
Ludovic Chabant <ludovic@chabant.com>
parents:
161
diff
changeset
|
157 logging.info("%s:" % p) |
c4b155b08b52
paths: properly format lists of paths.
Ludovic Chabant <ludovic@chabant.com>
parents:
161
diff
changeset
|
158 for v in value: |
c4b155b08b52
paths: properly format lists of paths.
Ludovic Chabant <ludovic@chabant.com>
parents:
161
diff
changeset
|
159 logging.info(" - %s" % v) |
3
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
160 else: |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
161 logging.info("%s: %s" % (p, value)) |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
162 |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
163 |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
164 class FindCommand(ChefCommand): |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
165 def __init__(self): |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
166 super(FindCommand, self).__init__() |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
167 self.name = 'find' |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
168 self.description = "Find pages in the website." |
1
aaa8fb7c8918
Re-arranged modules to reduce dependencies to builtin stuff.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
169 |
3
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
170 def setupParser(self, parser, app): |
161
516db87a04d4
cosmetic: pep8 compliance.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
171 parser.add_argument( |
852
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
792
diff
changeset
|
172 'pattern', |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
792
diff
changeset
|
173 help="The pattern to match with page filenames", |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
792
diff
changeset
|
174 nargs='?') |
161
516db87a04d4
cosmetic: pep8 compliance.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
175 parser.add_argument( |
852
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
792
diff
changeset
|
176 '-n', '--name', |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
792
diff
changeset
|
177 help="Limit the search to sources matching this name") |
161
516db87a04d4
cosmetic: pep8 compliance.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
178 parser.add_argument( |
852
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
792
diff
changeset
|
179 '--full-path', |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
792
diff
changeset
|
180 help="Return full paths instead of root-relative paths", |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
792
diff
changeset
|
181 action='store_true') |
161
516db87a04d4
cosmetic: pep8 compliance.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
182 parser.add_argument( |
852
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
792
diff
changeset
|
183 '--metadata', |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
792
diff
changeset
|
184 help="Return metadata about the page instead of just the path", |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
792
diff
changeset
|
185 action='store_true') |
164
4534ccbdd2a3
find: Fix the `find` command, add more options.
Ludovic Chabant <ludovic@chabant.com>
parents:
163
diff
changeset
|
186 parser.add_argument( |
852
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
792
diff
changeset
|
187 '--include-theme', |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
792
diff
changeset
|
188 help="Include theme pages to the search", |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
792
diff
changeset
|
189 action='store_true') |
164
4534ccbdd2a3
find: Fix the `find` command, add more options.
Ludovic Chabant <ludovic@chabant.com>
parents:
163
diff
changeset
|
190 parser.add_argument( |
852
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
792
diff
changeset
|
191 '--exact', |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
792
diff
changeset
|
192 help=("Match the exact given pattern, instead of any page " |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
792
diff
changeset
|
193 "containing the pattern"), |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
792
diff
changeset
|
194 action='store_true') |
3
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
195 |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
196 def run(self, ctx): |
879
58ae026b4c31
chef: Optimize startup time.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
197 import fnmatch |
58ae026b4c31
chef: Optimize startup time.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
198 from piecrust.sources.fs import FSContentSourceBase |
58ae026b4c31
chef: Optimize startup time.
Ludovic Chabant <ludovic@chabant.com>
parents:
852
diff
changeset
|
199 |
3
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
200 pattern = ctx.args.pattern |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
201 sources = list(ctx.app.sources) |
340
794b047c9726
find: Don't change the pattern when there's none.
Ludovic Chabant <ludovic@chabant.com>
parents:
334
diff
changeset
|
202 if not ctx.args.exact and pattern is not None: |
164
4534ccbdd2a3
find: Fix the `find` command, add more options.
Ludovic Chabant <ludovic@chabant.com>
parents:
163
diff
changeset
|
203 pattern = '*%s*' % pattern |
4534ccbdd2a3
find: Fix the `find` command, add more options.
Ludovic Chabant <ludovic@chabant.com>
parents:
163
diff
changeset
|
204 |
3
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
205 for src in sources: |
164
4534ccbdd2a3
find: Fix the `find` command, add more options.
Ludovic Chabant <ludovic@chabant.com>
parents:
163
diff
changeset
|
206 if not ctx.args.include_theme and src.is_theme_source: |
4534ccbdd2a3
find: Fix the `find` command, add more options.
Ludovic Chabant <ludovic@chabant.com>
parents:
163
diff
changeset
|
207 continue |
4534ccbdd2a3
find: Fix the `find` command, add more options.
Ludovic Chabant <ludovic@chabant.com>
parents:
163
diff
changeset
|
208 if ctx.args.name and not fnmatch.fnmatch(src.name, ctx.args.name): |
4534ccbdd2a3
find: Fix the `find` command, add more options.
Ludovic Chabant <ludovic@chabant.com>
parents:
163
diff
changeset
|
209 continue |
4534ccbdd2a3
find: Fix the `find` command, add more options.
Ludovic Chabant <ludovic@chabant.com>
parents:
163
diff
changeset
|
210 |
852
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
792
diff
changeset
|
211 is_fs_src = isinstance(src, FSContentSourceBase) |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
792
diff
changeset
|
212 items = src.getAllContents() |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
792
diff
changeset
|
213 for item in items: |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
792
diff
changeset
|
214 if ctx.args.metadata: |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
792
diff
changeset
|
215 logger.info("spec:%s" % item.spec) |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
792
diff
changeset
|
216 for key, val in item.metadata.items(): |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
792
diff
changeset
|
217 logger.info("%s:%s" % (key, val)) |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
792
diff
changeset
|
218 logger.info("---") |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
792
diff
changeset
|
219 else: |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
792
diff
changeset
|
220 if is_fs_src: |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
792
diff
changeset
|
221 name = os.path.relpath(item.spec, ctx.app.root_dir) |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
792
diff
changeset
|
222 if pattern is None or fnmatch.fnmatch(name, pattern): |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
792
diff
changeset
|
223 if ctx.args.metadata: |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
792
diff
changeset
|
224 logger.info("path:%s" % item.spec) |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
792
diff
changeset
|
225 for key, val in item.metadata.items(): |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
792
diff
changeset
|
226 logger.info("%s:%s" % (key, val)) |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
792
diff
changeset
|
227 logger.info("---") |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
792
diff
changeset
|
228 else: |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
792
diff
changeset
|
229 if ctx.args.full_path: |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
792
diff
changeset
|
230 name = item.spec |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
792
diff
changeset
|
231 logger.info(name) |
3
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
232 else: |
852
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
792
diff
changeset
|
233 if pattern is None or fnmatch.fnmatch(name, pattern): |
4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
792
diff
changeset
|
234 logger.info(item.spec) |
3
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
235 |