From 971e2ff76ad8de454e5f606d24d6326673421d40 Mon Sep 17 00:00:00 2001 From: Ross Scroggs Date: Tue, 14 Apr 2020 15:31:14 -0700 Subject: [PATCH] Make it easy to capture created drive file ID (#1159) Linux/MacOS fileId=`gam user user@domain.com create drivefile ...` Windows PowerShell $fileId = & gam user user@domain.com create drivefile ...` --- src/GamCommands.txt | 2 +- src/gam.py | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/GamCommands.txt b/src/GamCommands.txt index 2ea86bfb..7bec48df 100644 --- a/src/GamCommands.txt +++ b/src/GamCommands.txt @@ -1299,7 +1299,7 @@ gam show fileinfo [allfields|*] gam show filerevisions gam show filetree [anyowner] (orderby [ascending|descending])* -gam create|add drivefile [drivefilename ] * [csv] [todrive] +gam create|add drivefile [drivefilename ] * [csv] [todrive] [returnidonly] gam update drivefile (id )|(query ] * gam get drivefile (id )|(drivefilename )|(query ) [revision ] [(format )|(csvsheet )] diff --git a/src/gam.py b/src/gam.py index db76eef2..9b6bb6ec 100755 --- a/src/gam.py +++ b/src/gam.py @@ -3524,7 +3524,7 @@ def doUpdateDriveFile(users): print(f'Successfully copied {fileId} to {result["id"]}') def createDriveFile(users): - csv_output = to_drive = False + csv_output = return_id_only = to_drive = False csv_rows = [] csv_titles = ['User', 'title', 'id'] media_body = None @@ -3541,6 +3541,9 @@ def createDriveFile(users): elif myarg == 'todrive': to_drive = True i += 1 + elif myarg == 'returnidonly': + return_id_only = True + i += 1 else: i = getDriveFileAttribute(i, body, parameters, myarg, False) for user in users: @@ -3559,10 +3562,12 @@ def createDriveFile(users): ocrLanguage=parameters[DFA_OCRLANGUAGE], media_body=media_body, body=body, fields='id,title,mimeType', supportsAllDrives=True) - titleInfo = f'{result["title"]}({result["id"]})' - if csv_output: + if return_id_only: + sys.stdout.write(f"{result['id']}\n") + elif csv_output: csv_rows.append({'User': user, 'title': result['title'], 'id': result['id']}) else: + titleInfo = f'{result["title"]}({result["id"]})' if parameters[DFA_LOCALFILENAME]: print(f'Successfully uploaded {parameters[DFA_LOCALFILENAME]} to Drive File {titleInfo}') else: