Mercurial > piecrust2
comparison piecrust/commands/builtin/baking.py @ 331:f0fc2a9d3191
showrecord: Add ability to filter on the output path.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Wed, 01 Apr 2015 00:27:38 -0700 |
parents | f82262f59600 |
children | b034f6f15e22 |
comparison
equal
deleted
inserted
replaced
330:de4903457bed | 331:f0fc2a9d3191 |
---|---|
98 nargs='?') | 98 nargs='?') |
99 parser.add_argument( | 99 parser.add_argument( |
100 '-p', '--path', | 100 '-p', '--path', |
101 help="A pattern that will be used to filter the relative path " | 101 help="A pattern that will be used to filter the relative path " |
102 "of entries to show.") | 102 "of entries to show.") |
103 parser.add_argument( | |
104 '-t', '--out', | |
105 help="A pattern that will be used to filter the output path " | |
106 "of entries to show.") | |
103 | 107 |
104 def run(self, ctx): | 108 def run(self, ctx): |
105 out_dir = ctx.args.output or os.path.join(ctx.app.root_dir, '_counter') | 109 out_dir = ctx.args.output or os.path.join(ctx.app.root_dir, '_counter') |
106 record_name = (hashlib.md5(out_dir.encode('utf8')).hexdigest() + | 110 record_name = (hashlib.md5(out_dir.encode('utf8')).hexdigest() + |
107 '.record') | 111 '.record') |
108 | 112 |
109 pattern = None | 113 pattern = None |
110 if ctx.args.path: | 114 if ctx.args.path: |
111 pattern = '*%s*' % ctx.args.path.strip('*') | 115 pattern = '*%s*' % ctx.args.path.strip('*') |
116 | |
117 out_pattern = None | |
118 if ctx.args.out: | |
119 out_pattern = '*%s*' % ctx.args.out.strip('*') | |
112 | 120 |
113 record_cache = ctx.app.cache.getCache('baker') | 121 record_cache = ctx.app.cache.getCache('baker') |
114 if not record_cache.has(record_name): | 122 if not record_cache.has(record_name): |
115 raise Exception("No record has been created for this output path. " | 123 raise Exception("No record has been created for this output path. " |
116 "Did you bake there yet?") | 124 "Did you bake there yet?") |
124 logging.info("Status: success") | 132 logging.info("Status: success") |
125 else: | 133 else: |
126 logging.error("Status: failed") | 134 logging.error("Status: failed") |
127 logging.info("Entries:") | 135 logging.info("Entries:") |
128 for entry in record.entries: | 136 for entry in record.entries: |
129 if pattern: | 137 if pattern and not fnmatch.fnmatch(entry.rel_path, pattern): |
130 if not fnmatch.fnmatch(entry.rel_path, pattern): | 138 continue |
131 continue | 139 if out_pattern and not ( |
140 any([o for o in entry.out_paths | |
141 if fnmatch.fnmatch(o, out_pattern)])): | |
142 continue | |
143 | |
132 logging.info(" - ") | 144 logging.info(" - ") |
133 logging.info(" path: %s" % entry.rel_path) | 145 logging.info(" path: %s" % entry.rel_path) |
134 logging.info(" spec: %s:%s" % (entry.source_name, | 146 logging.info(" spec: %s:%s" % (entry.source_name, |
135 entry.rel_path)) | 147 entry.rel_path)) |
136 logging.info(" taxonomy: %s:%s" % (entry.taxonomy_name, | 148 logging.info(" taxonomy: %s:%s" % (entry.taxonomy_name, |
158 logging.info("Status: success") | 170 logging.info("Status: success") |
159 else: | 171 else: |
160 logging.error("Status: failed") | 172 logging.error("Status: failed") |
161 logging.info("Entries:") | 173 logging.info("Entries:") |
162 for entry in record.entries: | 174 for entry in record.entries: |
163 if pattern: | 175 if pattern and not fnmatch.fnmatch(entry.rel_input, pattern): |
164 if not fnmatch.fnmatch(entry.rel_input, pattern): | 176 continue |
165 continue | 177 if out_pattern and not ( |
178 any([o for o in entry.rel_outputs | |
179 if fnmatch.fnmatch(o, out_pattern)])): | |
180 continue | |
181 | |
166 flags = [] | 182 flags = [] |
167 if entry.flags & FLAG_PREPARED: | 183 if entry.flags & FLAG_PREPARED: |
168 flags.append('prepared') | 184 flags.append('prepared') |
169 if entry.flags & FLAG_PROCESSED: | 185 if entry.flags & FLAG_PROCESSED: |
170 flags.append('processed') | 186 flags.append('processed') |