Commit all these files.
This commit is contained in:
parent
77a6ddaf03
commit
08bd677664
@ -1,6 +1,9 @@
|
||||
import os
|
||||
import webnotes
|
||||
from webnotes.utils import get_request_site_address
|
||||
from webnotes.utils import get_request_site_address, get_base_path
|
||||
from webnotes import _
|
||||
|
||||
filename = ''
|
||||
|
||||
@webnotes.whitelist()
|
||||
def get_dropbox_authorize_url():
|
||||
@ -10,7 +13,6 @@ def get_dropbox_authorize_url():
|
||||
+ "?cmd=setup.doctype.backup_manager.backup_dropbox.dropbox_callback"
|
||||
|
||||
url = sess.build_authorize_url(request_token, return_address)
|
||||
|
||||
return {
|
||||
"url": url,
|
||||
"key": request_token.key,
|
||||
@ -49,7 +51,7 @@ def dropbox_callback(oauth_token=None, not_approved=False):
|
||||
webnotes.response['page_name'] = 'message.html'
|
||||
|
||||
def backup_to_dropbox():
|
||||
from dropbox import client, session
|
||||
from dropbox import client, session, rest
|
||||
from conf import dropbox_access_key, dropbox_secret_key
|
||||
from webnotes.utils.backups import new_backup
|
||||
if not webnotes.conn:
|
||||
@ -67,22 +69,19 @@ def backup_to_dropbox():
|
||||
backup = new_backup()
|
||||
filename = backup.backup_path_db
|
||||
upload_file_to_dropbox(filename, "database", dropbox_client)
|
||||
|
||||
# upload files
|
||||
response = dropbox_client.metadata("files")
|
||||
response = dropbox_client.metadata("/database")
|
||||
|
||||
#add missing files
|
||||
# for filename in os.listdir(filename):
|
||||
# found = False
|
||||
# for file_metadata in response["contents"]:
|
||||
# if filename==os.path.basename(file_metadata["path"]):
|
||||
# if os.stat(filename).st_size==file_metadata["bytes"]:
|
||||
# found=True
|
||||
|
||||
# add missing files
|
||||
for filename in os.listdir(os.path.join("public", "files")):
|
||||
found = False
|
||||
for file_metadata in response["contents"]:
|
||||
if filename==os.path.basename(file_metadata["path"]):
|
||||
if os.stat(os.path.join("public", "files", filename)).st_size==file_metadata["bytes"]:
|
||||
found=True
|
||||
|
||||
if not found:
|
||||
upload_file_to_dropbox(os.path.join("public", "files", filename), "files", dropbox_client)
|
||||
|
||||
# if not found:
|
||||
# upload_file_to_dropbox(filename, "database", dropbox_client)
|
||||
|
||||
def get_dropbox_session():
|
||||
from dropbox import session
|
||||
@ -91,25 +90,25 @@ def get_dropbox_session():
|
||||
except ImportError, e:
|
||||
webnotes.msgprint(_("Please set Dropbox access keys in") + " conf.py",
|
||||
raise_exception=True)
|
||||
|
||||
sess = session.DropboxSession(dropbox_access_key, dropbox_secret_key, "app_folder")
|
||||
return sess
|
||||
|
||||
def upload_file_to_dropbox(filename, folder, dropbox_client):
|
||||
if __name__=="__main__":
|
||||
print "Uploading " + filename
|
||||
size = os.stat(filename).st_size
|
||||
f = open(filename,'r')
|
||||
path = os.path.join(get_base_path(),"public", "backups")
|
||||
for files in os.listdir(path):
|
||||
file_name = path + "/" + files
|
||||
size = os.stat(file_name).st_size
|
||||
f = open(filename,'r')
|
||||
|
||||
if size > 4194304:
|
||||
uploader = dropbox_client.get_chunked_uploader(f, size)
|
||||
while uploader.offset < size:
|
||||
try:
|
||||
uploader.upload_chunked()
|
||||
except rest.ErrorResponse, e:
|
||||
pass
|
||||
else:
|
||||
response = dropbox_client.put_file(folder + "/" + os.path.basename(filename), f, overwrite=True)
|
||||
if size > 4194304:
|
||||
uploader = dropbox_client.get_chunked_uploader(f, size)
|
||||
while uploader.offset < size:
|
||||
try:
|
||||
uploader.upload_chunked()
|
||||
except rest.ErrorResponse, e:
|
||||
pass
|
||||
else:
|
||||
response = dropbox_client.put_file(folder + "/" + os.path.basename(file_name), f, overwrite=True)
|
||||
|
||||
if __name__=="__main__":
|
||||
backup_to_dropbox()
|
@ -3,6 +3,7 @@
|
||||
from __future__ import unicode_literals
|
||||
import webnotes
|
||||
from webnotes import _
|
||||
from backup_dropbox import dropbox_callback, get_dropbox_session, get_dropbox_authorize_url
|
||||
|
||||
class DocType:
|
||||
def __init__(self, d, dl):
|
||||
@ -26,7 +27,6 @@ def take_backups():
|
||||
send_email(True, "Dropbox")
|
||||
except Exception, e:
|
||||
send_email(False, "Dropbox", e)
|
||||
|
||||
def send_email(success, service_name, error_status=None):
|
||||
if success:
|
||||
subject = "Backup Upload Successful"
|
||||
@ -45,4 +45,6 @@ def send_email(success, service_name, error_status=None):
|
||||
# email system managers
|
||||
from webnotes.utils.email_lib import sendmail
|
||||
sendmail(webnotes.conn.get_value("Backup Manager", None, "send_notifications_to").split(","),
|
||||
subject=subject, msg=message)
|
||||
subject=subject, msg=message)
|
||||
|
||||
get_dropbox_authorize_url()
|
Loading…
Reference in New Issue
Block a user