Exemple #1
0
def install_package_to_remote(package, instance):
    try:
        connection = FrappeClient(
            instance.instance_url, instance.username,
            get_decrypted_password(instance.doctype, instance.name))
    except Exception:
        frappe.log_error(frappe.get_traceback())
        frappe.throw(
            _("Couldn't connect to site {0}. Please check Error Logs.").format(
                instance.instance_url))

    try:
        connection.post_request({
            "cmd":
            "frappe.custom.doctype.package_publish_tool.package_publish_tool.import_package",
            "package": json.dumps(package)
        })
    except Exception:
        frappe.log_error(frappe.get_traceback())
        frappe.throw(
            _("Error while installing package to site {0}. Please check Error Logs."
              ).format(instance.instance_url))
Exemple #2
0
    def send_mirror_data(self, item):
        client = FrappeClient(
            self.mirror_url, self.username,
            self.get_password(fieldname="password", raise_exception=False))
        print("Sender: Sending {1}:{2} to remote system on {0}".format(
            client.url, item.doc_type, item.doc_method))

        result = client.post_request({
            "cmd":
            "corrugation.corrugation.doctype.cm_doc_mirror.cm_doc_mirror.mirror_document",
            "seq_no":
            item.seq_no,
            "method":
            item.doc_method,
            "doc":
            json.dumps(item.doc, default=date_handler)
        })
        print("Sender: Received ack {0} for remote request".format(result))
        return int(result)
def create_support_user():
    url = frappe.conf.erpnext_support_url
    user = frappe.conf.erpnext_support_user
    password = frappe.conf.erpnext_support_password

    if not url:
        common_site_config_path = os.path.join(frappe.utils.get_bench_path(),
                                               "sites",
                                               "common_site_config.json")
        url = "https://frappe.erpnext.com"
        update_site_config("erpnext_support_url",
                           url,
                           site_config_path=common_site_config_path)

    if not (user and password):
        user = "******" + frappe.utils.random_string(
            8) + "@erpnext.com"
        password = frappe.utils.random_string(16)

        params = {
            "cmd": "erpnext_support.api.server.make_support_user",
            "user": user,
            "password": password
        }

        r = FrappeClient(url)
        res = json.loads(r.post_request(params))

        if res:
            common_site_config_path = os.path.join(
                frappe.utils.get_bench_path(), "sites",
                "common_site_config.json")
            update_site_config("erpnext_support_user",
                               res.get("user"),
                               site_config_path=common_site_config_path)
            update_site_config("erpnext_support_password",
                               res.get("password"),
                               site_config_path=common_site_config_path)