comparison piecrust/commands/builtin/info.py @ 852:4850f8c21b6e

core: Start of the big refactor for PieCrust 3.0. * Everything is a `ContentSource`, including assets directories. * Most content sources are subclasses of the base file-system source. * A source is processed by a "pipeline", and there are 2 built-in pipelines, one for assets and one for pages. The asset pipeline is vaguely functional, but the page pipeline is completely broken right now. * Rewrite the baking process as just running appropriate pipelines on each content item. This should allow for better parallelization.
author Ludovic Chabant <ludovic@chabant.com>
date Wed, 17 May 2017 00:11:48 -0700
parents 58ebf50235a5
children 58ae026b4c31
comparison
equal deleted inserted replaced
851:2c7e57d80bba 852:4850f8c21b6e
1 import os.path 1 import os.path
2 import logging 2 import logging
3 import fnmatch 3 import fnmatch
4 from piecrust.commands.base import ChefCommand 4 from piecrust.commands.base import ChefCommand
5 from piecrust.configuration import ConfigurationDumper 5 from piecrust.configuration import ConfigurationDumper
6 from piecrust.sources.fs import FSContentSourceBase
6 7
7 8
8 logger = logging.getLogger(__name__) 9 logger = logging.getLogger(__name__)
9 10
10 11
27 self.name = 'showconfig' 28 self.name = 'showconfig'
28 self.description = ("Shows the website's configuration.") 29 self.description = ("Shows the website's configuration.")
29 30
30 def setupParser(self, parser, app): 31 def setupParser(self, parser, app):
31 parser.add_argument( 32 parser.add_argument(
32 'path', 33 'path',
33 help="The path to a config section or value", 34 help="The path to a config section or value",
34 nargs='?') 35 nargs='?')
35 36
36 def run(self, ctx): 37 def run(self, ctx):
37 if ctx.args.path: 38 if ctx.args.path:
38 show = ctx.app.config.get(ctx.args.path) 39 show = ctx.app.config.get(ctx.args.path)
39 else: 40 else:
63 64
64 def run(self, ctx): 65 def run(self, ctx):
65 for src in ctx.app.sources: 66 for src in ctx.app.sources:
66 logger.info("%s:" % src.name) 67 logger.info("%s:" % src.name)
67 logger.info(" type: %s" % src.config.get('type')) 68 logger.info(" type: %s" % src.config.get('type'))
68 logger.info(" class: %s" % type(src)) 69 logger.debug(" class: %s" % type(src))
70 desc = src.describe()
71 if isinstance(desc, dict):
72 for k, v in desc.items():
73 logger.info(" %s: %s" % (k, v))
69 74
70 75
71 class ShowRoutesCommand(ChefCommand): 76 class ShowRoutesCommand(ChefCommand):
72 def __init__(self): 77 def __init__(self):
73 super(ShowRoutesCommand, self).__init__() 78 super(ShowRoutesCommand, self).__init__()
79 84
80 def run(self, ctx): 85 def run(self, ctx):
81 for route in ctx.app.routes: 86 for route in ctx.app.routes:
82 logger.info("%s:" % route.uri_pattern) 87 logger.info("%s:" % route.uri_pattern)
83 logger.info(" source: %s" % (route.source_name or '')) 88 logger.info(" source: %s" % (route.source_name or ''))
84 logger.info(" generator: %s" % (route.generator_name or ''))
85 logger.info(" regex: %s" % route.uri_re.pattern) 89 logger.info(" regex: %s" % route.uri_re.pattern)
86 logger.info(" function: %s(%s)" % ( 90 logger.info(" function: %s(%s)" % (
87 route.func_name, 91 route.func_name,
88 ', '.join(route.uri_params))) 92 ', '.join(route.uri_params)))
89 93
116 self.name = 'find' 120 self.name = 'find'
117 self.description = "Find pages in the website." 121 self.description = "Find pages in the website."
118 122
119 def setupParser(self, parser, app): 123 def setupParser(self, parser, app):
120 parser.add_argument( 124 parser.add_argument(
121 'pattern', 125 'pattern',
122 help="The pattern to match with page filenames", 126 help="The pattern to match with page filenames",
123 nargs='?') 127 nargs='?')
124 parser.add_argument( 128 parser.add_argument(
125 '-n', '--name', 129 '-n', '--name',
126 help="Limit the search to sources matching this name") 130 help="Limit the search to sources matching this name")
127 parser.add_argument( 131 parser.add_argument(
128 '--full-path', 132 '--full-path',
129 help="Return full paths instead of root-relative paths", 133 help="Return full paths instead of root-relative paths",
130 action='store_true') 134 action='store_true')
131 parser.add_argument( 135 parser.add_argument(
132 '--metadata', 136 '--metadata',
133 help="Return metadata about the page instead of just the path", 137 help="Return metadata about the page instead of just the path",
134 action='store_true') 138 action='store_true')
135 parser.add_argument( 139 parser.add_argument(
136 '--include-theme', 140 '--include-theme',
137 help="Include theme pages to the search", 141 help="Include theme pages to the search",
138 action='store_true') 142 action='store_true')
139 parser.add_argument( 143 parser.add_argument(
140 '--exact', 144 '--exact',
141 help=("Match the exact given pattern, instead of any page " 145 help=("Match the exact given pattern, instead of any page "
142 "containing the pattern"), 146 "containing the pattern"),
143 action='store_true') 147 action='store_true')
144 148
145 def run(self, ctx): 149 def run(self, ctx):
146 pattern = ctx.args.pattern 150 pattern = ctx.args.pattern
147 sources = list(ctx.app.sources) 151 sources = list(ctx.app.sources)
148 if not ctx.args.exact and pattern is not None: 152 if not ctx.args.exact and pattern is not None:
152 if not ctx.args.include_theme and src.is_theme_source: 156 if not ctx.args.include_theme and src.is_theme_source:
153 continue 157 continue
154 if ctx.args.name and not fnmatch.fnmatch(src.name, ctx.args.name): 158 if ctx.args.name and not fnmatch.fnmatch(src.name, ctx.args.name):
155 continue 159 continue
156 160
157 page_facs = src.getPageFactories() 161 is_fs_src = isinstance(src, FSContentSourceBase)
158 for pf in page_facs: 162 items = src.getAllContents()
159 name = os.path.relpath(pf.path, ctx.app.root_dir) 163 for item in items:
160 if pattern is None or fnmatch.fnmatch(name, pattern): 164 if ctx.args.metadata:
161 if ctx.args.full_path: 165 logger.info("spec:%s" % item.spec)
162 name = pf.path 166 for key, val in item.metadata.items():
163 if ctx.args.metadata: 167 logger.info("%s:%s" % (key, val))
164 logger.info("path:%s" % pf.path) 168 logger.info("---")
165 for key, val in pf.metadata.items(): 169 else:
166 logger.info("%s:%s" % (key, val)) 170 if is_fs_src:
167 logger.info("---") 171 name = os.path.relpath(item.spec, ctx.app.root_dir)
172 if pattern is None or fnmatch.fnmatch(name, pattern):
173 if ctx.args.metadata:
174 logger.info("path:%s" % item.spec)
175 for key, val in item.metadata.items():
176 logger.info("%s:%s" % (key, val))
177 logger.info("---")
178 else:
179 if ctx.args.full_path:
180 name = item.spec
181 logger.info(name)
168 else: 182 else:
169 logger.info(name) 183 if pattern is None or fnmatch.fnmatch(name, pattern):
184 logger.info(item.spec)
170 185