mirror of
https://github.com/GAM-team/GAM.git
synced 2025-07-09 06:03:35 +00:00
Add revision argument to gam get drivefile; add command gam show filerevisions
This commit is contained in:
92
src/gam.py
92
src/gam.py
@ -3876,24 +3876,28 @@ def createDriveFile(users):
|
|||||||
|
|
||||||
def downloadDriveFile(users):
|
def downloadDriveFile(users):
|
||||||
i = 5
|
i = 5
|
||||||
query = fileIds = None
|
query = fileIds = revision = None
|
||||||
gdownload_format = u'openoffice'
|
gdownload_format = u'openoffice'
|
||||||
target_folder = GC_Values[GC_DRIVE_DIR]
|
target_folder = GC_Values[GC_DRIVE_DIR]
|
||||||
safe_filename_chars = "-_.() %s%s" % (string.ascii_letters, string.digits)
|
safe_filename_chars = "-_.() %s%s" % (string.ascii_letters, string.digits)
|
||||||
while i < len(sys.argv):
|
while i < len(sys.argv):
|
||||||
if sys.argv[i].lower() == u'id':
|
myarg = sys.argv[i].lower().replace('_', '')
|
||||||
|
if myarg == u'id':
|
||||||
fileIds = [sys.argv[i+1],]
|
fileIds = [sys.argv[i+1],]
|
||||||
i += 2
|
i += 2
|
||||||
elif sys.argv[i].lower() == 'query':
|
elif myarg == u'query':
|
||||||
query = sys.argv[i+1]
|
query = sys.argv[i+1]
|
||||||
i += 2
|
i += 2
|
||||||
elif sys.argv[i].lower() == u'format':
|
elif myarg == u'revision':
|
||||||
|
revision = sys.argv[i+1]
|
||||||
|
i += 2
|
||||||
|
elif myarg == u'format':
|
||||||
gdownload_format = sys.argv[i+1].lower()
|
gdownload_format = sys.argv[i+1].lower()
|
||||||
if gdownload_format not in [u'openoffice', u'ms', u'microsoft', u'micro$oft', u'pdf']:
|
if gdownload_format not in [u'openoffice', u'ms', u'microsoft', u'micro$oft', u'pdf']:
|
||||||
print 'ERROR: format must be one of openoffice, microsoft or pdf. Got %s' % gdownload_format
|
print u'ERROR: format must be one of openoffice, microsoft or pdf. Got %s' % gdownload_format
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
i += 2
|
i += 2
|
||||||
elif sys.argv[i].lower().replace('_', '') == u'targetfolder':
|
elif myarg == u'targetfolder':
|
||||||
target_folder = sys.argv[i+1]
|
target_folder = sys.argv[i+1]
|
||||||
if not os.path.isdir(target_folder):
|
if not os.path.isdir(target_folder):
|
||||||
os.makedirs(target_folder)
|
os.makedirs(target_folder)
|
||||||
@ -3901,7 +3905,7 @@ def downloadDriveFile(users):
|
|||||||
else:
|
else:
|
||||||
print u'ERROR: %s is not a valid argument for "gam <users> get drivefile"' % sys.argv[i]
|
print u'ERROR: %s is not a valid argument for "gam <users> get drivefile"' % sys.argv[i]
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
export_extensions = {u'application/pdf': '.pdf',
|
export_extensions = {u'application/pdf': u'.pdf',
|
||||||
u'application/vnd.openxmlformats-officedocument.wordprocessingml.document': u'.docx',
|
u'application/vnd.openxmlformats-officedocument.wordprocessingml.document': u'.docx',
|
||||||
u'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': u'.xlsx',
|
u'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': u'.xlsx',
|
||||||
u'application/vnd.openxmlformats-officedocument.presentationml.presentation': u'.pptx',
|
u'application/vnd.openxmlformats-officedocument.presentationml.presentation': u'.pptx',
|
||||||
@ -3927,10 +3931,10 @@ def downloadDriveFile(users):
|
|||||||
if query:
|
if query:
|
||||||
fileIds = doDriveSearch(drive, query=query)
|
fileIds = doDriveSearch(drive, query=query)
|
||||||
else:
|
else:
|
||||||
if fileIds[0][:8].lower() == 'https://' or fileIds[0][:7].lower() == 'http://':
|
if fileIds[0][:8].lower() == u'https://' or fileIds[0][:7].lower() == u'http://':
|
||||||
fileIds[0] = fileIds[0][fileIds[0].find('/d/')+3:]
|
fileIds[0] = fileIds[0][fileIds[0].find(u'/d/')+3:]
|
||||||
if fileIds[0].find('/') != -1:
|
if fileIds[0].find(u'/') != -1:
|
||||||
fileIds[0] = fileIds[0][:fileIds[0].find('/')]
|
fileIds[0] = fileIds[0][:fileIds[0].find(u'/')]
|
||||||
if not fileIds:
|
if not fileIds:
|
||||||
print u'No files to download for %s' % user
|
print u'No files to download for %s' % user
|
||||||
i = 0
|
i = 0
|
||||||
@ -3965,13 +3969,13 @@ def downloadDriveFile(users):
|
|||||||
pass
|
pass
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
print convertUTF8(u'Skipping download of file {0}, Format {1} not available'.format(result[u'title'], ','.join(export_formats)))
|
print convertUTF8(u'Skipping download of file {0}, Format {1} not available'.format(result[u'title'], u','.join(export_formats)))
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
print convertUTF8(u'Skipping download of file {0}, Format not downloadable')
|
print convertUTF8(u'Skipping download of file {0}, Format not downloadable')
|
||||||
continue
|
continue
|
||||||
file_title = result[u'title']
|
file_title = result[u'title']
|
||||||
safe_file_title = ''.join(c for c in file_title if c in safe_filename_chars)
|
safe_file_title = u''.join(c for c in file_title if c in safe_filename_chars)
|
||||||
filename = os.path.join(target_folder, safe_file_title)
|
filename = os.path.join(target_folder, safe_file_title)
|
||||||
if extension and filename.lower()[:len(extension)] != extension:
|
if extension and filename.lower()[:len(extension)] != extension:
|
||||||
filename = u'%s%s' % (filename, extension)
|
filename = u'%s%s' % (filename, extension)
|
||||||
@ -3986,38 +3990,50 @@ def downloadDriveFile(users):
|
|||||||
break
|
break
|
||||||
filename = new_filename
|
filename = new_filename
|
||||||
print convertUTF8(my_line % filename)
|
print convertUTF8(my_line % filename)
|
||||||
|
if revision:
|
||||||
|
download_url = u'{0}&revision={1}'.format(download_url, revision)
|
||||||
_, content = drive._http.request(download_url)
|
_, content = drive._http.request(download_url)
|
||||||
writeFile(filename, content, continueOnError=True)
|
writeFile(filename, content, continueOnError=True)
|
||||||
|
|
||||||
|
def printDriveFileData(feed):
|
||||||
|
for setting in feed:
|
||||||
|
if setting in [u'kind', u'etag']:
|
||||||
|
continue
|
||||||
|
setting_type = str(type(feed[setting]))
|
||||||
|
if setting_type == u"<type 'list'>":
|
||||||
|
print u'%s:' % setting
|
||||||
|
for settin in feed[setting]:
|
||||||
|
if settin in [u'kind', u'etag']:
|
||||||
|
continue
|
||||||
|
settin_type = str(type(settin))
|
||||||
|
if settin_type == u"<type 'dict'>":
|
||||||
|
for setti in settin:
|
||||||
|
if setti in [u'kind', u'etag']:
|
||||||
|
continue
|
||||||
|
print convertUTF8(u' %s: %s' % (setti, settin[setti]))
|
||||||
|
print u''
|
||||||
|
elif setting_type == u"<type 'dict'>":
|
||||||
|
print u'%s:' % setting
|
||||||
|
for settin in feed[setting]:
|
||||||
|
if settin in [u'kind', u'etag']:
|
||||||
|
continue
|
||||||
|
print convertUTF8(u' %s: %s' % (settin, feed[setting][settin]))
|
||||||
|
else:
|
||||||
|
print convertUTF8(u'%s: %s' % (setting, feed[setting]))
|
||||||
|
|
||||||
def showDriveFileInfo(users):
|
def showDriveFileInfo(users):
|
||||||
for user in users:
|
for user in users:
|
||||||
fileId = sys.argv[5]
|
fileId = sys.argv[5]
|
||||||
drive = buildGAPIServiceObject(u'drive', user)
|
drive = buildGAPIServiceObject(u'drive', user)
|
||||||
feed = callGAPI(service=drive.files(), function=u'get', fileId=fileId)
|
feed = callGAPI(service=drive.files(), function=u'get', fileId=fileId)
|
||||||
for setting in feed:
|
printDriveFileData(feed)
|
||||||
if setting == u'kind':
|
|
||||||
continue
|
def showDriveFileRevisions(users):
|
||||||
setting_type = str(type(feed[setting]))
|
for user in users:
|
||||||
if setting_type == u"<type 'list'>":
|
fileId = sys.argv[5]
|
||||||
print u'%s:' % setting
|
drive = buildGAPIServiceObject(u'drive', user)
|
||||||
for settin in feed[setting]:
|
feed = callGAPI(service=drive.revisions(), function=u'list', fileId=fileId)
|
||||||
if settin == u'kind':
|
printDriveFileData(feed)
|
||||||
continue
|
|
||||||
settin_type = str(type(settin))
|
|
||||||
if settin_type == u"<type 'dict'>":
|
|
||||||
for setti in settin:
|
|
||||||
if setti == u'kind':
|
|
||||||
continue
|
|
||||||
print convertUTF8(u' %s: %s' % (setti, settin[setti]))
|
|
||||||
print u''
|
|
||||||
elif setting_type == u"<type 'dict'>":
|
|
||||||
print u'%s:' % setting
|
|
||||||
for settin in feed[setting]:
|
|
||||||
if settin == u'kind':
|
|
||||||
continue
|
|
||||||
print convertUTF8(u' %s: %s' % (settin, feed[setting][settin]))
|
|
||||||
else:
|
|
||||||
print convertUTF8(u'%s: %s' % (setting, feed[setting]))
|
|
||||||
|
|
||||||
def transferSecCals(users):
|
def transferSecCals(users):
|
||||||
target_user = sys.argv[5]
|
target_user = sys.argv[5]
|
||||||
@ -9527,6 +9543,8 @@ try:
|
|||||||
showDriveFileTree(users)
|
showDriveFileTree(users)
|
||||||
elif readWhat == u'fileinfo':
|
elif readWhat == u'fileinfo':
|
||||||
showDriveFileInfo(users)
|
showDriveFileInfo(users)
|
||||||
|
elif readWhat == u'filerevisions':
|
||||||
|
showDriveFileRevisions(users)
|
||||||
elif readWhat == u'sendas':
|
elif readWhat == u'sendas':
|
||||||
showSendAs(users)
|
showSendAs(users)
|
||||||
elif readWhat == u'gmailprofile':
|
elif readWhat == u'gmailprofile':
|
||||||
|
Reference in New Issue
Block a user