diff --git a/setup/doctype/backup_manager/backup_googledrive.py b/setup/doctype/backup_manager/backup_googledrive.py index a705f0efa9..533b37ddb0 100644 --- a/setup/doctype/backup_manager/backup_googledrive.py +++ b/setup/doctype/backup_manager/backup_googledrive.py @@ -92,8 +92,7 @@ def backup_to_gdrive(): mimetype = mimetypes.types_map.get("." + ext) or "application/octet-stream" #Compare Local File with Server File - param = {} - children = drive_service.children().list(folderId=files_folder_id, **param).execute() + children = drive_service.children().list(folderId=files_folder_id).execute() for child in children.get('items', []): file = drive_service.files().get(fileId=child['id']).execute() if filename == file['title'] and size == int(file['fileSize']): diff --git a/setup/doctype/backup_manager/backup_manager.js b/setup/doctype/backup_manager/backup_manager.js index 8d2d8de853..c78be3a1eb 100644 --- a/setup/doctype/backup_manager/backup_manager.js +++ b/setup/doctype/backup_manager/backup_manager.js @@ -1,67 +1,90 @@ -cur_frm.cscript.refresh = function(doc) { - cur_frm.disable_save(); -} - -//dropbox -cur_frm.cscript.allow_dropbox_access = function(doc) { - if (doc.send_notifications_to == '') { - msgprint("Please enter email address.") - } - else { - wn.call({ - method: "setup.doctype.backup_manager.backup_dropbox.get_dropbox_authorize_url", - callback: function(r) { - if(!r.exc) { - cur_frm.set_value("dropbox_access_secret", r.message.secret); - cur_frm.set_value("dropbox_access_key", r.message.key); - cur_frm.save(null, function() { - window.open(r.message.url); - }); - } +$.extend(cur_frm.cscript, { + refresh: function() { + cur_frm.disable_save(); + + if(!(cint(cur_frm.doc.dropbox_access_allowed) || + cint(cur_frm.doc.gdrive_access_allowed))) { + cur_frm.set_intro(wn._("You can start by selecting backup frequency and \ + granting access for sync")); + } else { + var services = { + "dropbox": wn._("Dropbox"), + "gdrive": wn._("Google Drive") + } + var active_services = []; + + $.each(services, function(service, label) { + var access_allowed = cint(cur_frm.doc[service + "_access_allowed"]); + var frequency = cur_frm.doc["upload_backups_to_" + service]; + if(access_allowed && frequency && frequency !== "Never") { + active_services.push(label + " [" + frequency + "]"); + } + }); + + if(active_services.length > 0) { + cur_frm.set_intro(wn._("Backups will be uploaded to") + ": " + + wn.utils.comma_and(active_services)); + } else { + cur_frm.set_intro(""); } - }) - } -} - -cur_frm.cscript.backup_right_now = function(doc) { - msgprint("Backing up and uploading. This may take a few minutes.") - wn.call({ - method: "setup.doctype.backup_manager.backup_manager.take_backups_dropbox", - callback: function(r) { - msgprint("Backups taken. Please check your email for the response.") } - }) -} -//gdrive -cur_frm.cscript.allow_gdrive_access = function(doc) { - if (doc.send_notifications_to == '') { - msgprint("Please enter email address.") - } - else { - wn.call({ - method: "setup.doctype.backup_manager.backup_googledrive.get_gdrive_authorize_url", - callback: function(r) { - if(!r.exc) { - window.open(r.message.authorize_url); + + }, + + validate_send_notifications_to: function() { + if(!cur_frm.doc.send_notifications_to) { + msgprint(wn._("Please specify") + ": " + + wn._(wn.meta.get_label(cur_frm.doctype, "send_notifications_to"))); + return false; + } + + return true; + }, + + allow_dropbox_access: function() { + if(cur_frm.cscript.validate_send_notifications_to()) { + wn.call({ + method: "setup.doctype.backup_manager.backup_dropbox.get_dropbox_authorize_url", + callback: function(r) { + if(!r.exc) { + cur_frm.set_value("dropbox_access_secret", r.message.secret); + cur_frm.set_value("dropbox_access_key", r.message.key); + cur_frm.save(null, function() { + window.open(r.message.url); + }); + } } - } - }) - } -} - -cur_frm.cscript.validate_gdrive = function(doc) { - wn.call({ - method: "setup.doctype.backup_manager.backup_googledrive.gdrive_callback", - args: { - verification_code: doc.verification_code - }, - }); -} - -cur_frm.cscript.upload_backups_to_dropbox = function(doc) { - cur_frm.save() -} - -cur_frm.cscript.upload_backups_to_gdrive = function(doc) { - cur_frm.save() -} + }); + } + }, + + allow_gdrive_access: function() { + if(cur_frm.cscript.validate_send_notifications_to()) { + wn.call({ + method: "setup.doctype.backup_manager.backup_googledrive.get_gdrive_authorize_url", + callback: function(r) { + if(!r.exc) { + window.open(r.message.authorize_url); + } + } + }); + } + }, + + validate_gdrive: function() { + wn.call({ + method: "setup.doctype.backup_manager.backup_googledrive.gdrive_callback", + args: { + verification_code: cur_frm.doc.verification_code + }, + }); + }, + + upload_backups_to_dropbox: function() { + cur_frm.save(); + }, + + upload_backups_to_gdrive: function() { + cur_frm.save(); + }, +}); \ No newline at end of file diff --git a/setup/doctype/backup_manager/backup_manager.py b/setup/doctype/backup_manager/backup_manager.py index a8ecd636db..c91cf1110f 100644 --- a/setup/doctype/backup_manager/backup_manager.py +++ b/setup/doctype/backup_manager/backup_manager.py @@ -20,8 +20,8 @@ def take_backups_if(freq): if webnotes.conn.get_value("Backup Manager", None, "upload_backups_to_dropbox")==freq: take_backups_dropbox() - if webnotes.conn.get_value("Backup Manager", None, "upload_backups_to_gdrive")==freq: - take_backups_gdrive() + # if webnotes.conn.get_value("Backup Manager", None, "upload_backups_to_gdrive")==freq: + # take_backups_gdrive() @webnotes.whitelist() def take_backups_dropbox(): @@ -35,7 +35,7 @@ def take_backups_dropbox(): except Exception: file_and_error = [" - ".join(f) for f in zip(did_not_upload, error_log)] error_message = ("\n".join(file_and_error) + "\n" + webnotes.getTraceback()) - print error_message + webnotes.errprint(error_message) send_email(False, "Dropbox", error_message) #backup to gdrive @@ -51,7 +51,7 @@ def take_backups_gdrive(): except Exception: file_and_error = [" - ".join(f) for f in zip(did_not_upload, error_log)] error_message = ("\n".join(file_and_error) + "\n" + webnotes.getTraceback()) - print error_message + webnotes.errprint(error_message) send_email(False, "Google Drive", error_message) def send_email(success, service_name, error_status=None): diff --git a/setup/doctype/backup_manager/backup_manager.txt b/setup/doctype/backup_manager/backup_manager.txt index 9a43f34746..2d6f191e5e 100644 --- a/setup/doctype/backup_manager/backup_manager.txt +++ b/setup/doctype/backup_manager/backup_manager.txt @@ -1,8 +1,8 @@ [ { - "creation": "2013-03-15 11:06:59", + "creation": "2013-04-30 12:58:38", "docstatus": 0, - "modified": "2013-03-15 17:27:33", + "modified": "2013-05-02 11:42:08", "modified_by": "Administrator", "owner": "Administrator" }, @@ -109,6 +109,7 @@ "doctype": "DocField", "fieldname": "sync_with_gdrive", "fieldtype": "Section Break", + "hidden": 1, "label": "Sync with Google Drive" }, {