Beispiel #1
0
    def find_best(self, include_keyworded=True, include_masked=True):
        """Returns the "best" version available.

        Order of preference:
                highest available stable =>
                highest available keyworded =>
                highest available masked

        @rtype: Package object or None
        @return: best of up to three options
        @raise errors.GentoolkitInvalidAtom: if query is not valid input
        """

        best = keyworded = masked = None
        try:
            best = portage.db[portage.root]["porttree"].dbapi.xmatch(
                "bestmatch-visible", self.query)
        except portage.exception.InvalidAtom as err:
            message = ("query.py: find_best(), bestmatch-visible, " +
                       "query=%s, InvalidAtom=%s" % (self.query, str(err)))
            raise errors.GentoolkitInvalidAtom(message)
        # xmatch can return an empty string, so checking for None is not enough
        if not best:
            if not (include_keyworded or include_masked):
                return None
            try:
                matches = portage.db[portage.root]["porttree"].dbapi.xmatch(
                    "match-all", self.query)
            except portage.exception.InvalidAtom as err:
                message = (
                    "query.py: find_best(), match-all, query=%s, InvalidAtom=%s"
                    % (self.query, str(err)))
                raise errors.GentoolkitInvalidAtom(message)
            masked = portage.best(matches)
            keywordable = []
            for m in matches:
                status = portage.getmaskingstatus(m)
                if "package.mask" not in status or "profile" not in status:
                    keywordable.append(m)
                if matches:
                    keyworded = portage.best(keywordable)
        else:
            return Package(best)
        if include_keyworded and keyworded:
            return Package(keyworded)
        if include_masked and masked:
            return Package(masked)
        return None
Beispiel #2
0
    def find(self, in_installed=True, include_masked=True):
        """Returns a list of Package objects that matched the query.

		@rtype: list
		@return: matching Package objects
		"""

        if not self.query:
            return []

        try:
            if include_masked:
                matches = portage.db[portage.root]["porttree"].dbapi.xmatch(
                    "match-all", self.query)
            else:
                matches = portage.db[portage.root]["porttree"].dbapi.match(
                    self.query)
            if in_installed:
                matches.extend(portage.db[portage.root]["vartree"].dbapi.match(
                    self.query))
        except portage.exception.InvalidAtom as err:
            message = "query.py: find(), query=%s, InvalidAtom=%s" % (
                self.query, str(err))
            raise errors.GentoolkitInvalidAtom(message)

        return [Package(x) for x in set(matches)]
Beispiel #3
0
    def find_installed(self):
        """Return a list of Package objects that matched the search key."""

        try:
            matches = portage.db[portage.root]["vartree"].dbapi.match(
                self.query)
        # catch the ambiguous package Exception
        except portage.exception.AmbiguousPackageName as err:
            matches = []
            for pkgkey in err.args[0]:
                matches.extend(
                    portage.db[portage.root]["vartree"].dbapi.match(pkgkey))
        except portage.exception.InvalidAtom as err:
            raise errors.GentoolkitInvalidAtom(err)

        return [Package(x) for x in set(matches)]
Beispiel #4
0
    def __init__(self, atom):
        self.atom = atom
        self.operator = self.blocker = self.use = self.slot = None

        try:
            portage.dep.Atom.__init__(self, atom)
        except portage.exception.InvalidAtom:
            raise errors.GentoolkitInvalidAtom(atom)

        # Make operator compatible with intersects
        if self.operator is None:
            self.operator = ''

        CPV.__init__(self, self.cpv)

        # use_conditional is USE flag condition for this Atom to be required:
        # For: !build? ( >=sys-apps/sed-4.0.5 ), use_conditional = '!build'
        self.use_conditional = None
Beispiel #5
0
    def _parser(self, deps, use_conditional=None, depth=0):
        """?DEPEND file parser.

		@rtype: list
		@return: L{gentoolkit.atom.Atom} objects
		"""
        result = []

        if depth == 0:
            deps = paren_reduce(deps)
        for tok in deps:
            if tok == '||':
                continue
            if tok[-1] == '?':
                use_conditional = tok[:-1]
                continue
            if isinstance(tok, list):
                sub_r = self._parser(tok, use_conditional, depth=depth + 1)
                result.extend(sub_r)
                use_conditional = None
                continue
            # FIXME: This is a quick fix for bug #299260.
            #        A better fix is to not discard blockers in the parser,
            #        but to check for atom.blocker in whatever equery/depends
            #        (in this case) and ignore them there.
            # TODO: Test to see how much a performance impact ignoring
            #       blockers here rather than checking for atom.blocker has.
            if tok[0] == '!':
                # We're not interested in blockers
                continue
            # skip it if it's empty
            if tok and tok != '':
                atom = Atom(tok)
                if use_conditional is not None:
                    atom.use_conditional = use_conditional
                result.append(atom)
            else:
                message = "dependencies.py: _parser() found an empty " +\
                 "dep string token for: %s, deps= %s"
                raise errors.GentoolkitInvalidAtom(message % (self.cpv, deps))

        return result