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 conf import dropbox_access_key, dropbox_secret_key
|
||||
from webnotes.utils.backups import new_backup
|
||||
found = False
|
||||
if not webnotes.conn:
|
||||
webnotes.connect()
|
||||
|
||||
@ -84,15 +83,15 @@ def backup_to_dropbox():
|
||||
response = dropbox_client.metadata("/files")
|
||||
# upload files to files folder
|
||||
path = os.path.join(get_base_path(), "public", "files")
|
||||
for files in os.listdir(path):
|
||||
filename = path + "/" + files
|
||||
for filename in os.listdir(path):
|
||||
found = False
|
||||
filepath = os.path.join(path, filename)
|
||||
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"]):
|
||||
found=True
|
||||
if os.path.basename(filepath) == os.path.basename(file_metadata["path"]) and os.stat(filepath).st_size == int(file_metadata["bytes"]):
|
||||
found = True
|
||||
break
|
||||
|
||||
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():
|
||||
from dropbox import session
|
||||
@ -112,7 +111,7 @@ def upload_file_to_dropbox(filename, folder, dropbox_client):
|
||||
while uploader.offset < size:
|
||||
try:
|
||||
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:
|
||||
pass
|
||||
else:
|
||||
|
@ -51,8 +51,6 @@ def upload_files(name, mimetype, service, folder_id):
|
||||
|
||||
def backup_to_gdrive():
|
||||
from webnotes.utils.backups import new_backup
|
||||
found_database = False
|
||||
found_files = False
|
||||
if not webnotes.conn:
|
||||
webnotes.connect()
|
||||
flow = get_gdrive_flow()
|
||||
@ -73,10 +71,11 @@ def backup_to_gdrive():
|
||||
|
||||
# upload files to files folder
|
||||
path = os.path.join(get_base_path(), "public", "files")
|
||||
for files in os.listdir(path):
|
||||
filename = path + "/" + files
|
||||
ext = filename.split('.')[-1]
|
||||
size = os.path.getsize(filename)
|
||||
for filename in os.listdir(path):
|
||||
found = False
|
||||
filepath = os.path.join(path, filename)
|
||||
ext = filepath.split('.')[-1]
|
||||
size = os.path.getsize(filepath)
|
||||
if ext == 'gz' or ext == 'gzip':
|
||||
mimetype = 'application/x-gzip'
|
||||
else:
|
||||
@ -88,11 +87,11 @@ def backup_to_gdrive():
|
||||
**param).execute()
|
||||
for child in children.get('items', []):
|
||||
file = drive_service.files().get(fileId=child['id']).execute()
|
||||
if files == file['title'] and size == int(file['fileSize']):
|
||||
found_files = True
|
||||
if filename == file['title'] and size == int(file['fileSize']):
|
||||
found = True
|
||||
break
|
||||
if not found_files:
|
||||
upload_files(filename, mimetype, drive_service, webnotes.conn.get_value("Backup Manager", None, "files_folder_id"))
|
||||
if not found:
|
||||
upload_files(filepath, mimetype, drive_service, webnotes.conn.get_value("Backup Manager", None, "files_folder_id"))
|
||||
|
||||
def get_gdrive_flow():
|
||||
from oauth2client.client import OAuth2WebServerFlow
|
||||
@ -106,10 +105,9 @@ def get_gdrive_flow():
|
||||
# + "?cmd=setup.doctype.backup_manager.backup_googledrive.googledrive_callback"
|
||||
|
||||
# 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,
|
||||
"https://www.googleapis.com/auth/drive", redirect_uri)
|
||||
"https://www.googleapis.com/auth/drive", conf.gdrive_redirect_url)
|
||||
return flow
|
||||
|
||||
@webnotes.whitelist()
|
||||
|
Loading…
Reference in New Issue
Block a user