Exemple #1
0
    def select(self):
        preform = self.package.split("/")
        if len(preform) == 3:
            self.repo, self.category, fullname = preform
        elif len(preform) == 2:
            self.category, fullname = preform
        elif len(preform) == 1:
            fullname = self.package

        if cst.slot_indicator in fullname:
            fullname, self.slot = fullname.split(":")

        self.name, self.version = utils.parse_pkgname(fullname)

        packages = self.database.find_package(package_repo=self.repo, package_name=self.name, \
                package_category=self.category, package_version=self.version)

        if not packages:
            raise PackageNotFound(self.package)

        convenient_arches = utils.get_convenient_arches(self.conf.arch)

        try:
            the_package = utils.get_convenient_package(packages, self.locked_packages, \
                    self.custom_arch_request, convenient_arches, self.database, self.slot)
        except UnavailablePackage:
            for package in packages:
                out.error("%s/%s/%s-%s:%s is unavailable for your arch(%s)." % (package.repo, package.category, \
                        package.name, package.version, package.slot, self.conf.arch))
            lpms.terminate()
        except LockedPackage:
            out.error(
                "these package(s) is/are locked by the system administrator:")
            for package in packages:
                out.error_notify("%s/%s/%s-%s:%s" % (package.repo, package.category, \
                        package.name, package.version, package.slot))
            lpms.terminate()

        if the_package is None:
            raise UnavailablePackage(self.package)
        return the_package
Exemple #2
0
    def select(self):
        preform = self.package.split("/")
        if len(preform) == 3:
            self.repo, self.category, fullname = preform
        elif len(preform) == 2:
            self.category, fullname = preform
        elif len(preform) == 1:
            fullname = self.package

        if cst.slot_indicator in fullname:
            fullname, self.slot = fullname.split(":")
        
        self.name, self.version = utils.parse_pkgname(fullname)
        
        packages = self.database.find_package(package_repo=self.repo, package_name=self.name, \
                package_category=self.category, package_version=self.version)
        
        if not packages:
            raise PackageNotFound(self.package)

        convenient_arches = utils.get_convenient_arches(self.conf.arch)

        try:
            the_package = utils.get_convenient_package(packages, self.locked_packages, \
                    self.custom_arch_request, convenient_arches, self.database, self.slot)
        except UnavailablePackage:
            for package in packages:
                out.error("%s/%s/%s-%s:%s is unavailable for your arch(%s)." % (package.repo, package.category, \
                        package.name, package.version, package.slot, self.conf.arch))
            lpms.terminate()
        except LockedPackage:
            out.error("these package(s) is/are locked by the system administrator:")
            for package in packages:
                out.error_notify("%s/%s/%s-%s:%s" % (package.repo, package.category, \
                        package.name, package.version, package.slot))
            lpms.terminate()

        if the_package is None:
            raise UnavailablePackage(self.package)
        return the_package
Exemple #3
0
    def get_convenient_package(self, package, instdb=False):
        def inline_options_management(inline_options):
            # TODO: inline_options variable must be a set
            # Check inline options, if an option is not available for the package, warn the user
            for inline_option in inline_options:
                if not inline_option in package.options:
                    out.warn("%s option is not available for %s/%s/%s-%s. So that the option is removing..." % (
                        inline_option,
                        package.repo,
                        package.category,
                        package.name,
                        package.version
                    ))
                    inline_options.remove(inline_option)

            if inline_options:
                target = self.current_package.id if self.current_package is not \
                        None else self.parent_package.id
                my_package = package.category+"/"+package.name+"/"+package.slot
                if target in self.inline_option_targets:
                    if my_package in self.inline_option_targets[target]:
                        for option in inline_options:
                            self.inline_option_targets[target][my_package].add(option)
                    else:
                        self.inline_option_targets[target][my_package] = set(inline_options)
                else:
                    self.inline_option_targets[target] = {my_package: set(inline_options)}
                
                if package.id in self.inline_options:
                    if not package.id in self.package_options:
                        self.package_options[package.id] = set()
                    for option in inline_options:
                        if not option in self.inline_options[package.id]:
                            self.inline_options[package.id].append(option)
                            if package.id in self.package_options:
                                self.package_options[package.id].add(option)
                else:
                    self.inline_options[package.id] = inline_options
                    if package.id in self.package_options:
                        for inline_option in inline_options:
                            self.package_options[package.id].add(inline_option)
                    else:
                        self.package_options[package.id] = set(inline_options)

        convenient_arches = utils.get_convenient_arches(self.conf.arch)
        current_package = self.parent_package if self.parent_package is not \
                None else self.current_package
        result = LCollect()
        database = self.repodb if instdb is False else self.instdb
        slot = None
        gte, lte, lt, gt, et = False, False, False, False, False
        slot_parsed = package.split(":")

        if len(slot_parsed) == 2:
            data, slot = slot_parsed
        elif len(slot_parsed) > 2:
            out.error("%s invalid dependency in %s.py" % (data, self.current_package))
            # Use and exception
            raise DependencyError
        else:
            data = package

        if ">=" == data[:2]:
            gte = True
            pkgname = data[2:]
        elif "<=" == data[:2]:
            lte = True
            pkgname = data[2:]
        elif "<" == data[:1]:
            lt = True
            pkgname = data[1:]
        elif ">" == data[:1]:
            gt = True
            pkgname = data[1:]
        elif "==" == data[:2]:
            et = True
            pkgname = data[2:]
        else:
            category, name = data.split("/")
            inline_options = self.parse_inline_options(name)
            if inline_options:
                name = name[:name.index("[")]
            if (category, name) in self.repository_cache:
                results = self.repository_cache[(category, name)]
            else:
                results = database.find_package(package_name=name, package_category=category)
                self.repository_cache[(category, name)] = results
            slot = self.get_convenient_slot(results, slot)
            if not results:
                if instdb:
                    return
                current_package = current_package.repo+"/"+current_package.category+\
                        "/"+current_package.name+"-"+current_package.version+":"+current_package.slot
                out.error("unmet dependency: %s depends on %s" % (out.color(current_package, \
                        "red"), out.color(package, "red")))
                raise DependencyError
            try:
                package = utils.get_convenient_package(
                        results, 
                        self.locked_packages,
                        self.custom_arch_requests, 
                        convenient_arches, 
                        self.instdb, 
                        slot
                )
            except UnavailablePackage:
                for result in results:
                    out.error("%s/%s/%s-%s:%s {%s} is unavailable for your arch(%s)." % (result.repo, result.category, \
                            result.name, result.version, result.slot, result.arch, self.conf.arch))
                out.write("\n")
                out.write("%s %s/%s/%s-%s:%s {%s}\n" % (out.color("->", "brightyellow"), current_package.repo, \
                        current_package.category, current_package.name, current_package.version, \
                        current_package.slot, current_package.arch))
                out.write(" %s %s/%s/%s-%s:%s {%s}\n" % (out.color("->", "brightyellow"), current_package.repo, \
                        current_package.category, current_package.name, current_package.version, \
                        current_package.slot, current_package.arch))
                raise DependencyError
            except LockedPackage:
                out.error("these package(s) is/are locked by the system administrator:")
                for result in results:
                    out.error_notify("%s/%s/%s-%s:%s {%s}" % (result.repo, result.category, \
                            result.name, result.version, result.slot, result.arch))
                out.write("\n")
                out.write("%s %s/%s/%s-%s:%s {%s}\n" % (out.color("->", "brightyellow"), current_package.repo, \
                        current_package.category, current_package.name, current_package.version, \
                        current_package.slot, current_package.arch))
                out.write(" %s %s/%s/%s-%s:%s {%s}\n" % (out.color("->", "brightyellow"), current_package.repo, \
                        current_package.category, current_package.name, current_package.version, \
                        current_package.slot, current_package.arch))
                raise DependencyError

            # Set some variables to manage inline options
            inline_options_management(inline_options)

            return package

        category, name = pkgname.split("/")
        inline_options = self.parse_inline_options(name)
        if inline_options:
            name = name[:name.index("[")]
        name, version = utils.parse_pkgname(name)
        if (category, name) in self.repository_cache:
            results = self.repository_cache[(category, name)]
        else:
            results = database.find_package(package_name=name, package_category=category)
            self.repository_cache[(category, name)] = results
        slot = self.get_convenient_slot(results, slot)
        packages = []
        decision_point = {}
        owner_package = current_package.repo+"/"+current_package.category+\
                "/"+current_package.name+"-"+current_package.version
        if gte:
            decision_point = {"type": ">=", "version": version, \
                    "owner_package": owner_package, "owner_id": current_package.id}
            for result in results:
                comparison = utils.vercmp(result.version, version)
                if comparison == 1 or comparison == 0:
                    packages.append(result)
        elif lte:
            decision_point = {"type": "<=", "version": version, \
                    "owner_package": owner_package, "owner_id": current_package.id}
            for result in results:
                comparison = utils.vercmp(result.version, version)
                if comparison == -1 or comparison == 0:
                    packages.append(result)
        elif lt:
            decision_point = {"type": "<", "version": version, \
                    "owner_package": owner_package, "owner_id": current_package.id}
            for result in results:
                comparison = utils.vercmp(result.version, version)
                if comparison == -1:
                    packages.append(result)
        elif gt:
            decision_point = {"type": ">", "version": version, \
                    "owner_package": owner_package, "owner_id": current_package.id}
            for result in results:
                comparison = utils.vercmp(result.version, version)
                if comparison == 1:
                    packages.append(result)
        elif et:
            decision_point = {"type": "==", "version": version, \
                    "owner_package": owner_package, "owner_id": current_package.id}
            for result in results:
                comparison = utils.vercmp(result.version, version)
                if comparison == 0:
                    packages.append(result)

        if not packages:
            out.error("unmet dependency: %s/%s/%s-%s:%s {%s} depends on %s" % \
                    (current_package.repo, \
                    current_package.category, \
                    current_package.name, \
                    current_package.version, \
                    current_package.slot, \
                    current_package.arch, \
                    out.color(package, "red")))
            raise DependencyError

        try:
            package = utils.get_convenient_package(
                    results if not packages else packages,
                    self.locked_packages,
                    self.custom_arch_requests,
                    convenient_arches,
                    self.instdb,
                    slot
                    )
        except UnavailablePackage:
            for result in results:
                out.error("%s/%s/%s-%s:%s {%s}is unavailable for your arch(%s)." % (result.repo, result.category, \
                        result.name, result.version, result.slot, result.arch, self.conf.arch))
            out.write("\n")
            out.write("%s %s/%s/%s-%s:%s {%s}\n" % (out.color("->", "brightyellow"), current_package.repo, \
                    current_package.category, current_package.name, current_package.version, \
                    current_package.slot, current_package.arch))
            out.write(" %s %s/%s/%s-%s:%s {%s}\n" % (out.color("->", "brightyellow"), current_package.repo, \
                    current_package.category, current_package.name, current_package.version, \
                    current_package.slot, current_package.arch))
            raise DependencyError
        except LockedPackage:
            out.error("these package(s) is/are locked by the system administrator:")
            for result in results:
                out.error_notify("%s/%s/%s-%s:%s {%s}" % (result.repo, result.category, \
                        result.name, result.version, result.slot, result.arch))
            out.write("\n")
            out.write("%s %s/%s/%s-%s:%s {%s}\n" % (out.color("->", "brightyellow"), current_package.repo, \
                    current_package.category, current_package.name, current_package.version, \
                    current_package.slot, current_package.arch))
            out.write(" %s %s/%s/%s-%s:%s {%s}\n" % (out.color("->", "brightyellow"), current_package.repo, \
                    current_package.category, current_package.name, current_package.version, \
                    current_package.slot, current_package.arch))
            raise DependencyError

        # Set some variables to manage inline options
        inline_options_management(inline_options)

        if package.id in self.conditional_packages:
            self.conditional_packages[package.id].append(decision_point)
        else:
            self.conditional_packages[package.id] = [decision_point]

        return package