mirror of
https://github.com/GAM-team/GAM.git
synced 2025-07-09 14:13:35 +00:00
Add update drive file changes from master pull 212
This commit is contained in:
21
src/gam.py
21
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']))
|
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):
|
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'
|
operation = u'update'
|
||||||
i = 5
|
i = 5
|
||||||
body = {}
|
body = {}
|
||||||
@ -3582,6 +3582,9 @@ def doUpdateDriveFile(users):
|
|||||||
elif sys.argv[i].lower() == u'id':
|
elif sys.argv[i].lower() == u'id':
|
||||||
fileIds = [sys.argv[i+1],]
|
fileIds = [sys.argv[i+1],]
|
||||||
i += 2
|
i += 2
|
||||||
|
elif sys.argv[i].lower() == u'query':
|
||||||
|
query = sys.argv[i+1]
|
||||||
|
i += 2
|
||||||
elif sys.argv[i].lower() == u'drivefilename':
|
elif sys.argv[i].lower() == u'drivefilename':
|
||||||
drivefilename = sys.argv[i+1]
|
drivefilename = sys.argv[i+1]
|
||||||
i += 2
|
i += 2
|
||||||
@ -3597,8 +3600,8 @@ def doUpdateDriveFile(users):
|
|||||||
elif sys.argv[i].lower() in [u'ocrlanguage',]:
|
elif sys.argv[i].lower() in [u'ocrlanguage',]:
|
||||||
ocrLanguage = sys.argv[i+1]
|
ocrLanguage = sys.argv[i+1]
|
||||||
i += 2
|
i += 2
|
||||||
elif sys.argv[i].lower() in [u'restrict', 'restricted']:
|
elif sys.argv[i].lower() in [u'restrict', u'restricted']:
|
||||||
if 'labels' not in body:
|
if u'labels' not in body:
|
||||||
body[u'labels'] = dict()
|
body[u'labels'] = dict()
|
||||||
if sys.argv[i+1].lower() in true_values:
|
if sys.argv[i+1].lower() in true_values:
|
||||||
body[u'labels'][u'restricted'] = True
|
body[u'labels'][u'restricted'] = True
|
||||||
@ -3685,11 +3688,11 @@ def doUpdateDriveFile(users):
|
|||||||
else:
|
else:
|
||||||
print u'ERROR: %s is not a valid argument for "gam <users> update drivefile"' % sys.argv[i]
|
print u'ERROR: %s is not a valid argument for "gam <users> update drivefile"' % sys.argv[i]
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
if not fileIds and not drivefilename:
|
if not fileIds and not drivefilename and not query:
|
||||||
print u'ERROR: you need to specify either id or query in order to determine the file(s) to update'
|
print u'ERROR: you need to specify either id, query or drivefilename in order to determine the file(s) to update'
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
elif fileIds and drivefilename:
|
elif (fileIds and drivefilename) or (fileIds and query) or (drivefilename and query):
|
||||||
print u'ERROR: you cannot specify both an id and a query.'
|
print u'ERROR: you cannot specify multiple file identifiers. Choose one of id, drivefilename, query.'
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
for user in users:
|
for user in users:
|
||||||
drive = buildGAPIServiceObject(u'drive', user)
|
drive = buildGAPIServiceObject(u'drive', user)
|
||||||
@ -3699,7 +3702,9 @@ def doUpdateDriveFile(users):
|
|||||||
body[u'parents'] = list()
|
body[u'parents'] = list()
|
||||||
for a_parent in more_parents:
|
for a_parent in more_parents:
|
||||||
body[u'parents'].append({u'id': a_parent})
|
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)
|
fileIds = doDriveSearch(drive, query=u'"me" in owners and title = "%s"' % drivefilename)
|
||||||
if local_filepath:
|
if local_filepath:
|
||||||
media_body = googleapiclient.http.MediaFileUpload(local_filepath, mimetype=mimetype, resumable=True)
|
media_body = googleapiclient.http.MediaFileUpload(local_filepath, mimetype=mimetype, resumable=True)
|
||||||
|
Reference in New Issue
Block a user