annotate piecrust/commands/builtin/info.py @ 411:e7b865f8f335

bake: Enable multiprocess baking. Baking is now done by running a worker per CPU, and sending jobs to them. This changes several things across the codebase: * Ability to not cache things related to pages other than the 'main' page (i.e. the page at the bottom of the execution stack). * Decouple the baking process from the bake records, so only the main process keeps track (and modifies) the bake record. * Remove the need for 'batch page getters' and loading a page directly from the page factories. There are various smaller changes too included here, including support for scope performance timers that are saved with the bake record and can be printed out to the console. Yes I got carried away. For testing, the in-memory 'mock' file-system doesn't work anymore, since we're spawning processes, so this is replaced by a 'tmpfs' file-system which is saved in temporary files on disk and deleted after tests have run.
author Ludovic Chabant <ludovic@chabant.com>
date Fri, 12 Jun 2015 17:09:19 -0700
parents 794b047c9726
children a65f04ddbea2
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
1
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
aaa8fb7c8918 Re-arranged modules to reduce dependencies to builtin stuff.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
8 logger = logging.getLogger(__name__)
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
aaa8fb7c8918 Re-arranged modules to reduce dependencies to builtin stuff.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
11 class RootCommand(ChefCommand):
aaa8fb7c8918 Re-arranged modules to reduce dependencies to builtin stuff.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
12 def __init__(self):
aaa8fb7c8918 Re-arranged modules to reduce dependencies to builtin stuff.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
13 super(RootCommand, self).__init__()
aaa8fb7c8918 Re-arranged modules to reduce dependencies to builtin stuff.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
14 self.name = 'root'
aaa8fb7c8918 Re-arranged modules to reduce dependencies to builtin stuff.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
15 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
16
3
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
17 def setupParser(self, parser, app):
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
18 pass
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
19
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
20 def run(self, ctx):
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
21 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
22
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 class ShowConfigCommand(ChefCommand):
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
25 def __init__(self):
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
26 super(ShowConfigCommand, self).__init__()
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
27 self.name = 'showconfig'
161
516db87a04d4 cosmetic: pep8 compliance.
Ludovic Chabant <ludovic@chabant.com>
parents: 107
diff changeset
28 self.description = ("Prints part of, or the entirety of, "
516db87a04d4 cosmetic: pep8 compliance.
Ludovic Chabant <ludovic@chabant.com>
parents: 107
diff changeset
29 "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(
516db87a04d4 cosmetic: pep8 compliance.
Ludovic Chabant <ludovic@chabant.com>
parents: 107
diff changeset
33 'path',
3
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
34 help="The path to a config section or value",
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
35 nargs='?')
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):
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
38 show = ctx.app.config.get(ctx.args.path)
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
39 if show is not None:
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
40 if isinstance(show, (dict, list)):
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
41 import yaml
107
10fc9c8bf682 Better support for times in YAML interop.
Ludovic Chabant <ludovic@chabant.com>
parents: 5
diff changeset
42 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
43 Dumper=ConfigurationDumper)
3
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
44 logger.info(out)
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
45 else:
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
46 logger.info(show)
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
47 elif ctx.args.path:
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
48 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
49 ctx.result = 1
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
50
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
51
163
6d23473fab41 sources: Add `chef sources` command to list page sources.
Ludovic Chabant <ludovic@chabant.com>
parents: 162
diff changeset
52 class ShowSourcesCommand(ChefCommand):
6d23473fab41 sources: Add `chef sources` command to list page sources.
Ludovic Chabant <ludovic@chabant.com>
parents: 162
diff changeset
53 def __init__(self):
6d23473fab41 sources: Add `chef sources` command to list page sources.
Ludovic Chabant <ludovic@chabant.com>
parents: 162
diff changeset
54 super(ShowSourcesCommand, self).__init__()
6d23473fab41 sources: Add `chef sources` command to list page sources.
Ludovic Chabant <ludovic@chabant.com>
parents: 162
diff changeset
55 self.name = 'sources'
6d23473fab41 sources: Add `chef sources` command to list page sources.
Ludovic Chabant <ludovic@chabant.com>
parents: 162
diff changeset
56 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
57
6d23473fab41 sources: Add `chef sources` command to list page sources.
Ludovic Chabant <ludovic@chabant.com>
parents: 162
diff changeset
58 def setupParser(self, parser, app):
6d23473fab41 sources: Add `chef sources` command to list page sources.
Ludovic Chabant <ludovic@chabant.com>
parents: 162
diff changeset
59 pass
6d23473fab41 sources: Add `chef sources` command to list page sources.
Ludovic Chabant <ludovic@chabant.com>
parents: 162
diff changeset
60
6d23473fab41 sources: Add `chef sources` command to list page sources.
Ludovic Chabant <ludovic@chabant.com>
parents: 162
diff changeset
61 def run(self, ctx):
6d23473fab41 sources: Add `chef sources` command to list page sources.
Ludovic Chabant <ludovic@chabant.com>
parents: 162
diff changeset
62 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
63 logger.info("%s:" % src.name)
6d23473fab41 sources: Add `chef sources` command to list page sources.
Ludovic Chabant <ludovic@chabant.com>
parents: 162
diff changeset
64 logger.info(" type: %s" % src.config.get('type'))
6d23473fab41 sources: Add `chef sources` command to list page sources.
Ludovic Chabant <ludovic@chabant.com>
parents: 162
diff changeset
65 logger.info(" class: %s" % type(src))
6d23473fab41 sources: Add `chef sources` command to list page sources.
Ludovic Chabant <ludovic@chabant.com>
parents: 162
diff changeset
66
6d23473fab41 sources: Add `chef sources` command to list page sources.
Ludovic Chabant <ludovic@chabant.com>
parents: 162
diff changeset
67
3
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
68 class ShowRoutesCommand(ChefCommand):
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
69 def __init__(self):
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
70 super(ShowRoutesCommand, self).__init__()
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
71 self.name = 'routes'
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
72 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
73
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
74 def setupParser(self, parser, app):
1
aaa8fb7c8918 Re-arranged modules to reduce dependencies to builtin stuff.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
75 pass
aaa8fb7c8918 Re-arranged modules to reduce dependencies to builtin stuff.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
76
aaa8fb7c8918 Re-arranged modules to reduce dependencies to builtin stuff.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
77 def run(self, ctx):
3
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
78 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
79 logger.info("%s:" % route.uri_pattern)
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
80 logger.info(" source: %s" % route.source_name)
334
b034f6f15e22 bake: Several bug taxonomy-related fixes for incorrect incremental bakes.
Ludovic Chabant <ludovic@chabant.com>
parents: 307
diff changeset
81 logger.info(" taxonomy: %s" % (route.taxonomy_name or ''))
168
56d6b17e057b routes: Show regex patterns for routes.
Ludovic Chabant <ludovic@chabant.com>
parents: 164
diff changeset
82 logger.info(" regex: %s" % route.uri_re.pattern)
3
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
83
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
84
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
85 class ShowPathsCommand(ChefCommand):
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
86 def __init__(self):
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
87 super(ShowPathsCommand, self).__init__()
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
88 self.name = 'paths'
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
89 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
90
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
91 def setupParser(self, parser, app):
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
92 pass
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 def run(self, ctx):
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
95 app = ctx.app
307
869a206facd5 internal: Remove mentions of plugins directories and sources.
Ludovic Chabant <ludovic@chabant.com>
parents: 168
diff changeset
96 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
97 for p in paths:
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
98 value = getattr(app, p)
162
c4b155b08b52 paths: properly format lists of paths.
Ludovic Chabant <ludovic@chabant.com>
parents: 161
diff changeset
99 if isinstance(value, list):
c4b155b08b52 paths: properly format lists of paths.
Ludovic Chabant <ludovic@chabant.com>
parents: 161
diff changeset
100 logging.info("%s:" % p)
c4b155b08b52 paths: properly format lists of paths.
Ludovic Chabant <ludovic@chabant.com>
parents: 161
diff changeset
101 for v in value:
c4b155b08b52 paths: properly format lists of paths.
Ludovic Chabant <ludovic@chabant.com>
parents: 161
diff changeset
102 logging.info(" - %s" % v)
3
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
103 else:
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
104 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
105
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
106
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
107 class FindCommand(ChefCommand):
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
108 def __init__(self):
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
109 super(FindCommand, self).__init__()
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
110 self.name = 'find'
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
111 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
112
3
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
113 def setupParser(self, parser, app):
161
516db87a04d4 cosmetic: pep8 compliance.
Ludovic Chabant <ludovic@chabant.com>
parents: 107
diff changeset
114 parser.add_argument(
516db87a04d4 cosmetic: pep8 compliance.
Ludovic Chabant <ludovic@chabant.com>
parents: 107
diff changeset
115 'pattern',
164
4534ccbdd2a3 find: Fix the `find` command, add more options.
Ludovic Chabant <ludovic@chabant.com>
parents: 163
diff changeset
116 help="The pattern to match with page filenames",
3
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
117 nargs='?')
161
516db87a04d4 cosmetic: pep8 compliance.
Ludovic Chabant <ludovic@chabant.com>
parents: 107
diff changeset
118 parser.add_argument(
164
4534ccbdd2a3 find: Fix the `find` command, add more options.
Ludovic Chabant <ludovic@chabant.com>
parents: 163
diff changeset
119 '-n', '--name',
4534ccbdd2a3 find: Fix the `find` command, add more options.
Ludovic Chabant <ludovic@chabant.com>
parents: 163
diff changeset
120 help="Limit the search to sources matching this name")
161
516db87a04d4 cosmetic: pep8 compliance.
Ludovic Chabant <ludovic@chabant.com>
parents: 107
diff changeset
121 parser.add_argument(
516db87a04d4 cosmetic: pep8 compliance.
Ludovic Chabant <ludovic@chabant.com>
parents: 107
diff changeset
122 '--full-path',
3
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
123 help="Return full paths instead of root-relative paths",
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
124 action='store_true')
161
516db87a04d4 cosmetic: pep8 compliance.
Ludovic Chabant <ludovic@chabant.com>
parents: 107
diff changeset
125 parser.add_argument(
516db87a04d4 cosmetic: pep8 compliance.
Ludovic Chabant <ludovic@chabant.com>
parents: 107
diff changeset
126 '--metadata',
3
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
127 help="Return metadata about the page instead of just the path",
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
128 action='store_true')
164
4534ccbdd2a3 find: Fix the `find` command, add more options.
Ludovic Chabant <ludovic@chabant.com>
parents: 163
diff changeset
129 parser.add_argument(
4534ccbdd2a3 find: Fix the `find` command, add more options.
Ludovic Chabant <ludovic@chabant.com>
parents: 163
diff changeset
130 '--include-theme',
4534ccbdd2a3 find: Fix the `find` command, add more options.
Ludovic Chabant <ludovic@chabant.com>
parents: 163
diff changeset
131 help="Include theme pages to the search",
4534ccbdd2a3 find: Fix the `find` command, add more options.
Ludovic Chabant <ludovic@chabant.com>
parents: 163
diff changeset
132 action='store_true')
4534ccbdd2a3 find: Fix the `find` command, add more options.
Ludovic Chabant <ludovic@chabant.com>
parents: 163
diff changeset
133 parser.add_argument(
4534ccbdd2a3 find: Fix the `find` command, add more options.
Ludovic Chabant <ludovic@chabant.com>
parents: 163
diff changeset
134 '--exact',
4534ccbdd2a3 find: Fix the `find` command, add more options.
Ludovic Chabant <ludovic@chabant.com>
parents: 163
diff changeset
135 help=("Match the exact given pattern, instead of any page "
4534ccbdd2a3 find: Fix the `find` command, add more options.
Ludovic Chabant <ludovic@chabant.com>
parents: 163
diff changeset
136 "containing the pattern"),
4534ccbdd2a3 find: Fix the `find` command, add more options.
Ludovic Chabant <ludovic@chabant.com>
parents: 163
diff changeset
137 action='store_true')
3
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
138
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
139 def run(self, ctx):
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
140 pattern = ctx.args.pattern
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
141 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
142 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
143 pattern = '*%s*' % pattern
4534ccbdd2a3 find: Fix the `find` command, add more options.
Ludovic Chabant <ludovic@chabant.com>
parents: 163
diff changeset
144
3
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
145 for src in sources:
164
4534ccbdd2a3 find: Fix the `find` command, add more options.
Ludovic Chabant <ludovic@chabant.com>
parents: 163
diff changeset
146 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
147 continue
4534ccbdd2a3 find: Fix the `find` command, add more options.
Ludovic Chabant <ludovic@chabant.com>
parents: 163
diff changeset
148 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
149 continue
4534ccbdd2a3 find: Fix the `find` command, add more options.
Ludovic Chabant <ludovic@chabant.com>
parents: 163
diff changeset
150
3
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
151 page_facs = src.getPageFactories()
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
152 for pf in page_facs:
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
153 name = os.path.relpath(pf.path, ctx.app.root_dir)
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
154 if pattern is None or fnmatch.fnmatch(name, pattern):
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
155 if ctx.args.full_path:
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
156 name = pf.path
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
157 if ctx.args.metadata:
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
158 logger.info("path:%s" % pf.path)
5
474c9882decf Upgrade to Python 3.
Ludovic Chabant <ludovic@chabant.com>
parents: 3
diff changeset
159 for key, val in pf.metadata.items():
3
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
160 logger.info("%s:%s" % (key, val))
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
161 logger.info("---")
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
162 else:
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
163 logger.info(name)
f485ba500df3 Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents: 1
diff changeset
164