chore: code cleanup
This commit is contained in:
parent
bf93a2d4c0
commit
6b944cadef
3 changed files with 11 additions and 33 deletions
|
|
@ -15,9 +15,6 @@ frappe.ui.form.on('Google Drive', {
|
|||
});
|
||||
frappe.call({
|
||||
method: "frappe.integrations.doctype.google_drive.google_drive.upload_system_backup_to_google_drive",
|
||||
args: {
|
||||
"g_drive": frm.doc.name
|
||||
},
|
||||
btn: sync_button
|
||||
}).then((r) => {
|
||||
frappe.msgprint(r.message);
|
||||
|
|
|
|||
|
|
@ -8,12 +8,11 @@
|
|||
"sb_00",
|
||||
"user",
|
||||
"backup_folder_name",
|
||||
"authorize_google_drive_access",
|
||||
"last_backup_on",
|
||||
"column_break_5",
|
||||
"backup_folder_id",
|
||||
"enable_system_backup",
|
||||
"authorize_google_drive_access",
|
||||
"column_break_5",
|
||||
"frequency",
|
||||
"last_backup_on",
|
||||
"refresh_token",
|
||||
"authorization_code"
|
||||
],
|
||||
|
|
@ -58,16 +57,10 @@
|
|||
{
|
||||
"fieldname": "backup_folder_id",
|
||||
"fieldtype": "Data",
|
||||
"label": "Backup Folder ID"
|
||||
"label": "Backup Folder ID",
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"default": "0",
|
||||
"fieldname": "enable_system_backup",
|
||||
"fieldtype": "Check",
|
||||
"label": "Enable System Backup"
|
||||
},
|
||||
{
|
||||
"depends_on": "enable_system_backup",
|
||||
"fieldname": "frequency",
|
||||
"fieldtype": "Select",
|
||||
"label": "Frequency",
|
||||
|
|
@ -93,7 +86,7 @@
|
|||
}
|
||||
],
|
||||
"issingle": 1,
|
||||
"modified": "2019-08-13 17:36:13.014410",
|
||||
"modified": "2019-08-15 22:13:14.637569",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Integrations",
|
||||
"name": "Google Drive",
|
||||
|
|
|
|||
|
|
@ -23,12 +23,6 @@ SCOPES = "https://www.googleapis.com/auth/drive/v3"
|
|||
|
||||
class GoogleDrive(Document):
|
||||
|
||||
def validate(self):
|
||||
if self.enable_system_backup:
|
||||
system_backup = frappe.db.exists("Google Drive", {"enable_system_backup": 1})
|
||||
if system_backup and not system_backup == self.name:
|
||||
frappe.throw(_("Google Drive System Backup can be enabled only for one account."))
|
||||
|
||||
def get_access_token(self):
|
||||
google_settings = frappe.get_doc("Google Settings")
|
||||
|
||||
|
|
@ -179,7 +173,7 @@ def upload_system_backup_to_google_drive():
|
|||
"parents": [account.backup_folder_id]
|
||||
}
|
||||
|
||||
media = MediaFileUpload(get_absolute_path(fileurl, True), mimetype="application/gzip", resumable=True)
|
||||
media = MediaFileUpload(get_absolute_path(fileurl), mimetype="application/gzip", resumable=True)
|
||||
|
||||
try:
|
||||
google_drive.files().create(body=file_metadata, media_body=media, fields="id").execute()
|
||||
|
|
@ -190,19 +184,13 @@ def upload_system_backup_to_google_drive():
|
|||
return _("Google Drive Backup Successful.")
|
||||
|
||||
def daily_backup():
|
||||
g_drive = frappe.db.exists("Google Drive", {"enable": 1, "enable_system_backup": 1, "frequency": "Daily"})
|
||||
if g_drive:
|
||||
if frappe.db.get_single_value("Google Drive", "frequency") == "Daily":
|
||||
upload_system_backup_to_google_drive()
|
||||
|
||||
def weekly_backup():
|
||||
g_drive = frappe.db.exists("Google Drive", {"enable": 1, "enable_system_backup": 1, "frequency": "Weekly"})
|
||||
if g_drive:
|
||||
if frappe.db.get_single_value("Google Drive", "frequency") == "Weekly":
|
||||
upload_system_backup_to_google_drive()
|
||||
|
||||
def get_absolute_path(filename, backup=False):
|
||||
file_path = os.path.join(get_files_path()[2:], filename)
|
||||
|
||||
if backup:
|
||||
file_path = os.path.join(get_backups_path()[2:], filename)
|
||||
|
||||
def get_absolute_path(filename):
|
||||
file_path = os.path.join(get_backups_path()[2:], filename)
|
||||
return "{0}/sites/{1}".format(get_bench_path(), file_path)
|
||||
Loading…
Add table
Reference in a new issue