From: Zac Medico Date: Sat, 2 Aug 2008 01:27:52 +0000 (-0000) Subject: Add a new RestrictSet which contains all packages that match specified X-Git-Tag: v2.2_rc7~61 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=f9871b71c8f8558a538effd0438ed3f5fced6768;p=portage.git Add a new RestrictSet which contains all packages that match specified RESTRICT values. This could be useful for implementing something like a @live-rebuild based on RESTRICT metadata, as suggested in bug #233589. svn path=/main/trunk/; revision=11317 --- diff --git a/doc/config/sets.docbook b/doc/config/sets.docbook index 7cccbbc93..3039aec7f 100644 --- a/doc/config/sets.docbook +++ b/doc/config/sets.docbook @@ -479,6 +479,24 @@ + + portage.sets.dbapi.RestrictSet + + Package set which contains all packages + that match specified RESTRICT values. + This class supports the following options: + + includes: A list of + values that must be contained within the RESTRICT + metadata. + + excludes: A list of + values that must not be contained within the RESTRICT + metadata. + + + + portage.sets.dbapi.DowngradeSet diff --git a/pym/portage/sets/dbapi.py b/pym/portage/sets/dbapi.py index 8c3eb43ac..c4ac95498 100644 --- a/pym/portage/sets/dbapi.py +++ b/pym/portage/sets/dbapi.py @@ -3,30 +3,50 @@ # $Id$ from portage.versions import catpkgsplit, catsplit, pkgcmp +from portage.dep import Atom from portage.sets.base import PackageSet from portage.sets import SetConfigError, get_boolean __all__ = ["CategorySet", "DowngradeSet", - "EverythingSet", "InheritSet", "OwnerSet"] + "EverythingSet", "InheritSet", "OwnerSet", "RestrictSet"] class EverythingSet(PackageSet): _operations = ["merge", "unmerge"] description = "Package set which contains SLOT " + \ "atoms to match all installed packages" + _filter = None def __init__(self, vdbapi): super(EverythingSet, self).__init__() self._db = vdbapi - + def load(self): myatoms = [] + db_keys = ["SLOT"] + aux_get = self._db.aux_get + cp_list = self._db.cp_list + for cp in self._db.cp_all(): - if len(self._db.cp_list(cp)) > 1: - for cpv in self._db.cp_list(cp): - myslot = self._db.aux_get(cpv, ["SLOT"])[0] - myatoms.append(cp+":"+myslot) + cpv_list = cp_list(cp) + + if len(cpv_list) > 1: + for cpv in cpv_list: + slot, = aux_get(cpv, db_keys) + atom = Atom("%s:%s" % (cp, slot)) + if self._filter: + if self._filter(atom): + myatoms.append(atom) + else: + myatoms.append(atom) + else: - myatoms.append(cp) + atom = Atom(cp) + if self._filter: + if self._filter(atom): + myatoms.append(atom) + else: + myatoms.append(atom) + self._setAtoms(myatoms) def singleBuilder(self, options, settings, trees): @@ -116,6 +136,46 @@ class InheritSet(PackageSet): singleBuilder = classmethod(singleBuilder) +class RestrictSet(EverythingSet): + + _operations = ["merge", "unmerge"] + + description = "Package set which contains all packages " + \ + "that match specified RESTRICT values." + + def __init__(self, vardb, portdb=None, includes=None, excludes=None): + super(RestrictSet, self).__init__(vardb) + self._portdb = portdb + self._includes = includes + self._excludes = excludes + + def _filter(self, atom): + ebuild = self._portdb.xmatch("bestmatch-visible", atom) + if not ebuild: + return False + restrict, = self._portdb.aux_get(ebuild, ["RESTRICT"]) + restrict = restrict.split() + if self._includes and not self._includes.intersection(restrict): + return False + if self._excludes and self._excludes.intersection(restrict): + return False + return True + + def singleBuilder(cls, options, settings, trees): + + includes = options.get("includes", "") + excludes = options.get("excludes", "") + + if not (includes or excludes): + raise SetConfigError("no includes or excludes given") + + return cls(trees["vartree"].dbapi, + portdb=trees["porttree"].dbapi, + excludes=frozenset(excludes.split()), + includes=frozenset(includes.split())) + + singleBuilder = classmethod(singleBuilder) + class DowngradeSet(PackageSet): _operations = ["merge", "unmerge"]