import arvados.commands._util as arv_cmd
CAUGHT_SIGNALS = [signal.SIGINT, signal.SIGQUIT, signal.SIGTERM]
+api_client = None
upload_opts = argparse.ArgumentParser(add_help=False)
STATE_PROPS = (arvados.ResumableCollectionWriter.STATE_PROPS +
['bytes_written', '_seen_inputs'])
- def __init__(self, cache=None, reporter=None, bytes_expected=None):
+ def __init__(self, cache=None, reporter=None, bytes_expected=None,
+ api_client=None):
self.bytes_written = 0
self._seen_inputs = []
self.cache = cache
self.reporter = reporter
self.bytes_expected = bytes_expected
- super(ArvPutCollectionWriter, self).__init__()
+ super(ArvPutCollectionWriter, self).__init__(api_client)
@classmethod
def from_cache(cls, cache, reporter=None, bytes_expected=None):
def check_project_exists(project_uuid):
try:
- arvados.api('v1').groups().get(uuid=project_uuid).execute()
+ api_client.groups().get(uuid=project_uuid).execute()
except (apiclient.errors.Error, arvados.errors.NotFoundError) as error:
raise ValueError("Project {} not found ({})".format(project_uuid,
error))
'link_class': 'name',
'name': args.name}
if not link['tail_uuid']:
- link['tail_uuid'] = arvados.api('v1').users().current().execute()['uuid']
+ link['tail_uuid'] = api_client.users().current().execute()['uuid']
elif not project_exists(link['tail_uuid']):
raise ValueError("Project {} not found".format(args.project_uuid))
if not link['name']:
def create_project_link(locator, link):
link['head_uuid'] = locator
- return arvados.api('v1').links().create(body=link).execute()
+ return api_client.links().create(body=link).execute()
def main(arguments=None, stdout=sys.stdout, stderr=sys.stderr):
+ global api_client
+ if api_client is None:
+ api_client = arvados.api('v1')
status = 0
args = parse_arguments(arguments)
output = ','.join(writer.data_locators())
else:
# Register the resulting collection in Arvados.
- collection = arvados.api().collections().create(
+ collection = api_client.collections().create(
body={
- 'uuid': writer.finish(),
'manifest_text': writer.manifest_text(),
+ 'owner_uuid': project_link['tail_uuid']
},
).execute()
- # Print the locator (uuid) of the new collection.
output = collection['uuid']
if project_link is not None:
+ # Update collection name
try:
- create_project_link(output, project_link)
+ if 'name' in collection:
+ arvados.api().collections().update(uuid=output,
+ body={"name": project_link["name"]}).execute()
+ else:
+ create_project_link(output, project_link)
except apiclient.errors.Error as error:
print >>stderr, (
"arv-put: Error adding Collection to project: {}.".format(
error))
status = 1
+ # Print the locator (uuid) of the new collection.
stdout.write(output)
if not output.endswith('\n'):
stdout.write('\n')