import arvados
import arvados.commands._util as arv_cmd
+import arvados.util as util
from arvados._version import __version__
api_client = arvados.api('v1')
r = re.search(r'^(.*?)(/.*)?$', args.locator)
- collection = r.group(1)
+ col_loc = r.group(1)
get_prefix = r.group(2)
if args.r and not get_prefix:
get_prefix = os.sep
try:
- reader = arvados.CollectionReader(collection, num_retries=args.retries)
+ 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
+ should_strip_manifest = False
+ if re.match(util.keep_locator_pattern, col_loc):
+ should_strip_manifest = True
if not get_prefix:
if not args.n:
open_flags = os.O_CREAT | os.O_WRONLY
open_flags |= os.O_EXCL
try:
if args.destination == "-":
- stdout.write(reader.manifest_text())
+ stdout.write(reader.manifest_text(strip=should_strip_manifest))
else:
out_fd = os.open(args.destination, open_flags)
with os.fdopen(out_fd, 'wb') as out_file:
- out_file.write(reader.manifest_text())
+ out_file.write(reader.manifest_text(strip=should_strip_manifest))
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(collection, error))
+ logger.error("failed to download '{}': {}".format(col_loc, error))
return 1
return 0
shutil.rmtree(self.tempdir)
def write_test_collection(self,
+ strip_manifest=True,
contents = {
'foo.txt' : 'foo',
'bar.txt' : 'bar',
with c.open(path, 'w') as f:
f.write(data)
c.save_new()
- return (c.manifest_locator(), c.portable_data_hash(), c.manifest_text())
+ return (c.manifest_locator(),
+ c.portable_data_hash(),
+ c.manifest_text(strip=strip_manifest))
def run_get(self, args):
self.stdout = io.BytesIO()
def test_get_collection_manifest(self):
# Get the collection manifest
- r = self.run_get([self.col_loc, self.tempdir])
+ r = self.run_get([self.col_pdh, self.tempdir])
self.assertEqual(0, r)
- with open("{}/{}".format(self.tempdir, self.col_loc), "r") as f:
+ with open("{}/{}".format(self.tempdir, self.col_pdh), "r") as f:
self.assertEqual(self.col_manifest, f.read())
def test_invalid_collection(self):