Add 'apps/arv-web/' from commit 'f9732ad8460d013c2f28363655d0d1b91894dca5'
[arvados.git] / sdk / python / bin / arv-normalize
1 #!/usr/bin/env python
2
3 import argparse
4 import hashlib
5 import os
6 import re
7 import string
8 import sys
9
10 parser = argparse.ArgumentParser(
11     description='Read manifest on standard input and put normalized manifest on standard output.')
12
13 parser.add_argument('--extract', type=str, help="The file to extract from the input manifest")
14 parser.add_argument('--strip', action='store_true', help="Strip authorization tokens")
15
16 args = parser.parse_args()
17
18 import arvados
19
20 r = sys.stdin.read()
21
22 cr = arvados.CollectionReader(r)
23 cr.normalize()
24
25 if args.extract:
26     i = args.extract.rfind('/')
27     if i == -1:
28         stream = '.'
29         fn = args.extract
30     else:
31         stream = args.extract[:i]
32         fn = args.extract[(i+1):]
33     for s in cr.all_streams():
34         if s.name() == stream:
35             if fn in s.files():
36                 sys.stdout.write(s.files()[fn].as_manifest())
37 else:
38     sys.stdout.write(cr.manifest_text(args.strip))