Add a more generic VariableSet to replace the InheritSet and RestrictSet
authorZac Medico <zmedico@gentoo.org>
Sun, 3 Aug 2008 05:51:33 +0000 (05:51 -0000)
committerZac Medico <zmedico@gentoo.org>
Sun, 3 Aug 2008 05:51:33 +0000 (05:51 -0000)
classes. Thanks to Arfrever Frehtes Taifersar Arahesis for this patch from
bug #233589 (with some minor adjustments from me).

svn path=/main/trunk/; revision=11320

cnf/sets.conf
doc/config/sets.docbook
pym/portage/sets/dbapi.py

index b0e331b00eb75cb5ff4524b53de139bf15e7e24c..0825f70a19957df560e7d84ebcbd97a9e832b690 100644 (file)
@@ -47,9 +47,10 @@ world-candidate = False
 
 # Installed ebuilds that inherit from known live eclasses.
 [live-rebuild]
-class = portage.sets.dbapi.InheritSet
+class = portage.sets.dbapi.VariableSet
 world-candidate = False
-inherits = cvs darcs git mercurial subversion
+variable = INHERITED
+includes = cvs darcs git mercurial subversion
 
 # Installed packages that own files inside /lib/modules.
 [module-rebuild]
index 052ace0d459b0ef529aa754b9e47059c3b03537b..14e171fb2819242d902ae20c9b77d6ff9823d675 100644 (file)
                        </para>
                        </sect3>
                </sect2>
-               <sect2 id='config-set-classes-InheritSet'>
-               <title>portage.sets.dbapi.InheritSet</title>
-               <para>
-               Package set which contains all packages
-               that inherit one or more specific eclasses.
-               This class supports the following options:
-               <itemizedlist>
-               <listitem><varname>inherits</varname>: Required. A list of eclass names
-               which should be used to create the package set.
-               </listitem>
-               </itemizedlist>
-               </para>
-               </sect2>
                <sect2 id='config-set-classes-OwnerSet'>
                <title>portage.sets.dbapi.OwnerSet</title>
                <para>
                </itemizedlist>
                </para>
                </sect2>
-               <sect2 id='config-set-classes-RestrictSet'>
-               <title>portage.sets.dbapi.RestrictSet</title>
+               <sect2 id='config-set-classes-VariableSet'>
+               <title>portage.sets.dbapi.VariableSet</title>
                <para>
                Package set which contains all packages
-               that match specified RESTRICT values.
+               that match specified values of specified variable.
                This class supports the following options:
                <itemizedlist>
+               <listitem><varname>variable</varname>: The name of
+               the specified variable whose values are checked.
+               </listitem>
                <listitem><varname>includes</varname>: A list of
-               values that must be contained within the RESTRICT
-               metadata.
+               values that must be contained within the specified
+               variable.
                </listitem>
                <listitem><varname>excludes</varname>: A list of
-               values that must not be contained within the RESTRICT
-               metadata.
+               values that must not be contained within the specified
+               variable.
                </listitem>
                </itemizedlist>
                </para>
        <listitem><varname>security</varname>: uses <classname>NewAffectedSet</classname> with default options</listitem>
        <listitem><varname>everything</varname>: uses <classname>EverythingSet</classname></listitem>
        <listitem><varname>preserved-rebuild</varname>: uses <classname>PreservedLibraryConsumerSet</classname></listitem>
-       <listitem><varname>live-rebuild</varname>: uses <classname>InheritSet</classname></listitem>
+       <listitem><varname>live-rebuild</varname>: uses <classname>VariableSet</classname></listitem>
        <listitem><varname>module-rebuild</varname>: uses <classname>OwnerSet</classname></listitem>
        <listitem><varname>downgrade</varname>: uses <classname>DowngradeSet</classname></listitem>
        </itemizedlist>
index c4ac95498df25a5e824d4c82e1b4aae94b5c5c19..2ddefb8618ab073034cb1b988bccb7af419b7711 100644 (file)
@@ -8,7 +8,7 @@ from portage.sets.base import PackageSet
 from portage.sets import SetConfigError, get_boolean
 
 __all__ = ["CategorySet", "DowngradeSet",
-       "EverythingSet", "InheritSet", "OwnerSet", "RestrictSet"]
+       "EverythingSet", "OwnerSet", "VariableSet"]
 
 class EverythingSet(PackageSet):
        _operations = ["merge", "unmerge"]
@@ -89,63 +89,17 @@ class OwnerSet(PackageSet):
 
        singleBuilder = classmethod(singleBuilder)
 
-class InheritSet(PackageSet):
+class VariableSet(EverythingSet):
 
        _operations = ["merge", "unmerge"]
 
        description = "Package set which contains all packages " + \
-               "that inherit one or more specific eclasses."
+               "that match specified values of a specified variable."
 
-       def __init__(self, portdb=None, vardb=None, inherits=None):
-               super(InheritSet, self).__init__()
-               self._portdb = portdb
-               self._db = vardb
-               self._inherits = inherits
-
-       def load(self):
-               atoms = []
-               inherits = self._inherits
-               xmatch = self._portdb.xmatch
-               xmatch_level = "bestmatch-visible"
-               cp_list = self._db.cp_list
-               aux_get = self._db.aux_get
-               portdb_aux_get = self._portdb.aux_get
-               vardb_keys = ["SLOT"]
-               portdb_keys = ["INHERITED"]
-               for cp in self._db.cp_all():
-                       for cpv in cp_list(cp):
-                               slot, = aux_get(cpv, vardb_keys)
-                               slot_atom = "%s:%s" % (cp, slot)
-                               ebuild = xmatch(xmatch_level, slot_atom)
-                               if not ebuild:
-                                       continue
-                               inherited, = portdb_aux_get(ebuild, portdb_keys)
-                               if inherits.intersection(inherited.split()):
-                                       atoms.append(slot_atom)
-
-               self._setAtoms(atoms)
-
-       def singleBuilder(cls, options, settings, trees):
-               if not "inherits" in options:
-                       raise SetConfigError("no inherits given")
-
-               inherits = options["inherits"]
-               return cls(portdb=trees["porttree"].dbapi,
-                       vardb=trees["vartree"].dbapi,
-                       inherits=frozenset(inherits.split()))
-
-       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)
+       def __init__(self, vardb, portdb=None, variable=None, includes=None, excludes=None):
+               super(VariableSet, self).__init__(vardb)
                self._portdb = portdb
+               self._variable = variable
                self._includes = includes
                self._excludes = excludes
 
@@ -153,16 +107,20 @@ class RestrictSet(EverythingSet):
                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):
+               values, = self._portdb.aux_get(ebuild, [self._variable])
+               values = values.split()
+               if self._includes and not self._includes.intersection(values):
                        return False
-               if self._excludes and self._excludes.intersection(restrict):
+               if self._excludes and self._excludes.intersection(values):
                        return False
                return True
 
        def singleBuilder(cls, options, settings, trees):
 
+               variable = options.get("variable")
+               if variable is None:
+                       raise SetConfigError("missing required attribute: 'variable'")
+
                includes = options.get("includes", "")
                excludes = options.get("excludes", "")
 
@@ -172,7 +130,8 @@ class RestrictSet(EverythingSet):
                return cls(trees["vartree"].dbapi,
                        portdb=trees["porttree"].dbapi,
                        excludes=frozenset(excludes.split()),
-                       includes=frozenset(includes.split()))
+                       includes=frozenset(includes.split()),
+                       variable=variable)
 
        singleBuilder = classmethod(singleBuilder)