From 3ada129e7f17c745f1856947d49c92c4fd1e9a57 Mon Sep 17 00:00:00 2001 From: Ross Scroggs Date: Tue, 19 Apr 2016 12:30:42 -0700 Subject: [PATCH] Add update drive file changes from master pull 212 --- src/gam.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/gam.py b/src/gam.py index 2fa2a844..5b8266a5 100755 --- a/src/gam.py +++ b/src/gam.py @@ -3562,7 +3562,7 @@ def deleteEmptyDriveFolders(users): print convertUTF8(u' not deleting folder %s because it contains at least 1 item (%s)' % (folder[u'title'], children[u'items'][0][u'id'])) def doUpdateDriveFile(users): - convert = ocr = ocrLanguage = parent_query = local_filepath = media_body = fileIds = drivefilename = None + convert = ocr = ocrLanguage = parent_query = local_filepath = media_body = fileIds = query = drivefilename = None operation = u'update' i = 5 body = {} @@ -3582,6 +3582,9 @@ def doUpdateDriveFile(users): elif sys.argv[i].lower() == u'id': fileIds = [sys.argv[i+1],] i += 2 + elif sys.argv[i].lower() == u'query': + query = sys.argv[i+1] + i += 2 elif sys.argv[i].lower() == u'drivefilename': drivefilename = sys.argv[i+1] i += 2 @@ -3597,8 +3600,8 @@ def doUpdateDriveFile(users): elif sys.argv[i].lower() in [u'ocrlanguage',]: ocrLanguage = sys.argv[i+1] i += 2 - elif sys.argv[i].lower() in [u'restrict', 'restricted']: - if 'labels' not in body: + elif sys.argv[i].lower() in [u'restrict', u'restricted']: + if u'labels' not in body: body[u'labels'] = dict() if sys.argv[i+1].lower() in true_values: body[u'labels'][u'restricted'] = True @@ -3685,11 +3688,11 @@ def doUpdateDriveFile(users): else: print u'ERROR: %s is not a valid argument for "gam update drivefile"' % sys.argv[i] sys.exit(2) - if not fileIds and not drivefilename: - print u'ERROR: you need to specify either id or query in order to determine the file(s) to update' + if not fileIds and not drivefilename and not query: + print u'ERROR: you need to specify either id, query or drivefilename in order to determine the file(s) to update' sys.exit(2) - elif fileIds and drivefilename: - print u'ERROR: you cannot specify both an id and a query.' + elif (fileIds and drivefilename) or (fileIds and query) or (drivefilename and query): + print u'ERROR: you cannot specify multiple file identifiers. Choose one of id, drivefilename, query.' sys.exit(2) for user in users: drive = buildGAPIServiceObject(u'drive', user) @@ -3699,7 +3702,9 @@ def doUpdateDriveFile(users): body[u'parents'] = list() for a_parent in more_parents: body[u'parents'].append({u'id': a_parent}) - if drivefilename: + if query: + fileIds = doDriveSearch(drive, query=query) + elif drivefilename: fileIds = doDriveSearch(drive, query=u'"me" in owners and title = "%s"' % drivefilename) if local_filepath: media_body = googleapiclient.http.MediaFileUpload(local_filepath, mimetype=mimetype, resumable=True)