#!/usr/bin/env python
+# Copyright (C) The Arvados Authors. All rights reserved.
+#
+# SPDX-License-Identifier: Apache-2.0
import argparse
import hashlib
get_prefix = r.group(2)
if args.r and not get_prefix:
get_prefix = os.sep
- try:
- reader = arvados.CollectionReader(col_loc, num_retries=args.retries)
- except Exception as error:
- logger.error("failed to read collection: {}".format(error))
- return 1
# User asked to download the collection's manifest
if not get_prefix:
open_flags |= os.O_EXCL
try:
if args.destination == "-":
- stdout.write(reader.manifest_text(strip=args.strip_manifest).encode())
+ write_block_or_manifest(dest=stdout, src=col_loc,
+ api_client=api_client, args=args)
else:
out_fd = os.open(args.destination, open_flags)
with os.fdopen(out_fd, 'wb') as out_file:
- out_file.write(reader.manifest_text(strip=args.strip_manifest).encode())
+ write_block_or_manifest(dest=out_file,
+ src=col_loc, api_client=api_client,
+ args=args)
except (IOError, OSError) as error:
logger.error("can't write to '{}': {}".format(args.destination, error))
return 1
except (arvados.errors.ApiError, arvados.errors.KeepReadError) as error:
logger.error("failed to download '{}': {}".format(col_loc, error))
return 1
+ except arvados.errors.ArgumentError as error:
+ if 'Argument to CollectionReader' in str(error):
+ logger.error("error reading collection: {}".format(error))
+ return 1
+ else:
+ raise
return 0
+ try:
+ reader = arvados.CollectionReader(col_loc, num_retries=args.retries)
+ except Exception as error:
+ logger.error("failed to read collection: {}".format(error))
+ return 1
+
# Scan the collection. Make an array of (stream, file, local
# destination filename) tuples, and add up total size to extract.
todo = []
elif isinstance(c[i], arvados.collection.Subcollection):
for s, f in files_in_collection(c[i]):
yield (s, f)
+
+def write_block_or_manifest(dest, src, api_client, args):
+ if '+A' in src:
+ # block locator
+ kc = KeepClient(api_client=api_client)
+ dest.write(kc.get(src, num_retries=args.retries))
+ else:
+ # collection UUID or portable data hash
+ reader = arvados.CollectionReader(src, num_retries=args.retries)
+ dest.write(reader.manifest_text(strip=args.strip_manifest).encode())