Ejemplo n.º 1
0
def getEditModuleHierarchy(typename):
    _menu = {}
    menus = {}
    types = []

    for type in loadAllDatatypes():
        if type.name == typename:
            types = [type]
            break

    for dtype in types:  # get menu for type
        _items = {}
        if dtype.name != "root":
            n = tree.Node("", type=dtype.name)
            menu_str = getEditMenuString(dtype.name)

            if menu_str != "":
                menus[n.type] = parseMenuString(menu_str)
                _menu = {}
                _menu[-1] = []

                editModules = getEditModules()  # modules installed in system

                for module in editModules:
                    if module.startswith("menu"):
                        active = -1
                        for m in menus[n.type]:
                            if m.getName().endswith(module):
                                active = menus[n.type].index(m)
                                break
                        if active not in _menu.keys():
                            _menu[active] = []
                        _menu[active].append(module)

                    else:
                        active = -1
                        for m in menus[n.type]:
                            items = m.getItemList()
                            for item in items:
                                if item == module:
                                    active = menus[n.type].index(m)
                                    if active not in _items.keys():
                                        _items[active] = []
                                    _items[active].append(
                                        (module, items.index(item)))
                                    break

                        if active == -1:
                            if active not in _items.keys():
                                _items[active] = []
                            _items[active].append((module, 0))

                for key in _menu.keys():
                    if key in _items.keys():
                        items = _items[key]
                        items.sort(lambda x, y: cmp(x[1], y[1]))
                        for item in items:
                            _menu[key].append(item[0])
    return _menu
Ejemplo n.º 2
0
def getEditModuleHierarchy(typename):
    _menu = {}
    menus = {}
    types = []

    for type in loadAllDatatypes():
        if type.name == typename:
            types = [type]
            break

    for dtype in types:  # get menu for type
        _items = {}
        if dtype.name != "root":
            n = tree.Node("", type=dtype.name)
            menu_str = getEditMenuString(dtype.name)

            if menu_str != "":
                menus[n.type] = parseMenuString(menu_str)
                _menu = {}
                _menu[-1] = []

                editModules = getEditModules()  # modules installed in system

                for module in editModules:
                    if module.startswith("menu"):
                        active = -1
                        for m in menus[n.type]:
                            if m.getName().endswith(module):
                                active = menus[n.type].index(m)
                                break
                        if active not in _menu.keys():
                            _menu[active] = []
                        _menu[active].append(module)

                    else:
                        active = -1
                        for m in menus[n.type]:
                            items = m.getItemList()
                            for item in items:
                                if item == module:
                                    active = menus[n.type].index(m)
                                    if active not in _items.keys():
                                        _items[active] = []
                                    _items[active].append((module, items.index(item)))
                                    break

                        if active == -1:
                            if active not in _items.keys():
                                _items[active] = []
                            _items[active].append((module, 0))

                for key in _menu.keys():
                    if key in _items.keys():
                        items = _items[key]
                        items.sort(lambda x, y: cmp(x[1], y[1]))
                        for item in items:
                            _menu[key].append(item[0])
    return _menu
Ejemplo n.º 3
0
def editModuleActions(req):
    for key in req.params.keys():
        if key == "editmodules_default":
            type = req.params.get("datatype")
            getRoot().set("edit.menu." + type,
                          getEditMenuString(type, default=1))
            break

        elif key.startswith("del|"):
            ret = ""
            m = key.split("|")[-1][:-2]
            type = req.params.get("datatype")
            items = getEditModuleHierarchy(type)
            for k in items:
                if k >= 0 and not (m.startswith("menu") and items[k][0] == m):
                    i = [item for item in items[k] if item != m]
                    if len(i) > 1:
                        ret += i[0] + "(" + ";".join(i[1:]) + ");"
                    else:
                        ret += i[0] + "();"
            getRoot().set("edit.menu." + type, ret[:-1])
            break

        elif key.startswith("show|"):  # add menu
            item = key.split("|")[-1][:-2]
            type = req.params.get("datatype")
            menu_str = getEditMenuString(type) + ";" + item + "()"
            getRoot().set("edit.menu." + type, menu_str)
            break

        elif key.startswith("move|") and req.params.get(key) != "":
            # move item to menu
            dest = req.params.get(key)
            dest_id = -1
            mod = key.split("|")[-1]
            type = req.params.get("datatype")
            items = getEditModuleHierarchy(type)
            for k in items:
                if dest in items[k]:
                    dest_id = k
                if mod in items[k]:
                    items[k].remove(mod)
            items[dest_id].append(mod)

            ret = ""
            for k in items:
                if len(items[k]) == 0 or k < 0:
                    pass
                elif items[k][0].startswith("menu"):
                    ret += items[k][0] + "(" + ";".join(items[k][1:]) + ");"
            getRoot().set("edit.menu." + type, ret[:-1])
            break

        elif key.startswith("up|"):
            # move module or module item up
            m = key[:-2].split("|")[-1]
            type = req.params.get("datatype")
            items = getEditModuleHierarchy(type)
            for k in items:
                if m in items[k] and items[k].index(m) == 0:  # menu
                    src = items[k]
                    items[k] = items[k - 1]
                    items[k - 1] = src
                    break

                elif m in items[k] and items[k].index > 0:  # menu item
                    src_id = items[k].index(m)
                    items[k][src_id] = items[k][src_id - 1]
                    items[k][src_id - 1] = m
                    break

            ret = ""
            for k in items:
                if len(items[k]) == 0 or k < 0:
                    pass
                elif items[k][0].startswith("menu"):
                    ret += items[k][0] + "(" + ";".join(items[k][1:]) + ");"
            getRoot().set("edit.menu." + type, ret[:-1])
            break

        elif key.startswith("down|"):
            # move module or module item down
            m = key[:-2].split("|")[-1]
            type = req.params.get("datatype")
            items = getEditModuleHierarchy(type)
            for k in items:
                if m in items[k] and items[k].index(m) == 0:  # menu
                    src = items[k]
                    items[k] = items[k + 1]
                    items[k + 1] = src
                    break

                elif m in items[k] and items[k].index > 0:  # menu item
                    src_id = items[k].index(m)
                    items[k][src_id] = items[k][src_id + 1]
                    items[k][src_id + 1] = m
                    break

            ret = ""
            for k in items:
                if len(items[k]) == 0 or k < 0:
                    pass
                elif items[k][0].startswith("menu"):
                    ret += items[k][0] + "(" + ";".join(items[k][1:]) + ");"
            getRoot().set("edit.menu." + type, ret[:-1])
            break
Ejemplo n.º 4
0
def editModuleActions(req):
    for key in req.params.keys():
        if key == "editmodules_default":
            type = req.params.get("datatype")
            getRoot().set("edit.menu." + type, getEditMenuString(type, default=1))
            break

        elif key.startswith("del|"):
            ret = ""
            m = key.split("|")[-1][:-2]
            type = req.params.get("datatype")
            items = getEditModuleHierarchy(type)
            for k in items:
                if k >= 0 and not (m.startswith("menu") and items[k][0] == m):
                    i = [item for item in items[k] if item != m]
                    if len(i) > 1:
                        ret += i[0] + "(" + ";".join(i[1:]) + ");"
                    else:
                        ret += i[0] + "();"
            getRoot().set("edit.menu." + type, ret[:-1])
            break

        elif key.startswith("show|"):  # add menu
            item = key.split("|")[-1][:-2]
            type = req.params.get("datatype")
            menu_str = getEditMenuString(type) + ";" + item + "()"
            getRoot().set("edit.menu." + type, menu_str)
            break

        elif key.startswith("move|") and req.params.get(key) != "":
            # move item to menu
            dest = req.params.get(key)
            dest_id = -1
            mod = key.split("|")[-1]
            type = req.params.get("datatype")
            items = getEditModuleHierarchy(type)
            for k in items:
                if dest in items[k]:
                    dest_id = k
                if mod in items[k]:
                    items[k].remove(mod)
            items[dest_id].append(mod)

            ret = ""
            for k in items:
                if len(items[k]) == 0 or k < 0:
                    pass
                elif items[k][0].startswith("menu"):
                    ret += items[k][0] + "(" + ";".join(items[k][1:]) + ");"
            getRoot().set("edit.menu." + type, ret[:-1])
            break

        elif key.startswith("up|"):
            # move module or module item up
            m = key[:-2].split("|")[-1]
            type = req.params.get("datatype")
            items = getEditModuleHierarchy(type)
            for k in items:
                if m in items[k] and items[k].index(m) == 0:  # menu
                    src = items[k]
                    items[k] = items[k - 1]
                    items[k - 1] = src
                    break

                elif m in items[k] and items[k].index > 0:  # menu item
                    src_id = items[k].index(m)
                    items[k][src_id] = items[k][src_id - 1]
                    items[k][src_id - 1] = m
                    break

            ret = ""
            for k in items:
                if len(items[k]) == 0 or k < 0:
                    pass
                elif items[k][0].startswith("menu"):
                    ret += items[k][0] + "(" + ";".join(items[k][1:]) + ");"
            getRoot().set("edit.menu." + type, ret[:-1])
            break

        elif key.startswith("down|"):
            # move module or module item down
            m = key[:-2].split("|")[-1]
            type = req.params.get("datatype")
            items = getEditModuleHierarchy(type)
            for k in items:
                if m in items[k] and items[k].index(m) == 0:  # menu
                    src = items[k]
                    items[k] = items[k + 1]
                    items[k + 1] = src
                    break

                elif m in items[k] and items[k].index > 0:  # menu item
                    src_id = items[k].index(m)
                    items[k][src_id] = items[k][src_id + 1]
                    items[k][src_id + 1] = m
                    break

            ret = ""
            for k in items:
                if len(items[k]) == 0 or k < 0:
                    pass
                elif items[k][0].startswith("menu"):
                    ret += items[k][0] + "(" + ";".join(items[k][1:]) + ");"
            getRoot().set("edit.menu." + type, ret[:-1])
            break