arvados.commands.normalize

 1#!/usr/bin/env python3
 2# Copyright (C) The Arvados Authors. All rights reserved.
 3#
 4# SPDX-License-Identifier: Apache-2.0
 5
 6import argparse
 7import hashlib
 8import os
 9import re
10import string
11import sys
12
13import arvados
14from arvados._version import __version__
15
16
17def get_parser():
18    parser = argparse.ArgumentParser(
19        description=(
20            'Read manifest on standard input and put normalized manifest'
21            ' on standard output.'
22        )
23    )
24    parser.add_argument('--extract', type=str,
25                        help="The file to extract from the input manifest")
26    parser.add_argument('--strip', action='store_true',
27                        help="Strip authorization tokens")
28    parser.add_argument('--version', action='version',
29                        version=f"%(prog)s {__version__}",
30                        help='Print version and exit.')
31    return parser
32
33
34def main(arguments=None):
35    parser = get_parser()
36    args = parser.parse_args(arguments)
37
38    r = sys.stdin.read()
39
40    cr = arvados.CollectionReader(r)
41
42    if args.extract:
43        i = args.extract.rfind('/')
44        if i == -1:
45            stream = '.'
46            fn = args.extract
47        else:
48            stream = args.extract[:i]
49            fn = args.extract[(i+1):]
50        for s in cr.all_streams():
51            if s.name() == stream:
52                if fn in s.files():
53                    sys.stdout.write(s.files()[fn].as_manifest())
54    else:
55        sys.stdout.write(cr.manifest_text(strip=args.strip, normalize=True))
56    sys.exit(0)
def get_parser():
18def get_parser():
19    parser = argparse.ArgumentParser(
20        description=(
21            'Read manifest on standard input and put normalized manifest'
22            ' on standard output.'
23        )
24    )
25    parser.add_argument('--extract', type=str,
26                        help="The file to extract from the input manifest")
27    parser.add_argument('--strip', action='store_true',
28                        help="Strip authorization tokens")
29    parser.add_argument('--version', action='version',
30                        version=f"%(prog)s {__version__}",
31                        help='Print version and exit.')
32    return parser
def main(arguments=None):
35def main(arguments=None):
36    parser = get_parser()
37    args = parser.parse_args(arguments)
38
39    r = sys.stdin.read()
40
41    cr = arvados.CollectionReader(r)
42
43    if args.extract:
44        i = args.extract.rfind('/')
45        if i == -1:
46            stream = '.'
47            fn = args.extract
48        else:
49            stream = args.extract[:i]
50            fn = args.extract[(i+1):]
51        for s in cr.all_streams():
52            if s.name() == stream:
53                if fn in s.files():
54                    sys.stdout.write(s.files()[fn].as_manifest())
55    else:
56        sys.stdout.write(cr.manifest_text(strip=args.strip, normalize=True))
57    sys.exit(0)