@@ -73,26 +73,27 @@ if not os.path.exists(dbpath):
migrate()
defgetDrive(gauth=None):
ifnotgauth:
gauth=GoogleAuth(settings_file='settings.yaml')
# Try to load saved client credentials
gauth.LoadCredentialsFile("gdrive_credentials")
ifgauth.access_token_expired:
# Refresh them if expired
gauth.Refresh()
else:
# Initialize the saved creds
gauth.Authorize()
# Save the current credentials to a file
returnGoogleDrive(gauth)
defgetEbooksFolder(drive=None):
defgetDrive(drive=None,gauth=None):
ifnotdrive:
drive=getDrive()
ifnotgauth:
gauth=GoogleAuth(settings_file='settings.yaml')
# Try to load saved client credentials
gauth.LoadCredentialsFile("gdrive_credentials")
ifgauth.access_token_expired:
# Refresh them if expired
gauth.Refresh()
else:
# Initialize the saved creds
gauth.Authorize()
# Save the current credentials to a file
returnGoogleDrive(gauth)
ifdrive.auth.access_token_expired:
drive.auth.Refresh()
returndrive
defgetEbooksFolder(drive=None):
drive=getDrive(drive)
ebooksFolder="title = '%s' and 'root' in parents and mimeType = 'application/vnd.google-apps.folder' and trashed = false"%config.config_google_drive_folder
folder="title = '%s' and '%s' in parents and mimeType = 'application/vnd.google-apps.folder' and trashed = false"%(folderName.replace("'","\\'"),parentId)
fileList=drive.ListFile({'q':folder}).GetList()
returnfileList[0]
defgetFile(pathId,fileName,drive=None):
ifnotdrive:
drive=getDrive()
ifdrive.auth.access_token_expired:
drive.auth.Refresh()
drive=getDrive(drive)
metaDataFile="'%s' in parents and trashed = false and title = '%s'"%(pathId,fileName.replace("'","\\'"))