3 from __future__ import print_function
8 import arvados.commands._util as arv_cmd
11 parser = argparse.ArgumentParser(
12 description='List contents of a manifest',
13 parents=[arv_cmd.retry_opt])
15 parser.add_argument('locator', type=str,
16 help="""Collection UUID or locator""")
17 parser.add_argument('-s', action='store_true',
18 help="""List file sizes, in KiB.""")
20 return parser.parse_args(args)
22 def size_formatter(coll_file):
23 return "{:>10}".format((coll_file.size() + 1023) / 1024)
25 def name_formatter(coll_file):
26 return "{}/{}".format(coll_file.stream_name(), coll_file.name)
28 def main(args, stdout, stderr, api_client=None):
29 args = parse_args(args)
31 if api_client is None:
32 api_client = arvados.api('v1')
35 cr = arvados.CollectionReader(args.locator, api_client=api_client,
36 num_retries=args.retries)
38 except (arvados.errors.ArgumentError,
39 arvados.errors.NotFoundError) as error:
40 print("arv-ls: error fetching collection: {}".format(error),
46 formatters.append(size_formatter)
47 formatters.append(name_formatter)
49 for f in cr.all_files():
50 print(*(info_func(f) for info_func in formatters), file=stdout)