+def check_project_exists(project_uuid):
+ try:
+ 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))
+ else:
+ return True
+
+def prep_project_link(args, stderr, project_exists=check_project_exists):
+ # Given the user's command line arguments, return a dictionary with data
+ # 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)
+ if not making_collection:
+ if args.name or args.project_uuid:
+ raise ValueError("Requested a Link without creating a Collection")
+ return None
+ link = {'tail_uuid': args.project_uuid,
+ 'link_class': 'name',
+ 'name': args.name}
+ if not link['tail_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']:
+ 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
+ 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
+