Merge branch 'master' into edge
This commit is contained in:
commit
3e8c696de7
@ -7,12 +7,14 @@
|
|||||||
# dropbox_access_key
|
# dropbox_access_key
|
||||||
# dropbox_access_secret
|
# dropbox_access_secret
|
||||||
|
|
||||||
|
from __future__ import unicode_literals
|
||||||
import os
|
import os
|
||||||
import webnotes
|
import webnotes
|
||||||
from webnotes.utils import get_request_site_address, get_base_path
|
from webnotes.utils import get_request_site_address, get_base_path, cstr
|
||||||
from webnotes import _
|
from webnotes import _
|
||||||
|
|
||||||
|
from backup_manager import ignore_list
|
||||||
|
|
||||||
@webnotes.whitelist()
|
@webnotes.whitelist()
|
||||||
def get_dropbox_authorize_url():
|
def get_dropbox_authorize_url():
|
||||||
sess = get_dropbox_session()
|
sess = get_dropbox_session()
|
||||||
@ -86,8 +88,13 @@ def backup_to_dropbox():
|
|||||||
response = dropbox_client.metadata("/files")
|
response = dropbox_client.metadata("/files")
|
||||||
|
|
||||||
# upload files to files folder
|
# upload files to files folder
|
||||||
|
did_not_upload = []
|
||||||
|
error_log = []
|
||||||
path = os.path.join(get_base_path(), "public", "files")
|
path = os.path.join(get_base_path(), "public", "files")
|
||||||
for filename in os.listdir(path):
|
for filename in os.listdir(path):
|
||||||
|
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"]:
|
||||||
@ -95,7 +102,13 @@ def backup_to_dropbox():
|
|||||||
found = True
|
found = True
|
||||||
break
|
break
|
||||||
if not found:
|
if not found:
|
||||||
upload_file_to_dropbox(filepath, "/files", dropbox_client)
|
try:
|
||||||
|
upload_file_to_dropbox(filepath, "/files", dropbox_client)
|
||||||
|
except Exception, e:
|
||||||
|
did_not_upload.append(filename)
|
||||||
|
error_log.append(cstr(e))
|
||||||
|
|
||||||
|
return did_not_upload, list(set(error_log))
|
||||||
|
|
||||||
def get_dropbox_session():
|
def get_dropbox_session():
|
||||||
try:
|
try:
|
||||||
|
@ -10,12 +10,13 @@
|
|||||||
# gdrive_client_id
|
# gdrive_client_id
|
||||||
# gdrive_client_secret
|
# gdrive_client_secret
|
||||||
|
|
||||||
|
from __future__ import unicode_literals
|
||||||
import httplib2
|
import httplib2
|
||||||
import os
|
import os
|
||||||
import mimetypes
|
import mimetypes
|
||||||
import webnotes
|
import webnotes
|
||||||
import oauth2client.client
|
import oauth2client.client
|
||||||
from webnotes.utils import get_base_path
|
from webnotes.utils import get_base_path, cstr
|
||||||
from webnotes import _, msgprint
|
from webnotes import _, msgprint
|
||||||
from apiclient.discovery import build
|
from apiclient.discovery import build
|
||||||
from apiclient.http import MediaFileUpload
|
from apiclient.http import MediaFileUpload
|
||||||
@ -30,6 +31,9 @@ def get_gdrive_authorize_url():
|
|||||||
|
|
||||||
@webnotes.whitelist()
|
@webnotes.whitelist()
|
||||||
def upload_files(name, mimetype, service, folder_id):
|
def upload_files(name, mimetype, service, folder_id):
|
||||||
|
import logging
|
||||||
|
logging.basicConfig()
|
||||||
|
|
||||||
if not webnotes.conn:
|
if not webnotes.conn:
|
||||||
webnotes.connect()
|
webnotes.connect()
|
||||||
file_name = os.path.basename(name)
|
file_name = os.path.basename(name)
|
||||||
@ -69,6 +73,9 @@ def backup_to_gdrive():
|
|||||||
webnotes.conn.get_value("Backup Manager", None, "database_folder_id"))
|
webnotes.conn.get_value("Backup Manager", None, "database_folder_id"))
|
||||||
|
|
||||||
# upload files to files folder
|
# upload files to files folder
|
||||||
|
did_not_upload = []
|
||||||
|
error_log = []
|
||||||
|
|
||||||
path = os.path.join(get_base_path(), "public", "files")
|
path = os.path.join(get_base_path(), "public", "files")
|
||||||
for filename in os.listdir(path):
|
for filename in os.listdir(path):
|
||||||
found = False
|
found = False
|
||||||
@ -78,7 +85,8 @@ def backup_to_gdrive():
|
|||||||
if ext == 'gz' or ext == 'gzip':
|
if ext == 'gz' or ext == 'gzip':
|
||||||
mimetype = 'application/x-gzip'
|
mimetype = 'application/x-gzip'
|
||||||
else:
|
else:
|
||||||
mimetype = mimetypes.types_map["." + ext]
|
mimetype = mimetypes.types_map.get("." + ext) or "application/octet-stream"
|
||||||
|
|
||||||
#Compare Local File with Server File
|
#Compare Local File with Server File
|
||||||
param = {}
|
param = {}
|
||||||
children = drive_service.children().list(
|
children = drive_service.children().list(
|
||||||
@ -90,7 +98,14 @@ def backup_to_gdrive():
|
|||||||
found = True
|
found = True
|
||||||
break
|
break
|
||||||
if not found:
|
if not found:
|
||||||
upload_files(filepath, mimetype, drive_service, webnotes.conn.get_value("Backup Manager", None, "files_folder_id"))
|
try:
|
||||||
|
upload_files(filepath, mimetype, drive_service,
|
||||||
|
webnotes.conn.get_value("Backup Manager", None, "files_folder_id"))
|
||||||
|
except Exception, e:
|
||||||
|
did_not_upload.append(filename)
|
||||||
|
error_log.append(cstr(e))
|
||||||
|
|
||||||
|
return did_not_upload, list(set(error_log))
|
||||||
|
|
||||||
def get_gdrive_flow():
|
def get_gdrive_flow():
|
||||||
from oauth2client.client import OAuth2WebServerFlow
|
from oauth2client.client import OAuth2WebServerFlow
|
||||||
|
@ -41,7 +41,9 @@ cur_frm.cscript.allow_gdrive_access = function(doc) {
|
|||||||
wn.call({
|
wn.call({
|
||||||
method: "setup.doctype.backup_manager.backup_googledrive.get_gdrive_authorize_url",
|
method: "setup.doctype.backup_manager.backup_googledrive.get_gdrive_authorize_url",
|
||||||
callback: function(r) {
|
callback: function(r) {
|
||||||
window.open(r.message.authorize_url);
|
if(!r.exc) {
|
||||||
|
window.open(r.message.authorize_url);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -49,7 +51,7 @@ cur_frm.cscript.allow_gdrive_access = function(doc) {
|
|||||||
|
|
||||||
cur_frm.cscript.validate_gdrive = function(doc) {
|
cur_frm.cscript.validate_gdrive = function(doc) {
|
||||||
wn.call({
|
wn.call({
|
||||||
method: "setup.doctype.backup_manager.backup_manager.gdrive_callback",
|
method: "setup.doctype.backup_manager.backup_googledrive.gdrive_callback",
|
||||||
args: {
|
args: {
|
||||||
verification_code: doc.verification_code
|
verification_code: doc.verification_code
|
||||||
},
|
},
|
||||||
|
@ -4,6 +4,8 @@ from __future__ import unicode_literals
|
|||||||
import webnotes
|
import webnotes
|
||||||
from webnotes import _
|
from webnotes import _
|
||||||
|
|
||||||
|
ignore_list = []
|
||||||
|
|
||||||
class DocType:
|
class DocType:
|
||||||
def __init__(self, d, dl):
|
def __init__(self, d, dl):
|
||||||
self.doc, self.doclist = d, dl
|
self.doc, self.doclist = d, dl
|
||||||
@ -23,22 +25,32 @@ def take_backups_if(freq):
|
|||||||
|
|
||||||
@webnotes.whitelist()
|
@webnotes.whitelist()
|
||||||
def take_backups_dropbox():
|
def take_backups_dropbox():
|
||||||
|
did_not_upload, error_log = [], []
|
||||||
try:
|
try:
|
||||||
from setup.doctype.backup_manager.backup_dropbox import backup_to_dropbox
|
from setup.doctype.backup_manager.backup_dropbox import backup_to_dropbox
|
||||||
backup_to_dropbox()
|
did_not_upload, error_log = backup_to_dropbox()
|
||||||
|
if did_not_upload: raise Exception
|
||||||
|
|
||||||
send_email(True, "Dropbox")
|
send_email(True, "Dropbox")
|
||||||
except Exception:
|
except Exception:
|
||||||
send_email(False, "Dropbox", webnotes.getTraceback())
|
error_message = ("\n".join(error_log) + "\n" + webnotes.getTraceback())
|
||||||
|
print error_message
|
||||||
|
send_email(False, "Dropbox", error_message)
|
||||||
|
|
||||||
#backup to gdrive
|
#backup to gdrive
|
||||||
@webnotes.whitelist()
|
@webnotes.whitelist()
|
||||||
def take_backups_gdrive():
|
def take_backups_gdrive():
|
||||||
|
did_not_upload, error_log = [], []
|
||||||
try:
|
try:
|
||||||
from setup.doctype.backup_manager.backup_googledrive import backup_to_gdrive
|
from setup.doctype.backup_manager.backup_googledrive import backup_to_gdrive
|
||||||
backup_to_gdrive()
|
did_not_upload, error_log = backup_to_gdrive()
|
||||||
|
if did_not_upload: raise Exception
|
||||||
|
|
||||||
send_email(True, "Google Drive")
|
send_email(True, "Google Drive")
|
||||||
except Exception:
|
except Exception:
|
||||||
send_email(False, "Google Drive", webnotes.getTraceback())
|
error_message = ("\n".join(error_log) + "\n" + webnotes.getTraceback())
|
||||||
|
print error_message
|
||||||
|
send_email(False, "Google Drive", error_message)
|
||||||
|
|
||||||
def send_email(success, service_name, error_status=None):
|
def send_email(success, service_name, error_status=None):
|
||||||
if success:
|
if success:
|
||||||
@ -58,4 +70,4 @@ def send_email(success, service_name, error_status=None):
|
|||||||
# email system managers
|
# email system managers
|
||||||
from webnotes.utils.email_lib import sendmail
|
from webnotes.utils.email_lib import sendmail
|
||||||
sendmail(webnotes.conn.get_value("Backup Manager", None, "send_notifications_to").split(","),
|
sendmail(webnotes.conn.get_value("Backup Manager", None, "send_notifications_to").split(","),
|
||||||
subject=subject, msg=message)
|
subject=subject, msg=message)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user