annotate piecrust/commands/builtin/info.py @ 868:8d25f76fce98

bake: Add ability to specify pipelines to exclude during the bake.
author Ludovic Chabant <ludovic@chabant.com>
date Mon, 12 Jun 2017 22:22:19 -0700
parents 4850f8c21b6e
children 58ae026b4c31
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
3
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
3 import fnmatch
1
aaa8fb7c8918 Re-arranged modules to reduce dependencies to builtin stuff.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
4 from piecrust.commands.base import ChefCommand
107
10fc9c8bf682 Better support for times in YAML interop.
Ludovic Chabant <ludovic@chabant.com>
parents: 5
diff changeset
5 from piecrust.configuration import ConfigurationDumper
852
4850f8c21b6e core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents: 792
diff changeset
6 from piecrust.sources.fs import FSContentSourceBase
1
aaa8fb7c8918 Re-arranged modules to reduce dependencies to builtin stuff.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
7
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 logger = logging.getLogger(__name__)
aaa8fb7c8918 Re-arranged modules to reduce dependencies to builtin stuff.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
10
aaa8fb7c8918 Re-arranged modules to reduce dependencies to builtin stuff.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
11
aaa8fb7c8918 Re-arranged modules to reduce dependencies to builtin stuff.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
12 class RootCommand(ChefCommand):
aaa8fb7c8918 Re-arranged modules to reduce dependencies to builtin stuff.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
13 def __init__(self):
aaa8fb7c8918 Re-arranged modules to reduce dependencies to builtin stuff.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
14 super(RootCommand, self).__init__()
aaa8fb7c8918 Re-arranged modules to reduce dependencies to builtin stuff.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
15 self.name = 'root'
aaa8fb7c8918 Re-arranged modules to reduce dependencies to builtin stuff.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
16 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
17
3
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
18 def setupParser(self, parser, app):
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
19 pass
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
20
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
21 def run(self, ctx):
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
22 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
23
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
24
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
25 class ShowConfigCommand(ChefCommand):
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
26 def __init__(self):
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
27 super(ShowConfigCommand, self).__init__()
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
28 self.name = 'showconfig'
755
f9d926669d7a chef: Make all the commands descriptions fit in one line.
Ludovic Chabant <ludovic@chabant.com>
parents: 731
diff changeset
29 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
30
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
31 def setupParser(self, parser, app):
161
516db87a04d4 cosmetic: pep8 compliance.
Ludovic Chabant <ludovic@chabant.com>
parents: 107
diff changeset
32 parser.add_argument(
852
4850f8c21b6e core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents: 792
diff changeset
33 'path',
4850f8c21b6e core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents: 792
diff changeset
34 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
35 nargs='?')
3
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
36
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
37 def run(self, ctx):
567
a65f04ddbea2 showconfig: Don't crash when the whole config should be shown.
Ludovic Chabant <ludovic@chabant.com>
parents: 340
diff changeset
38 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
39 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
40 else:
a65f04ddbea2 showconfig: Don't crash when the whole config should be shown.
Ludovic Chabant <ludovic@chabant.com>
parents: 340
diff changeset
41 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
42
3
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
43 if show is not None:
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
44 if isinstance(show, (dict, list)):
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
45 import yaml
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
aaa8fb7c8918 Re-arranged modules to reduce dependencies to builtin stuff.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
85 def run(self, ctx):
3
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
86 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
87 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
88 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
89 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
90 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
91 route.func_name,
792
58ebf50235a5 routing: Simplify how routes are defined.
Ludovic Chabant <ludovic@chabant.com>
parents: 787
diff changeset
92 ', '.join(route.uri_params)))
3
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
93
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
94
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
95 class ShowPathsCommand(ChefCommand):
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
96 def __init__(self):
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
97 super(ShowPathsCommand, self).__init__()
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
98 self.name = 'paths'
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
99 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
100
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
101 def setupParser(self, parser, app):
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
102 pass
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
103
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
104 def run(self, ctx):
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
105 app = ctx.app
307
869a206facd5 internal: Remove mentions of plugins directories and sources.
Ludovic Chabant <ludovic@chabant.com>
parents: 168
diff changeset
106 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
107 for p in paths:
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
108 value = getattr(app, p)
162
c4b155b08b52 paths: properly format lists of paths.
Ludovic Chabant <ludovic@chabant.com>
parents: 161
diff changeset
109 if isinstance(value, list):
c4b155b08b52 paths: properly format lists of paths.
Ludovic Chabant <ludovic@chabant.com>
parents: 161
diff changeset
110 logging.info("%s:" % p)
c4b155b08b52 paths: properly format lists of paths.
Ludovic Chabant <ludovic@chabant.com>
parents: 161
diff changeset
111 for v in value:
c4b155b08b52 paths: properly format lists of paths.
Ludovic Chabant <ludovic@chabant.com>
parents: 161
diff changeset
112 logging.info(" - %s" % v)
3
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
113 else:
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
114 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
115
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
116
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
117 class FindCommand(ChefCommand):
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
118 def __init__(self):
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
119 super(FindCommand, self).__init__()
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
120 self.name = 'find'
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
121 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
122
3
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
123 def setupParser(self, parser, app):
161
516db87a04d4 cosmetic: pep8 compliance.
Ludovic Chabant <ludovic@chabant.com>
parents: 107
diff changeset
124 parser.add_argument(
852
4850f8c21b6e core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents: 792
diff changeset
125 'pattern',
4850f8c21b6e core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents: 792
diff changeset
126 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
127 nargs='?')
161
516db87a04d4 cosmetic: pep8 compliance.
Ludovic Chabant <ludovic@chabant.com>
parents: 107
diff changeset
128 parser.add_argument(
852
4850f8c21b6e core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents: 792
diff changeset
129 '-n', '--name',
4850f8c21b6e core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents: 792
diff changeset
130 help="Limit the search to sources matching this name")
161
516db87a04d4 cosmetic: pep8 compliance.
Ludovic Chabant <ludovic@chabant.com>
parents: 107
diff changeset
131 parser.add_argument(
852
4850f8c21b6e core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents: 792
diff changeset
132 '--full-path',
4850f8c21b6e core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents: 792
diff changeset
133 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
134 action='store_true')
161
516db87a04d4 cosmetic: pep8 compliance.
Ludovic Chabant <ludovic@chabant.com>
parents: 107
diff changeset
135 parser.add_argument(
852
4850f8c21b6e core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents: 792
diff changeset
136 '--metadata',
4850f8c21b6e core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents: 792
diff changeset
137 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
138 action='store_true')
164
4534ccbdd2a3 find: Fix the `find` command, add more options.
Ludovic Chabant <ludovic@chabant.com>
parents: 163
diff changeset
139 parser.add_argument(
852
4850f8c21b6e core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents: 792
diff changeset
140 '--include-theme',
4850f8c21b6e core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents: 792
diff changeset
141 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
142 action='store_true')
164
4534ccbdd2a3 find: Fix the `find` command, add more options.
Ludovic Chabant <ludovic@chabant.com>
parents: 163
diff changeset
143 parser.add_argument(
852
4850f8c21b6e core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents: 792
diff changeset
144 '--exact',
4850f8c21b6e core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents: 792
diff changeset
145 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
146 "containing the pattern"),
4850f8c21b6e core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents: 792
diff changeset
147 action='store_true')
3
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
148
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
149 def run(self, ctx):
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
150 pattern = ctx.args.pattern
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
151 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
152 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
153 pattern = '*%s*' % pattern
4534ccbdd2a3 find: Fix the `find` command, add more options.
Ludovic Chabant <ludovic@chabant.com>
parents: 163
diff changeset
154
3
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
155 for src in sources:
164
4534ccbdd2a3 find: Fix the `find` command, add more options.
Ludovic Chabant <ludovic@chabant.com>
parents: 163
diff changeset
156 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
157 continue
4534ccbdd2a3 find: Fix the `find` command, add more options.
Ludovic Chabant <ludovic@chabant.com>
parents: 163
diff changeset
158 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
159 continue
4534ccbdd2a3 find: Fix the `find` command, add more options.
Ludovic Chabant <ludovic@chabant.com>
parents: 163
diff changeset
160
852
4850f8c21b6e core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents: 792
diff changeset
161 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
162 items = src.getAllContents()
4850f8c21b6e core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents: 792
diff changeset
163 for item in items:
4850f8c21b6e core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents: 792
diff changeset
164 if ctx.args.metadata:
4850f8c21b6e core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents: 792
diff changeset
165 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
166 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
167 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
168 logger.info("---")
4850f8c21b6e core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents: 792
diff changeset
169 else:
4850f8c21b6e core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents: 792
diff changeset
170 if is_fs_src:
4850f8c21b6e core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents: 792
diff changeset
171 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
172 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
173 if ctx.args.metadata:
4850f8c21b6e core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents: 792
diff changeset
174 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
175 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
176 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
177 logger.info("---")
4850f8c21b6e core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents: 792
diff changeset
178 else:
4850f8c21b6e core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents: 792
diff changeset
179 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
180 name = item.spec
4850f8c21b6e core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents: 792
diff changeset
181 logger.info(name)
3
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
182 else:
852
4850f8c21b6e core: Start of the big refactor for PieCrust 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents: 792
diff changeset
183 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
184 logger.info(item.spec)
3
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
185