Add drivefilename <DriveFileName> to gam get drivefile

This commit is contained in:
Ross Scroggs
2016-08-01 08:19:42 -07:00
parent 13d2f9dd96
commit 368a6d1217
3 changed files with 24 additions and 16 deletions

View File

@@ -695,7 +695,7 @@ gam <UserTypeEntity> show filetree
gam <UserTypeEntity> add drivefile [drivefilename <DriveFileName>] <DriveFileAddAttributes>* gam <UserTypeEntity> add drivefile [drivefilename <DriveFileName>] <DriveFileAddAttributes>*
gam <UserTypeEntity> update drivefile (id <DriveFileID)|(drivefilename <DriveFileName>)|(query <QueryDriveFile) [copy] [newfilename <DriveFileName>] <DriveFileUpdateAttributes>* gam <UserTypeEntity> update drivefile (id <DriveFileID)|(drivefilename <DriveFileName>)|(query <QueryDriveFile) [copy] [newfilename <DriveFileName>] <DriveFileUpdateAttributes>*
gam <UserTypeEntity> get drivefile (id <DriveFileID>)|(query <QueryDriveFile>) [format <FileFormatList>] [targetfolder <FilePath>] [revision <Number>] gam <UserTypeEntity> get drivefile (id <DriveFileID>)|(drivefilename <DriveFileName>)|(query <QueryDriveFile>) [format <FileFormatList>] [targetfolder <FilePath>] [revision <Number>]
gam <UserTypeEntity> delete|del drivefile <DriveFileID>|<DriveFileURL>|(query:<QueryDriveFile>) [purge|untrash] gam <UserTypeEntity> delete|del drivefile <DriveFileID>|<DriveFileURL>|(query:<QueryDriveFile>) [purge|untrash]
gam <UserTypeEntity> transfer drive <UserItem> [keepuser] gam <UserTypeEntity> transfer drive <UserItem> [keepuser]
gam <UserTypeEntity> delete|del emptydrivefolders gam <UserTypeEntity> delete|del emptydrivefolders

View File

@@ -4267,7 +4267,8 @@ DOCUMENT_FORMATS_MAP = {
def downloadDriveFile(users): def downloadDriveFile(users):
i = 5 i = 5
query = fileIds = revisionId = None fileIdSelection = {u'fileIds': None, u'query': None}
revisionId = None
exportFormatName = u'openoffice' exportFormatName = u'openoffice'
exportFormats = DOCUMENT_FORMATS_MAP[exportFormatName] exportFormats = DOCUMENT_FORMATS_MAP[exportFormatName]
targetFolder = GC_Values[GC_DRIVE_DIR] targetFolder = GC_Values[GC_DRIVE_DIR]
@@ -4275,10 +4276,13 @@ def downloadDriveFile(users):
while i < len(sys.argv): while i < len(sys.argv):
myarg = sys.argv[i].lower().replace(u'_', u'') myarg = sys.argv[i].lower().replace(u'_', u'')
if myarg == u'id': if myarg == u'id':
fileIds = [sys.argv[i+1],] fileIdSelection[u'fileIds'] = [sys.argv[i+1],]
i += 2 i += 2
elif myarg == u'query': elif myarg == u'query':
query = sys.argv[i+1] fileIdSelection[u'query'] = sys.argv[i+1]
i += 2
elif myarg == u'drivefilename':
fileIdSelection[u'query'] = u"'me' in owners and title = '{0}'".format(sys.argv[i+1])
i += 2 i += 2
elif myarg == u'revision': elif myarg == u'revision':
revisionId = sys.argv[i+1] revisionId = sys.argv[i+1]
@@ -4301,27 +4305,30 @@ 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)
if not query and not fileIds: if not fileIdSelection[u'query'] and not fileIdSelection[u'fileIds']:
print u'ERROR: need to specify a file ID with id parameter or a search query with the query parameter.' print u'ERROR: you need to specify either id, query or drivefilename in order to determine the file(s) to download'
sys.exit(2) sys.exit(2)
if query and fileIds: if fileIdSelection[u'query'] and fileIdSelection[u'fileIds']:
print u'ERROR: you cannot specify both the id and query parameters at the same time.' 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:
user, drive = buildDriveGAPIObject(user) user, drive = buildDriveGAPIObject(user)
if not drive: if not drive:
continue continue
if query: if fileIdSelection[u'query']:
fileIdSelection[u'fileIds'] = doDriveSearch(drive, query=fileIdSelection[u'query'])
fileIds = doDriveSearch(drive, query=query) fileIds = doDriveSearch(drive, query=query)
else: else:
if fileIds[0][:8].lower() == u'https://' or fileIds[0][:7].lower() == u'http://': fileId = fileIdSelection[u'fileIds'][0]
fileIds[0] = fileIds[0][fileIds[0].find(u'/d/')+3:] if fileId[:8].lower() == u'https://' or fileId[:7].lower() == u'http://':
if fileIds[0].find(u'/') != -1: fileId = fileId[fileId.find(u'/d/')+3:]
fileIds[0] = fileIds[0][:fileIds[0].find(u'/')] if fileId.find(u'/') != -1:
if not fileIds: fileId = fileId[:fileId.find(u'/')]
fileIdSelection[u'fileIds'][0] = fileId
if not fileIdSelection[u'fileIds']:
print u'No files to download for %s' % user print u'No files to download for %s' % user
i = 0 i = 0
for fileId in fileIds: for fileId in fileIdSelection[u'fileIds']:
extension = None extension = None
result = callGAPI(drive.files(), u'get', fileId=fileId, fields=u'fileSize,title,mimeType,downloadUrl,exportLinks') result = callGAPI(drive.files(), u'get', fileId=fileId, fields=u'fileSize,title,mimeType,downloadUrl,exportLinks')
if result[u'mimeType'] == MIMETYPE_GA_FOLDER: if result[u'mimeType'] == MIMETYPE_GA_FOLDER:

View File

@@ -177,9 +177,10 @@ order, they will have to be updated. If your scripts process the CSV files by co
2016/07/31 2016/07/31
Changed gam get drivefile to take a list of file formats rather than a single format. The first format in the list that is available will be used. Changed gam get drivefile to take a list of file formats rather than a single format. The first format in the list that is available will be used.
Added drivefilename argument to allow downloading file by name.
<FileFormat> ::= csv|html|txt|tsv|jpeg|jpg|png|svg|pdf|rtf|pptx|xlsx|docx|odt|ods|openoffice|ms|microsoft|micro$oft <FileFormat> ::= csv|html|txt|tsv|jpeg|jpg|png|svg|pdf|rtf|pptx|xlsx|docx|odt|ods|openoffice|ms|microsoft|micro$oft
<FileFormatList> ::= '<FileFormat>(,<FileFormat)*' <FileFormatList> ::= '<FileFormat>(,<FileFormat)*'
gam <UserTypeEntity> get drivefile (id <DriveFileID>)|(query <QueryDriveFile>) [format <FileFormatList>] [targetfolder <FilePath>] [revision <Number>] gam <UserTypeEntity> get drivefile (id <DriveFileID>)|(drivefilename <DriveFileName>)|(query <QueryDriveFile>) [format <FileFormatList>] [targetfolder <FilePath>] [revision <Number>]
GAM 3.65 GAM 3.65
-fix vacation issues (Ross) -fix vacation issues (Ross)