feat: package migrator

This commit is contained in:
Himanshu Warekar 2020-03-17 11:37:47 +05:30 committed by Saurabh
parent ea93f12a9a
commit f0ec5cec0e
5 changed files with 131 additions and 0 deletions

View file

@ -0,0 +1,51 @@
// Copyright (c) 2020, Frappe Technologies and contributors
// For license information, please see license.txt
frappe.ui.form.on('Package Migration', {
refresh: function(frm) {
if (frm.doc.attach) {
frm.add_custom_button(__("Connect"), function() {
let dialog = new frappe.ui.Dialog({
title: __('Connect to Remote Instance'),
fields: [
{
fieldtype: 'Data',
label: 'Remote Instance',
fieldname: 'remote_instance',
reqd: 1
},
{
fieldtype: 'Data',
label: 'User',
fieldname: 'user',
reqd: 1
},
{
fieldtype: 'Password',
label: 'Password',
fieldname: 'password',
reqd: 1
},
],
primary_action: function() {
let values = dialog.get_values();
frm.call("install_package_to_remote", {
"remote_instance": values.remote_instance,
"user": values.user,
"password": values.password
}).then((r) => {
console.log(r);
})
dialog.hide();
},
primary_action_label: "Execute"
});
dialog.show();
})
}
}
});
// "erpnext_support_password": "uYrMeEhb2NzuEGOk",
// "erpnext_support_url": "https://marketplace.erpnext.com",
// "erpnext_support_user": "erpnext_support_fQrhUujW@erpnext.com",

View file

@ -0,0 +1,42 @@
{
"actions": [],
"creation": "2020-03-17 00:13:31.851579",
"doctype": "DocType",
"editable_grid": 1,
"engine": "InnoDB",
"field_order": [
"attach"
],
"fields": [
{
"fieldname": "attach",
"fieldtype": "Attach",
"in_list_view": 1,
"label": "Attach",
"reqd": 1
}
],
"issingle": 1,
"links": [],
"modified": "2020-03-17 10:00:26.676328",
"modified_by": "Administrator",
"module": "Custom",
"name": "Package Migration",
"owner": "Administrator",
"permissions": [
{
"create": 1,
"delete": 1,
"email": 1,
"print": 1,
"read": 1,
"role": "System Manager",
"share": 1,
"write": 1
}
],
"quick_entry": 1,
"sort_field": "modified",
"sort_order": "DESC",
"track_changes": 1
}

View file

@ -0,0 +1,28 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2020, Frappe Technologies and contributors
# For license information, please see license.txt
from __future__ import unicode_literals
import frappe
from frappe.frappeclient import FrappeClient
from frappe.model.document import Document
from frappe import _
class PackageMigration(Document):
def install_package_to_remote(self, remote_instance, user, password):
connection = FrappeClient(remote_instance, user, password)
package_file = frappe.get_all("File", filters={
"attached_to_doctype": "Package Migration",
"attached_to_name": "Package Migration"
}, limit=1, order_by="creation desc")
try:
connection.post_request({
"cmd": "frappe.custom.doctype.package.package.import_package",
"package": frappe.get_doc("File", package_file[0].name).get_content()
})
except Exception:
frappe.log_error(frappe.get_traceback())
frappe.throw(_("Could not connect to Remote Site."))

View file

@ -0,0 +1,10 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2020, Frappe Technologies and Contributors
# See license.txt
from __future__ import unicode_literals
# import frappe
import unittest
class TestPackageMigration(unittest.TestCase):
pass