Beispiel #1
0
def raw_to_subpkg_kw(raw_dict):
    d = build_ast_from_raw_dict(raw_dict)

    libraries_d, misc_d = extract_top_dicts_subento(deepcopy(d))

    kw = {}
    libraries = build_libs_from_dict(libraries_d)
    kw.update(libraries)
    kw["hook_files"] = misc_d["hook_files"]
    sub_directory = kw.pop("sub_directory")
    if sub_directory is not None:
        raise InternalBentoError("Unexpected sub_directory while parsing recursed bendo")

    return kw, misc_d["subento"]
Beispiel #2
0
def raw_to_options_kw(raw):
    d = build_ast_from_raw_dict(raw)

    kw = {}
    if not "name" in d:
        raise ValueError("No name field found")
    kw["name"] = d["name"]

    kw["path_options"] = {}
    path_options = d.get("path_options", {})
    for name, path in list(path_options.items()):
        kw["path_options"][name] = PathOption(path["name"], path["default"],
                                              path["description"])

    kw["flag_options"] = {}
    flag_options = d.get("flag_options", {})
    for name, flag in list(flag_options.items()):
        kw["flag_options"][name] = FlagOption(flag["name"], flag["default"],
                                              flag["description"])

    return kw
Beispiel #3
0
def raw_to_options_kw(raw):
    d = build_ast_from_raw_dict(raw)

    kw = {}
    if not "name" in d:
        raise ValueError("No name field found")
    kw["name"] = d["name"]

    kw["path_options"] = {}
    path_options = d.get("path_options", {})
    for name, path in path_options.items():
        kw["path_options"][name] = PathOption(path["name"],
                                              path["default"],
                                              path["description"])

    kw["flag_options"] = {}
    flag_options = d.get("flag_options", {})
    for name, flag in flag_options.items():
        kw["flag_options"][name] = FlagOption(flag["name"],
                                              flag["default"],
                                              flag["description"])

    return kw
Beispiel #4
0
def raw_to_pkg_kw(raw_dict, user_flags, bento_info=None):
    if bento_info is None:
        source_dir = os.getcwd()
    else:
        # bento_info may be a string or a node
        try:
            source_dir = bento_info.parent.abspath()
            bento_info_path = bento_info.srcpath()
        except AttributeError:
            if os.path.isabs(bento_info):
                source_dir = os.path.dirname(bento_info)
                bento_info_path = os.path.basename(bento_info)
            else:
                source_dir = os.getcwd()
                bento_info_path = os.path.basename(bento_info)
                assert bento_info_path == bento_info

    d = build_ast_from_raw_dict(raw_dict, user_flags)

    meta_d, libraries_d, options_d, misc_d = extract_top_dicts(deepcopy(d))
    libraries = build_libs_from_dict(libraries_d)
    executables = build_executables_from_dict(misc_d.pop("executables"))
    data_files = build_data_files_from_dict(misc_d.pop("data_files"))

    kw = {}
    kw.update(meta_d)
    for k in libraries:
        kw[k] = libraries[k]
    kw["executables"] = executables
    kw["data_files"] = data_files

    misc_d.pop("path_options")
    misc_d.pop("flag_options")

    if "subento" in misc_d:
        subentos = misc_d.pop("subento")
        if len(subentos
               ) > 0 and libraries and libraries["sub_directory"] is not None:
            raise InvalidPackage(
                "You cannot use both Recurse and Library:SubDirectory features !"
            )
        else:
            subpackages, files = recurse_subentos(subentos,
                                                  source_dir=source_dir)
            kw["subpackages"] = subpackages
    else:
        files = []

    kw.update(misc_d)
    if bento_info is not None:
        files.append(bento_info_path)
    files.extend(misc_d["hook_files"])
    # XXX: Do we want to automatically add the hook and bento files in extra
    # source files at the PackageDescription level ?
    kw["extra_source_files"].extend(files)

    if "description_from_file" in kw:
        if bento_info:
            description_file = os.path.join(source_dir,
                                            kw["description_from_file"])
        else:
            description_file = kw["description_from_file"]
        if not os.path.exists(description_file):
            raise IOError("Description file %r not found" %
                          (description_file, ))
        else:
            f = open(description_file)
            try:
                kw["description"] = f.read()
            finally:
                f.close()
    return kw, files
Beispiel #5
0
def raw_to_pkg_kw(raw_dict, user_flags, bento_info=None):
    if bento_info is None:
        source_dir = os.getcwd()
    else:
        # bento_info may be a string or a node
        try:
            source_dir = bento_info.parent.abspath()
            bento_info_path = bento_info.srcpath()
        except AttributeError:
            if os.path.isabs(bento_info):
                source_dir = os.path.dirname(bento_info)
                bento_info_path = os.path.basename(bento_info)
            else:
                source_dir = os.getcwd()
                bento_info_path = os.path.basename(bento_info)
                assert bento_info_path == bento_info

    d = build_ast_from_raw_dict(raw_dict, user_flags)

    meta_d, libraries_d, options_d, misc_d = extract_top_dicts(deepcopy(d))
    libraries = build_libs_from_dict(libraries_d)
    executables = build_executables_from_dict(misc_d.pop("executables"))
    data_files = build_data_files_from_dict(misc_d.pop("data_files"))

    kw = {}
    kw.update(meta_d)
    for k in libraries:
        kw[k] = libraries[k]
    kw["executables"] = executables
    kw["data_files"] = data_files

    misc_d.pop("path_options")
    misc_d.pop("flag_options")

    if "subento" in misc_d:
        subentos = misc_d.pop("subento")
        if len(subentos) > 0 and libraries and libraries["sub_directory"] is not None:
            raise InvalidPackage("You cannot use both Recurse and Library:SubDirectory features !")
        else:
            subpackages, files = recurse_subentos(subentos, source_dir=source_dir)
            kw["subpackages"] = subpackages
    else:
        files = []

    kw.update(misc_d)
    if bento_info is not None:
        files.append(bento_info_path)
    files.extend(misc_d["hook_files"])
    # XXX: Do we want to automatically add the hook and bento files in extra
    # source files at the PackageDescription level ?
    kw["extra_source_files"].extend(files)

    if "description_from_file" in kw:
        if bento_info:
            description_file = os.path.join(source_dir, kw["description_from_file"])
        else:
            description_file = kw["description_from_file"]
        if not os.path.exists(description_file):
            raise IOError("Description file %r not found" % (description_file,))
        else:
            f = open(description_file)
            try:
                kw["description"] = f.read()
            finally:
                f.close()
    return kw, files