comparison piecrust/commands/builtin/info.py @ 164:4534ccbdd2a3

find: Fix the `find` command, add more options. The `--endpoint` option doesn't make any sense anymore since page sources could have non-file-system endpoints. This was replaced with `--name` to match source names instead. Also added `--include-theme`, with filtering out theme pages by default, and `--exact` to explicitely match the given pattern, with matching anything that contains the pattern by default.
author Ludovic Chabant <ludovic@chabant.com>
date Thu, 01 Jan 2015 21:34:06 -0800
parents 6d23473fab41
children 56d6b17e057b
comparison
equal deleted inserted replaced
163:6d23473fab41 164:4534ccbdd2a3
110 self.description = "Find pages in the website." 110 self.description = "Find pages in the website."
111 111
112 def setupParser(self, parser, app): 112 def setupParser(self, parser, app):
113 parser.add_argument( 113 parser.add_argument(
114 'pattern', 114 'pattern',
115 help="The pattern to match with page slugs", 115 help="The pattern to match with page filenames",
116 nargs='?') 116 nargs='?')
117 parser.add_argument( 117 parser.add_argument(
118 '--endpoint', 118 '-n', '--name',
119 help="The endpoint(s) to look into", 119 help="Limit the search to sources matching this name")
120 nargs='+')
121 parser.add_argument( 120 parser.add_argument(
122 '--full-path', 121 '--full-path',
123 help="Return full paths instead of root-relative paths", 122 help="Return full paths instead of root-relative paths",
124 action='store_true') 123 action='store_true')
125 parser.add_argument( 124 parser.add_argument(
126 '--metadata', 125 '--metadata',
127 help="Return metadata about the page instead of just the path", 126 help="Return metadata about the page instead of just the path",
128 action='store_true') 127 action='store_true')
128 parser.add_argument(
129 '--include-theme',
130 help="Include theme pages to the search",
131 action='store_true')
132 parser.add_argument(
133 '--exact',
134 help=("Match the exact given pattern, instead of any page "
135 "containing the pattern"),
136 action='store_true')
129 137
130 def run(self, ctx): 138 def run(self, ctx):
131 pattern = ctx.args.pattern 139 pattern = ctx.args.pattern
132 sources = list(ctx.app.sources) 140 sources = list(ctx.app.sources)
133 if ctx.args.endpoint: 141 if not ctx.args.exact:
134 endpoints = ctx.args.endpoint 142 pattern = '*%s*' % pattern
135 sources = [s for s in sources if s.endpoint in endpoints] 143
136 for src in sources: 144 for src in sources:
145 if not ctx.args.include_theme and src.is_theme_source:
146 continue
147 if ctx.args.name and not fnmatch.fnmatch(src.name, ctx.args.name):
148 continue
149
137 page_facs = src.getPageFactories() 150 page_facs = src.getPageFactories()
138 for pf in page_facs: 151 for pf in page_facs:
139 name = os.path.relpath(pf.path, ctx.app.root_dir) 152 name = os.path.relpath(pf.path, ctx.app.root_dir)
140 if pattern is None or fnmatch.fnmatch(name, pattern): 153 if pattern is None or fnmatch.fnmatch(name, pattern):
141 if ctx.args.full_path: 154 if ctx.args.full_path: