3499: arv-put collections in home project if no --project-uuid specified.
[arvados.git] / sdk / python / arvados / commands / put.py
index fa648dac4592d6adee7821a0eac523355584cdc4..342915e541b39cdb661623362d5ab14e4a97d724 100644 (file)
@@ -352,31 +352,29 @@ def prep_project_link(args, stderr, project_exists=check_project_exists):
     # to create the desired project link for this Collection, or None.
     # Raises ValueError if the arguments request something impossible.
     making_collection = not (args.raw or args.stream)
-    any_link_spec = args.project_uuid or args.name
     if not making_collection:
-        if any_link_spec:
+        if args.name or args.project_uuid:
             raise ValueError("Requested a Link without creating a Collection")
         return None
-    elif not any_link_spec:
-        stderr.write(
-            "arv-put: No --project-uuid or --name specified.  This data will be cached\n"
-            "in Keep.  You will need to find this upload by its locator(s) later.\n")
-        return None
-    elif not args.project_uuid:
-        raise ValueError("--name requires --project-uuid")
-    elif not project_exists(args.project_uuid):
+    link = {'tail_uuid': args.project_uuid,
+            'link_class': 'name',
+            'name': args.name}
+    if not link['tail_uuid']:
+        link['tail_uuid'] = arvados.api('v1').users().current().execute()['uuid']
+    elif not project_exists(link['tail_uuid']):
         raise ValueError("Project {} not found".format(args.project_uuid))
-    link = {'tail_uuid': args.project_uuid, 'link_class': 'name'}
-    if args.name:
-        link['name'] = args.name
+    if not link['name']:
+        link['name'] = "Saved at {} by {}@{}".format(
+            datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S UTC"),
+            pwd.getpwuid(os.getuid()).pw_name,
+            socket.gethostname())
+        stderr.write(
+            "arv-put: No --name specified. Saving as \"%s\"\n" % link['name'])
+    link['owner_uuid'] = link['tail_uuid']
     return link
 
 def create_project_link(locator, link):
     link['head_uuid'] = locator
-    link.setdefault('name', "Collection saved by {}@{} at {}".format(
-            pwd.getpwuid(os.getuid()).pw_name,
-            socket.gethostname(),
-            datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S UTC")))
     return arvados.api('v1').links().create(body=link).execute()
 
 def main(arguments=None, stdout=sys.stdout, stderr=sys.stderr):