3706: Add (skipped) test for broken max_manifest_depth=0 feature.
[arvados.git] / sdk / python / bin / arv-normalize
index 0a0adbe6af53e9ff3fcd0a0f3df2c0dcb69d62fb..b84910ef7efb582b38105e7293ccf0384c1c36d2 100755 (executable)
@@ -6,19 +6,33 @@ import os
 import re
 import string
 import sys
-import logging
-
-logger = logging.getLogger(os.path.basename(sys.argv[0]))
 
 parser = argparse.ArgumentParser(
-    description='Normalize contents of a manifest')
+    description='Read manifest on standard input and put normalized manifest on standard output.')
+
+parser.add_argument('--extract', type=str, help="The file to extract from the input manifest")
+parser.add_argument('--strip', action='store_true', help="Strip authorization tokens")
 
 args = parser.parse_args()
 
 import arvados
 
 r = sys.stdin.read()
-    
+
 cr = arvados.CollectionReader(r)
+cr.normalize()
 
-print cr.manifest_text()
+if args.extract:
+    i = args.extract.rfind('/')
+    if i == -1:
+        stream = '.'
+        fn = args.extract
+    else:
+        stream = args.extract[:i]
+        fn = args.extract[(i+1):]
+    for s in cr.all_streams():
+        if s.name() == stream:
+            if fn in s.files():
+                sys.stdout.write(s.files()[fn].as_manifest())
+else:
+    sys.stdout.write(cr.manifest_text(args.strip))