[minor] ignore list for dropbox
This commit is contained in:
parent
0939a5ac4c
commit
b092339c3a
@ -16,6 +16,8 @@ import frappe
|
|||||||
from frappe.utils import get_request_site_address, cstr
|
from frappe.utils import get_request_site_address, cstr
|
||||||
from frappe import _
|
from frappe import _
|
||||||
|
|
||||||
|
ignore_list = [".DS_Store"]
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_dropbox_authorize_url():
|
def get_dropbox_authorize_url():
|
||||||
sess = get_dropbox_session()
|
sess = get_dropbox_session()
|
||||||
@ -35,12 +37,12 @@ def get_dropbox_authorize_url():
|
|||||||
def dropbox_callback(oauth_token=None, not_approved=False):
|
def dropbox_callback(oauth_token=None, not_approved=False):
|
||||||
from dropbox import client
|
from dropbox import client
|
||||||
if not not_approved:
|
if not not_approved:
|
||||||
if frappe.db.get_value("Backup Manager", None, "dropbox_access_key")==oauth_token:
|
if frappe.db.get_value("Backup Manager", None, "dropbox_access_key")==oauth_token:
|
||||||
allowed = 1
|
allowed = 1
|
||||||
message = "Dropbox access allowed."
|
message = "Dropbox access allowed."
|
||||||
|
|
||||||
sess = get_dropbox_session()
|
sess = get_dropbox_session()
|
||||||
sess.set_request_token(frappe.db.get_value("Backup Manager", None, "dropbox_access_key"),
|
sess.set_request_token(frappe.db.get_value("Backup Manager", None, "dropbox_access_key"),
|
||||||
frappe.db.get_value("Backup Manager", None, "dropbox_access_secret"))
|
frappe.db.get_value("Backup Manager", None, "dropbox_access_secret"))
|
||||||
access_token = sess.obtain_access_token()
|
access_token = sess.obtain_access_token()
|
||||||
frappe.db.set_value("Backup Manager", "Backup Manager", "dropbox_access_key", access_token.key)
|
frappe.db.set_value("Backup Manager", "Backup Manager", "dropbox_access_key", access_token.key)
|
||||||
@ -61,10 +63,10 @@ def dropbox_callback(oauth_token=None, not_approved=False):
|
|||||||
|
|
||||||
frappe.local.message_title = "Dropbox Approval"
|
frappe.local.message_title = "Dropbox Approval"
|
||||||
frappe.local.message = "<h3>%s</h3><p>Please close this window.</p>" % message
|
frappe.local.message = "<h3>%s</h3><p>Please close this window.</p>" % message
|
||||||
|
|
||||||
if allowed:
|
if allowed:
|
||||||
frappe.local.message_success = True
|
frappe.local.message_success = True
|
||||||
|
|
||||||
frappe.db.commit()
|
frappe.db.commit()
|
||||||
frappe.response['type'] = 'page'
|
frappe.response['type'] = 'page'
|
||||||
frappe.response['page_name'] = 'message.html'
|
frappe.response['page_name'] = 'message.html'
|
||||||
@ -80,7 +82,7 @@ def backup_to_dropbox():
|
|||||||
|
|
||||||
sess.set_token(frappe.db.get_value("Backup Manager", None, "dropbox_access_key"),
|
sess.set_token(frappe.db.get_value("Backup Manager", None, "dropbox_access_key"),
|
||||||
frappe.db.get_value("Backup Manager", None, "dropbox_access_secret"))
|
frappe.db.get_value("Backup Manager", None, "dropbox_access_secret"))
|
||||||
|
|
||||||
dropbox_client = client.DropboxClient(sess)
|
dropbox_client = client.DropboxClient(sess)
|
||||||
|
|
||||||
# upload database
|
# upload database
|
||||||
@ -90,7 +92,7 @@ def backup_to_dropbox():
|
|||||||
|
|
||||||
frappe.db.close()
|
frappe.db.close()
|
||||||
response = dropbox_client.metadata("/files")
|
response = dropbox_client.metadata("/files")
|
||||||
|
|
||||||
# upload files to files folder
|
# upload files to files folder
|
||||||
did_not_upload = []
|
did_not_upload = []
|
||||||
error_log = []
|
error_log = []
|
||||||
@ -98,6 +100,9 @@ def backup_to_dropbox():
|
|||||||
for filename in os.listdir(path):
|
for filename in os.listdir(path):
|
||||||
filename = cstr(filename)
|
filename = cstr(filename)
|
||||||
|
|
||||||
|
if filename in ignore_list:
|
||||||
|
continue
|
||||||
|
|
||||||
found = False
|
found = False
|
||||||
filepath = os.path.join(path, filename)
|
filepath = os.path.join(path, filename)
|
||||||
for file_metadata in response["contents"]:
|
for file_metadata in response["contents"]:
|
||||||
@ -110,7 +115,7 @@ def backup_to_dropbox():
|
|||||||
except Exception:
|
except Exception:
|
||||||
did_not_upload.append(filename)
|
did_not_upload.append(filename)
|
||||||
error_log.append(frappe.get_traceback())
|
error_log.append(frappe.get_traceback())
|
||||||
|
|
||||||
frappe.connect()
|
frappe.connect()
|
||||||
return did_not_upload, list(set(error_log))
|
return did_not_upload, list(set(error_log))
|
||||||
|
|
||||||
@ -119,7 +124,7 @@ def get_dropbox_session():
|
|||||||
from dropbox import session
|
from dropbox import session
|
||||||
except:
|
except:
|
||||||
frappe.msgprint(_("Please install dropbox python module"), raise_exception=1)
|
frappe.msgprint(_("Please install dropbox python module"), raise_exception=1)
|
||||||
|
|
||||||
if not (frappe.conf.dropbox_access_key or frappe.conf.dropbox_secret_key):
|
if not (frappe.conf.dropbox_access_key or frappe.conf.dropbox_secret_key):
|
||||||
frappe.throw(_("Please set Dropbox access keys in your site config"))
|
frappe.throw(_("Please set Dropbox access keys in your site config"))
|
||||||
|
|
||||||
@ -129,11 +134,11 @@ def get_dropbox_session():
|
|||||||
def upload_file_to_dropbox(filename, folder, dropbox_client):
|
def upload_file_to_dropbox(filename, folder, dropbox_client):
|
||||||
from dropbox import rest
|
from dropbox import rest
|
||||||
size = os.stat(filename).st_size
|
size = os.stat(filename).st_size
|
||||||
|
|
||||||
with open(filename, 'r') as f:
|
with open(filename, 'r') as f:
|
||||||
# if max packet size reached, use chunked uploader
|
# if max packet size reached, use chunked uploader
|
||||||
max_packet_size = 4194304
|
max_packet_size = 4194304
|
||||||
|
|
||||||
if size > max_packet_size:
|
if size > max_packet_size:
|
||||||
uploader = dropbox_client.get_chunked_uploader(f, size)
|
uploader = dropbox_client.get_chunked_uploader(f, size)
|
||||||
while uploader.offset < size:
|
while uploader.offset < size:
|
||||||
@ -146,4 +151,4 @@ def upload_file_to_dropbox(filename, folder, dropbox_client):
|
|||||||
dropbox_client.put_file(folder + "/" + os.path.basename(filename), f, overwrite=True)
|
dropbox_client.put_file(folder + "/" + os.path.basename(filename), f, overwrite=True)
|
||||||
|
|
||||||
if __name__=="__main__":
|
if __name__=="__main__":
|
||||||
backup_to_dropbox()
|
backup_to_dropbox()
|
||||||
|
Loading…
Reference in New Issue
Block a user