diff 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
line wrap: on
line diff
--- a/piecrust/commands/builtin/baking.py	Wed Apr 01 00:26:54 2015 -0700
+++ b/piecrust/commands/builtin/baking.py	Wed Apr 01 00:27:38 2015 -0700
@@ -100,6 +100,10 @@
                 '-p', '--path',
                 help="A pattern that will be used to filter the relative path "
                      "of entries to show.")
+        parser.add_argument(
+                '-t', '--out',
+                help="A pattern that will be used to filter the output path "
+                     "of entries to show.")
 
     def run(self, ctx):
         out_dir = ctx.args.output or os.path.join(ctx.app.root_dir, '_counter')
@@ -110,6 +114,10 @@
         if ctx.args.path:
             pattern = '*%s*' % ctx.args.path.strip('*')
 
+        out_pattern = None
+        if ctx.args.out:
+            out_pattern = '*%s*' % ctx.args.out.strip('*')
+
         record_cache = ctx.app.cache.getCache('baker')
         if not record_cache.has(record_name):
             raise Exception("No record has been created for this output path. "
@@ -126,9 +134,13 @@
             logging.error("Status: failed")
         logging.info("Entries:")
         for entry in record.entries:
-            if pattern:
-                if not fnmatch.fnmatch(entry.rel_path, pattern):
-                    continue
+            if pattern and not fnmatch.fnmatch(entry.rel_path, pattern):
+                continue
+            if out_pattern and not (
+                    any([o for o in entry.out_paths
+                         if fnmatch.fnmatch(o, out_pattern)])):
+                continue
+
             logging.info(" - ")
             logging.info("   path:      %s" % entry.rel_path)
             logging.info("   spec:      %s:%s" % (entry.source_name,
@@ -160,9 +172,13 @@
             logging.error("Status: failed")
         logging.info("Entries:")
         for entry in record.entries:
-            if pattern:
-                if not fnmatch.fnmatch(entry.rel_input, pattern):
-                    continue
+            if pattern and not fnmatch.fnmatch(entry.rel_input, pattern):
+                continue
+            if out_pattern and not (
+                    any([o for o in entry.rel_outputs
+                         if fnmatch.fnmatch(o, out_pattern)])):
+                continue
+
             flags = []
             if entry.flags & FLAG_PREPARED:
                 flags.append('prepared')