Ejemplo n.º 1
0
    def target_machine():
        result = Platform._key_value_file_lookup("TARGET_MACHINE",
                                                 "/etc/target")

        if not result:
            result = PackageManager.instance().main_architecture()
        if not result:
            result = Platform.config_guess().split("-")[0]
        return result
Ejemplo n.º 2
0
        def package_name(self):
            if self.pkg_name is None:
                pkg_manager = PackageManager.instance()

                self.pkg_name = (
                    pkg_manager.which_package_provides(self.lib_path) or
                    pkg_manager.which_package_provides(
                        os.path.realpath(self.lib_path)
                    )
                )

            return self.pkg_name
Ejemplo n.º 3
0
 def package_version(self):
     if self.pkg_version is None:
         pkg_manager = PackageManager.instance()
         self.pkg_version = pkg_manager\
                 .installed_version_of_package(self.package_name())
     return self.pkg_version
Ejemplo n.º 4
0
 def package_name(self):
     if self.pkg_name is None:
         pkg_manager = PackageManager.instance()
         self.pkg_name = \
                 pkg_manager.which_package_provides(self.lib_path)
     return self.pkg_name
Ejemplo n.º 5
0
    def __init__(self, xml_config, **kwargs):
        actual_build_for = kwargs.get("build_for", "target")

        if "machine" in kwargs:
            machine = kwargs["machine"]
        elif actual_build_for in ["tools", "cross-tools"]:
            machine = Platform.tools_machine()
        else:
            machine = Platform.target_machine()

        if isinstance(xml_config, etree._Element):
            bin_node = xml_config
        elif isinstance(xml_config, str):
            bin_node = etree.fromstring(xml_config)
        else:
            msg = "expected 'etree._Element' or 'str' but got '%s'" % \
                    xml_config.__class__.__name__
            raise ValueError(msg)
        #end if

        epoch = \
            bin_node.get("epoch",    0)
        version = \
            bin_node.get("version", "")
        revision = \
            bin_node.get("revision", None)

        self.name = \
            bin_node.get("name")
        self.description = \
            PackageDescription(bin_node.find("description"))
        self.maintainer = \
            bin_node.get("maintainer") + " <" + \
            bin_node.get("email") + ">"

        self.version = \
            (epoch + ":" if int(epoch) > 0 else "") + version + \
            ("-" + revision if revision is not None else "")

        self.section = \
            bin_node.get("section", "unknown")
        self.source = \
            bin_node.get("source")
        self.architecture = \
            bin_node.get("architecture")

        # This is the XML attribute.
        self.build_for = bin_node.get("build-for")
        if self.build_for:
            self.build_for = [v.strip() for v in self.build_for.split(",")]

        # This is the XML attribute.
        self.supported_on = bin_node.get("supported-on")
        if self.supported_on:
            self.supported_on = [
                v.strip() for v in self.supported_on.split(",")
            ]

        self.make_debug_pkgs = \
            kwargs.get("debug_pkgs", True)
        self.install_prefix = \
            kwargs.get("install_prefix", "/usr")
        self.host_type = \
            kwargs.get("host_type", Platform.target_type())

        self.relations = {}

        for dep_type in ["requires", "provides", "conflicts", "replaces"]:
            dep_node = bin_node.find(dep_type)

            if dep_node is None:
                continue

            for pkg_node in dep_node.findall(".//package"):
                dep_version = pkg_node.get("version", "").strip()
                dep_name = pkg_node.get("name").strip()

                if dep_version.endswith("=="):
                    is_own_package = False

                    if dep_type == "provides":
                        is_own_package = True

                    for tmp_node in bin_node.getparent().iterfind("package"):
                        if tmp_node.get("name") == dep_name:
                            is_own_package = True
                            break
                    #end for

                    if is_own_package:
                        pkg_node.attrib["version"] = dep_version[:-1] \
                            + " " + self.version
                    else:
                        pkg_manager = PackageManager.instance()
                        tmp_version = pkg_manager\
                                .installed_version_of_package(dep_name)
                        if not tmp_version:
                            raise UnmetDependency(
                                "cannot resolve dependency '%s'." % dep_name)
                        pkg_node.attrib["version"] = dep_version[:-1] \
                            + " " + tmp_version
                    #end if
                #end if

                pkg_prefix = pkg_node.get(actual_build_for + "-prefix", None)

                if pkg_prefix is None:
                    if self.architecture == "tools":
                        pkg_prefix = "tools-"
                if pkg_prefix is not None:
                    pkg_node.attrib["name"] = pkg_prefix + \
                            pkg_node.attrib["name"]

                # This is the XML attribute.
                supported_on = pkg_node.get("supported-on")
                if supported_on:
                    supported_on = [v.strip() for v in supported_on.split(",")]

                # Mark nodes which are not supported on machine.
                if not BasePackage._is_supported_on(supported_on, machine):
                    pkg_node.attrib["ignore"] = "true"
            #end for

            self.relations[dep_type] = BasePackage.DependencySpecification\
                    .from_xml(dep_node)
        #end for

        self.contents = {}
        self.content_spec = {}
        prefix_regex = re.compile("^" + re.escape("${prefix}"))

        for node in bin_node.findall('contents/*'):
            src = prefix_regex.sub(self.install_prefix,
                                   node.get("src").strip())

            if len(src) > 1:
                src = src.rstrip(os.sep)

            # '<file>' nodes have precedence over '<dir>'
            entry = self.content_spec.get(src)
            if entry and entry.deftype == "file" and node.tag == "dir":
                continue

            self.content_spec[src] = BinaryPackage.EntryAttributes({
                "deftype":
                node.tag,
                "mode":
                node.get("mode"),
                "owner":
                node.get("owner"),
                "group":
                node.get("group"),
                "conffile":
                node.get("conffile")
            })
        #end for

        self.maintainer_scripts = {}
        for node in bin_node.findall("maintainer-scripts/*"):
            if node.tag in ["preinst", "postinst", "prerm", "postrm"]:
                self.maintainer_scripts[node.tag] = textwrap.dedent(
                    """\
                    #!/bin/sh -e

                    export BOLT_INSTALL_PREFIX="%s"
                    export BOLT_HOST_TYPE="%s"
                    export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin"

                    if [ -d "/tools" ]; then
                        export PATH="/tools/sbin:/tools/bin:$PATH"
                    fi

                    """ % (self.install_prefix, self.host_type)  # noqa
                ) + etree.tostring(node, method="text", encoding="unicode")
            #end if
        #end for

        content_node = bin_node.find("contents")
        if content_node is not None:
            self.content_subdir = content_node.get("subdir")
            if content_node.get("collect-py-cache-files", "false")\
                    .lower() == "true":
                self.collect_py_cache_files = True
            else:
                self.collect_py_cache_files = False
            #end if
        else:
            self.content_subdir = ""
            self.collect_py_cache_files = False
        #end function

        self.basedir = os.path.realpath(".")
        self.output_dir = "."
Ejemplo n.º 6
0
 def is_fulfilled(self):
     package_manager = PackageManager.instance()
     return package_manager\
             .installed_version_meets_condition(self.name, self.version)