示例#1
0
def editor_revert(app=None, version=None, check_db=True):
    app = app or frappe.form_dict.app
    version = version or frappe.form_dict.version
    if not app or not version:
        raise frappe.ValidationError

    valid_app_owner(app)

    if check_db is True and not frappe.get_value("IOT Application Version", {
            "app": app,
            "version": version
    }, "name"):
        throw(_("Version {0} does not exits!").format(version))

    app_dir = get_app_release_path(app)
    app_file = os.path.join(app_dir, str(version) + '.zip')

    if not os.access(app_file, os.R_OK):
        throw(_("Version {0}  release file does not exits!").format(version))

    editor_dir = get_app_editor_file_path(app)
    shutil.rmtree(editor_dir, ignore_errors=True)
    os.mkdir(editor_dir)
    f = zipfile.ZipFile(app_file, 'r')
    f.extractall(editor_dir)
    f.close()

    return _("Workspace revert success!")
示例#2
0
def editor_init(app, version=None):
    from app_center.app_center.doctype.iot_application_version.iot_application_version import get_latest_version

    valid_app_owner(app)

    ver = editor_workspace_version(app)
    if ver:
        return ver

    version = int(version or get_latest_version(app, beta=1))

    if version is None:
        version = 0

    # Revert editor workspace to specified version
    if version > 0:
        editor_revert(app, version)
    else:
        editor_dir = get_app_editor_file_path(app)
        if not os.access(editor_dir, os.R_OK):
            os.mkdir(editor_dir)

    # Make sure the workspace has correct version file
    if editor_workspace_version(app) is None:
        editor_dir = get_app_editor_file_path(app)
        vf = open(os.path.join(editor_dir, "version"), 'w')
        vf.write(str(version))
        vf.write('\n')
        vf.write("WEB_EDITOR")
        vf.close()

    return version
示例#3
0
def editor_release(app=None, version=None, comment=None):
    app = app or frappe.form_dict.app
    version = version or frappe.form_dict.version
    comment = comment or frappe.form_dict.comment
    if not app or not version or not comment:
        raise frappe.ValidationError

    valid_app_owner(app)

    data = {
        "doctype": "IOT Application Version",
        "app": app,
        "version": version,
        "beta": 1,
        "comment": comment,
    }

    app_file = zip_application(app, version)

    try:
        doc = frappe.get_doc(data).insert()
        os.system("md5sum " + app_file + " > " + app_file + ".md5")
    except Exception as ex:
        frappe.logger(__name__).error(repr(ex))
        remove_version_file(app, version)
        raise ex

    copy_to_latest(app, version)

    return _("Application upload success")
示例#4
0
def editor_workspace_version(app):
    valid_app_owner(app)

    editor_dir = get_app_editor_file_path(app)
    try:
        vf = open(os.path.join(editor_dir, "version"), 'r')
        if vf:
            version = vf.readline()
            vf.close()
        return int(version)

    except Exception:
        return
示例#5
0
def editor():
    app = frappe.form_dict.app
    operation = frappe.form_dict.operation
    node_id = frappe.form_dict.id if frappe.form_dict.id != "/" else ""
    valid_app_owner(app)

    content = None
    if operation == 'get_node':
        content = editor_get_node(app, node_id)

    if operation == 'create_node':
        type = frappe.form_dict.type
        text = frappe.form_dict.text
        content = editor_create_node(app, node_id, type, text)

    if operation == 'rename_node':
        text = frappe.form_dict.text
        content = editor_rename_node(app, node_id, text)

    if operation == 'move_node':
        dst = frappe.form_dict.parent if frappe.form_dict.parent != "/" else ""
        content = editor_move_node(app, node_id, dst)

    if operation == 'delete_node':
        if frappe.form_dict.id == "/":
            throw(_("Cannot remove root folder"))
        content = editor_delete_node(app, node_id)

    if operation == 'copy_node':
        dst = frappe.form_dict.parent if frappe.form_dict.parent != "/" else ""
        content = editor_copy_node(app, node_id, dst)

    if operation == 'get_content':
        content = editor_get_content(app, node_id)

    if operation == 'set_content':
        text = frappe.form_dict.text
        content = editor_set_content(app, node_id, text)

    if content is not None:
        fire_raw_content(json.dumps(content), 200,
                         'application/json; charset=utf-8')
示例#6
0
def editor_apply():
    from iot.device_api import send_action
    device = frappe.form_dict.device
    inst = frappe.form_dict.inst
    app = frappe.form_dict.app
    if not app or not inst or not device:
        raise frappe.ValidationError

    valid_app_owner(app)

    version = editor_workspace_version(app) or frappe.form_dict.version

    app_file = zip_application(app, version, True)
    os.system("md5sum " + app_file + " > " + app_file + ".md5")

    data = {
        "inst": inst,
        "name": app,
        "fork": 1,
        "version": "beta." + str(version) + ".editor"
    }
    return send_action("app", action="upgrade", device=device, data=data)