Exemple #1
0
def write_libraries(config):

    INFO("Libraries Data: Processing...")

    libs_path = os.path.join(config["source"], constants.LIBRARIES_FOLDER)
    if not os.path.exists(libs_path):
        CRITICAL("Can't find: {}".format(libs_path))
        emergency_exit()

    write_xml("Libraries", indent=2)

    files = list(set(os.listdir(libs_path)) - set(constants.RESERVED_NAMES))
    for lib_name in sorted(files):
        lib_path = os.path.join(libs_path, lib_name)

        if not os.path.isfile(lib_path):
            continue

        DEBUG("Open file: %s", lib_path)
        with open_file(lib_path) as lib_f:
            write_xml(
                tagname="Library",
                attrs={"Name": lib_name.split(".", 1)[0]},
                indent=4,
                data=lib_f.read(),
                close=True
            )

    write_xml("Libraries", indent=2, closing=True)
    INFO("Libraries Data: Done!")
Exemple #2
0
def write_resources(config):

    INFO("Resources Data: Processing...")

    resources_path = os.path.join(config["source"], constants.RESOURCES_FOLDER)
    if not os.path.exists(resources_path):
        CRITICAL("Can't find: {}".format(resources_path))
        emergency_exit()

    write_xml("Resources", indent=2)

    files = list(set(os.listdir(resources_path)) - set(constants.RESERVED_NAMES))
    for res_name in sorted(files):
        res_path = os.path.join(resources_path, res_name)

        if not os.path.isfile(res_path):
            continue

        raw_name = res_name.split("_", 2)

        try:
            res_guid = UUID(raw_name[0])

        except ValueError:
            res_guid = gen_guid()
            res_type = res_name.rsplit(".", 1)
            res_type = res_type[1] if len(res_type) == 2 else "res"

        else:
            res_type = raw_name[1]
            res_name = raw_name[2]

        attrs = {
            "ID": res_guid,
            "Name": res_name,
            "Type": res_type
        }

        DEBUG("Open file: %s", res_path)
        with open_file(res_path) as res_f:
            write_xml(
                tagname="Resource",
                attrs=attrs,
                indent=4,
                data=base64.b64encode(res_f.read()),
                close=True
            )

    write_xml("Resources", indent=2, closing=True)
    INFO("Resources Data: Done!")
Exemple #3
0
def write_pages(config):

    INFO("Pages Data: Processing...")

    pages_path = os.path.join(config["source"], constants.PAGES_FOLDER)

    if not os.path.exists(pages_path):
        CRITICAL("Can't find: {}".format(pages_path))
        emergency_exit()

    write_xml("Objects", indent=2)
    for page in sorted(os.listdir(pages_path)):
        walk(pages_path, page, indent=4)

    write_xml("Objects", indent=2, closing=True)


    actions_path = os.path.join(config["source"], constants.APP_ACTIONS_FOLDER)
    write_actions(actions_path, 2)

    INFO("Pages Data: Done!")
Exemple #4
0
def parse_ignore_file(config):
    """Convert strings to regexps
    """
    global IGNORE

    if not config["ignore"]:
        config["ignore"] = {}

    if not isinstance(config["ignore"], dict):
        ERROR("Ignore settings must be dict")
        emergency_exit()

    keys = ["Resources", "Libraries", "Databases", "Actions", "Pages"]

    for key in keys:
        data = config["ignore"].get(key, [])
        if not isinstance(data, (list, tuple)):
            data = (data, )

        config["ignore"][key] = convert_to_regexp(data)

    IGNORE = config["ignore"]
Exemple #5
0
def walk(path, name, indent):
    new_path = os.path.join(path, name)
    actions_folder = "Actions-{}".format(name)

    info_path = os.path.join(new_path, constants.INFO_FILE)
    if not os.path.exists(info_path):
        CRITICAL("Can't find: {}".format(info_path))
        emergency_exit()

    with open_file(info_path) as info_file:
        info_json = json_load(info_file, critical=True)

    attrs = info_json["attrs"]
    if attrs is not None and 'ID' in attrs:
        id = attrs['ID']
        if id in OBJS:
            ERROR("Encountered duplicate GUID: {duplicate} duplicates {origin}: Ignoring {duplicate}".format(
                duplicate=name, origin=OBJS[id]
            ))
            return
        else:
            OBJS[id] = name

    write_xml("Object", attrs=attrs, indent=indent)
    write_actions(os.path.join(new_path, actions_folder), indent+2)
    write_xml("Objects", indent=indent+2)


    childs_order_path = os.path.join(new_path, constants.CHILDS_ORDER)

    if os.path.exists(childs_order_path):
        with open(childs_order_path) as f:
            names = json_load(f, default=[], critical=False)
            names = map(lambda s: s.lower(), names)
            childs_order = dict(zip(names, xrange(len(names))))
    else:
        childs_order = {}

    max_value = len(childs_order) + 1


    def key_func(name):
        key = name.lower()
        if key.endswith('.json'): 
            key = key[:-5]

        return [childs_order.get(key, max_value), name]

    nodes = list(set(os.listdir(new_path)) - set(constants.RESERVED_NAMES) - {actions_folder})
    nodes = [node for node in nodes if not constants.RESERVED_NAMES_REGEXP.match(node)]
    ordered_nodes = sorted(nodes, key=key_func)

    for name in ordered_nodes:
        if os.path.isdir(os.path.join(new_path, name)):
            walk(new_path, name, indent+4)

        else:
            write_object(new_path, name, indent+4)

    write_xml("Objects", indent=indent+2, closing=True)
    write_attributes(info_json["attributes"], indent+2)
    write_xml("Object", indent=indent, closing=True)