3 from __future__ import print_function
9 import arvados.commands._util as arv_cmd
11 from arvados._version import __version__
14 parser = argparse.ArgumentParser(
15 description='List contents of a manifest',
16 parents=[arv_cmd.retry_opt])
18 parser.add_argument('locator', type=str,
19 help="""Collection UUID or locator""")
20 parser.add_argument('-s', action='store_true',
21 help="""List file sizes, in KiB.""")
22 parser.add_argument('--version', action='version',
23 version="%s %s" % (sys.argv[0], __version__),
24 help='Print version and exit.')
26 return parser.parse_args(args)
28 def size_formatter(coll_file):
29 return "{:>10}".format((coll_file.size() + 1023) / 1024)
31 def name_formatter(coll_file):
32 return "{}/{}".format(coll_file.stream_name(), coll_file.name)
34 def main(args, stdout, stderr, api_client=None):
35 args = parse_args(args)
37 if api_client is None:
38 api_client = arvados.api('v1')
41 cr = arvados.CollectionReader(args.locator, api_client=api_client,
42 num_retries=args.retries)
44 except (arvados.errors.ArgumentError,
45 arvados.errors.NotFoundError) as error:
46 print("arv-ls: error fetching collection: {}".format(error),
52 formatters.append(size_formatter)
53 formatters.append(name_formatter)
55 for f in cr.all_files():
56 print(*(info_func(f) for info_func in formatters), file=stdout)