projects
/
arvados.git
/ blobdiff
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
3699: accept collection hash as uuid
[arvados.git]
/
sdk
/
python
/
arvados
/
commands
/
put.py
diff --git
a/sdk/python/arvados/commands/put.py
b/sdk/python/arvados/commands/put.py
index 335ef174de6dcb860f6d13ee9ec32e330d54cc31..7b6b048b1d035adc7b3b3399fd77a2c81e3bed3b 100644
(file)
--- a/
sdk/python/arvados/commands/put.py
+++ b/
sdk/python/arvados/commands/put.py
@@
-22,6
+22,7
@@
import tempfile
import arvados.commands._util as arv_cmd
CAUGHT_SIGNALS = [signal.SIGINT, signal.SIGQUIT, signal.SIGTERM]
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)
upload_opts = argparse.ArgumentParser(add_help=False)
@@
-238,13
+239,14
@@
class ArvPutCollectionWriter(arvados.ResumableCollectionWriter):
STATE_PROPS = (arvados.ResumableCollectionWriter.STATE_PROPS +
['bytes_written', '_seen_inputs'])
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
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):
@classmethod
def from_cache(cls, cache, reporter=None, bytes_expected=None):
@@
-342,7
+344,7
@@
def exit_signal_handler(sigcode, frame):
def check_project_exists(project_uuid):
try:
def check_project_exists(project_uuid):
try:
- a
rvados.api('v1')
.groups().get(uuid=project_uuid).execute()
+ a
pi_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))
except (apiclient.errors.Error, arvados.errors.NotFoundError) as error:
raise ValueError("Project {} not found ({})".format(project_uuid,
error))
@@
-362,7
+364,7
@@
def prep_project_link(args, stderr, project_exists=check_project_exists):
'link_class': 'name',
'name': args.name}
if not link['tail_uuid']:
'link_class': 'name',
'name': args.name}
if not link['tail_uuid']:
- link['tail_uuid'] = a
rvados.api('v1')
.users().current().execute()['uuid']
+ link['tail_uuid'] = a
pi_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']:
elif not project_exists(link['tail_uuid']):
raise ValueError("Project {} not found".format(args.project_uuid))
if not link['name']:
@@
-377,9
+379,12
@@
def prep_project_link(args, stderr, project_exists=check_project_exists):
def create_project_link(locator, link):
link['head_uuid'] = locator
def create_project_link(locator, link):
link['head_uuid'] = locator
- return a
rvados.api('v1')
.links().create(body=link).execute()
+ return a
pi_client
.links().create(body=link).execute()
def main(arguments=None, stdout=sys.stdout, stderr=sys.stderr):
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)
status = 0
args = parse_arguments(arguments)
@@
-445,23
+450,33
@@
def main(arguments=None, stdout=sys.stdout, stderr=sys.stderr):
output = ','.join(writer.data_locators())
else:
# Register the resulting collection in Arvados.
output = ','.join(writer.data_locators())
else:
# Register the resulting collection in Arvados.
- collection = a
rvados.api()
.collections().create(
+ collection = a
pi_client
.collections().create(
body={
'manifest_text': writer.manifest_text(),
body={
'manifest_text': writer.manifest_text(),
+ 'owner_uuid': project_link['tail_uuid']
},
).execute()
},
).execute()
- # Print the locator (uuid) of the new collection.
- output = collection['uuid']
+ if 'portable_data_hash' in collection and collection['portable_data_hash']:
+ output = collection['portable_data_hash']
+ else:
+ output = collection['uuid']
+
if project_link is not None:
if project_link is not None:
+ # Update collection name
try:
try:
- create_project_link(output, project_link)
+ if 'name' in collection:
+ arvados.api().collections().update(uuid=collection['uuid'],
+ 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
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')
stdout.write(output)
if not output.endswith('\n'):
stdout.write('\n')