dropbox and googledrive problems fixed
This commit is contained in:
parent
3433f11abe
commit
3abf67cf5e
@ -64,7 +64,6 @@ def backup_to_dropbox():
|
|||||||
from dropbox import client, session, rest
|
from dropbox import client, session, rest
|
||||||
from conf import dropbox_access_key, dropbox_secret_key
|
from conf import dropbox_access_key, dropbox_secret_key
|
||||||
from webnotes.utils.backups import new_backup
|
from webnotes.utils.backups import new_backup
|
||||||
found = False
|
|
||||||
if not webnotes.conn:
|
if not webnotes.conn:
|
||||||
webnotes.connect()
|
webnotes.connect()
|
||||||
|
|
||||||
@ -84,15 +83,15 @@ def backup_to_dropbox():
|
|||||||
response = dropbox_client.metadata("/files")
|
response = dropbox_client.metadata("/files")
|
||||||
# upload files to files folder
|
# upload files to files folder
|
||||||
path = os.path.join(get_base_path(), "public", "files")
|
path = os.path.join(get_base_path(), "public", "files")
|
||||||
for files in os.listdir(path):
|
for filename in os.listdir(path):
|
||||||
filename = path + "/" + files
|
found = False
|
||||||
|
filepath = os.path.join(path, filename)
|
||||||
for file_metadata in response["contents"]:
|
for file_metadata in response["contents"]:
|
||||||
if os.path.basename(filename)==os.path.basename(file_metadata["path"]) and os.stat(filename).st_size==int(file_metadata["bytes"]):
|
if os.path.basename(filepath) == os.path.basename(file_metadata["path"]) and os.stat(filepath).st_size == int(file_metadata["bytes"]):
|
||||||
found = True
|
found = True
|
||||||
break
|
break
|
||||||
|
|
||||||
if not found:
|
if not found:
|
||||||
upload_file_to_dropbox(os.path.join(get_base_path(),"public", "files", filename), "files", dropbox_client)
|
upload_file_to_dropbox(filepath, "files", dropbox_client)
|
||||||
|
|
||||||
def get_dropbox_session():
|
def get_dropbox_session():
|
||||||
from dropbox import session
|
from dropbox import session
|
||||||
@ -112,7 +111,7 @@ def upload_file_to_dropbox(filename, folder, dropbox_client):
|
|||||||
while uploader.offset < size:
|
while uploader.offset < size:
|
||||||
try:
|
try:
|
||||||
uploader.upload_chunked()
|
uploader.upload_chunked()
|
||||||
uploader.finish(folder + '/' + os.path.basename(filename), overwrite='True')
|
uploader.finish(os.path.join(folder, os.path.basename(filename)), overwrite='True')
|
||||||
except rest.ErrorResponse, e:
|
except rest.ErrorResponse, e:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
|
@ -51,8 +51,6 @@ def upload_files(name, mimetype, service, folder_id):
|
|||||||
|
|
||||||
def backup_to_gdrive():
|
def backup_to_gdrive():
|
||||||
from webnotes.utils.backups import new_backup
|
from webnotes.utils.backups import new_backup
|
||||||
found_database = False
|
|
||||||
found_files = False
|
|
||||||
if not webnotes.conn:
|
if not webnotes.conn:
|
||||||
webnotes.connect()
|
webnotes.connect()
|
||||||
flow = get_gdrive_flow()
|
flow = get_gdrive_flow()
|
||||||
@ -73,10 +71,11 @@ def backup_to_gdrive():
|
|||||||
|
|
||||||
# upload files to files folder
|
# upload files to files folder
|
||||||
path = os.path.join(get_base_path(), "public", "files")
|
path = os.path.join(get_base_path(), "public", "files")
|
||||||
for files in os.listdir(path):
|
for filename in os.listdir(path):
|
||||||
filename = path + "/" + files
|
found = False
|
||||||
ext = filename.split('.')[-1]
|
filepath = os.path.join(path, filename)
|
||||||
size = os.path.getsize(filename)
|
ext = filepath.split('.')[-1]
|
||||||
|
size = os.path.getsize(filepath)
|
||||||
if ext == 'gz' or ext == 'gzip':
|
if ext == 'gz' or ext == 'gzip':
|
||||||
mimetype = 'application/x-gzip'
|
mimetype = 'application/x-gzip'
|
||||||
else:
|
else:
|
||||||
@ -88,11 +87,11 @@ def backup_to_gdrive():
|
|||||||
**param).execute()
|
**param).execute()
|
||||||
for child in children.get('items', []):
|
for child in children.get('items', []):
|
||||||
file = drive_service.files().get(fileId=child['id']).execute()
|
file = drive_service.files().get(fileId=child['id']).execute()
|
||||||
if files == file['title'] and size == int(file['fileSize']):
|
if filename == file['title'] and size == int(file['fileSize']):
|
||||||
found_files = True
|
found = True
|
||||||
break
|
break
|
||||||
if not found_files:
|
if not found:
|
||||||
upload_files(filename, mimetype, drive_service, webnotes.conn.get_value("Backup Manager", None, "files_folder_id"))
|
upload_files(filepath, mimetype, drive_service, webnotes.conn.get_value("Backup Manager", None, "files_folder_id"))
|
||||||
|
|
||||||
def get_gdrive_flow():
|
def get_gdrive_flow():
|
||||||
from oauth2client.client import OAuth2WebServerFlow
|
from oauth2client.client import OAuth2WebServerFlow
|
||||||
@ -106,10 +105,9 @@ def get_gdrive_flow():
|
|||||||
# + "?cmd=setup.doctype.backup_manager.backup_googledrive.googledrive_callback"
|
# + "?cmd=setup.doctype.backup_manager.backup_googledrive.googledrive_callback"
|
||||||
|
|
||||||
# for installed apps since google does not support subdomains
|
# for installed apps since google does not support subdomains
|
||||||
redirect_uri = "urn:ietf:wg:oauth:2.0:oob"
|
|
||||||
|
|
||||||
flow = OAuth2WebServerFlow(conf.gdrive_client_id, conf.gdrive_client_secret,
|
flow = OAuth2WebServerFlow(conf.gdrive_client_id, conf.gdrive_client_secret,
|
||||||
"https://www.googleapis.com/auth/drive", redirect_uri)
|
"https://www.googleapis.com/auth/drive", conf.gdrive_redirect_url)
|
||||||
return flow
|
return flow
|
||||||
|
|
||||||
@webnotes.whitelist()
|
@webnotes.whitelist()
|
||||||
|
Loading…
Reference in New Issue
Block a user