config: Move features_set into its own file
authorSebastian Luther <SebastianLuther@gmx.de>
Tue, 24 Aug 2010 08:26:54 +0000 (10:26 +0200)
committerZac Medico <zmedico@gentoo.org>
Tue, 24 Aug 2010 13:13:39 +0000 (06:13 -0700)
pym/portage/package/ebuild/_config/features_set.py [new file with mode: 0644]
pym/portage/package/ebuild/config.py

diff --git a/pym/portage/package/ebuild/_config/features_set.py b/pym/portage/package/ebuild/_config/features_set.py
new file mode 100644 (file)
index 0000000..e53c202
--- /dev/null
@@ -0,0 +1,69 @@
+# Copyright 2010 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+__all__ = (
+       'features_set',
+)
+
+from portage.dep import best_match_to_list
+
+class features_set(object):
+       """
+       Provides relevant set operations needed for access and modification of
+       config.features. The FEATURES variable is automatically synchronized
+       upon modification.
+
+       Modifications result in a permanent override that will cause the change
+       to propagate to the incremental stacking mechanism in config.regenerate().
+       This eliminates the need to call config.backup_changes() when FEATURES
+       is modified, since any overrides are guaranteed to persist despite calls
+       to config.reset().
+       """
+
+       def __init__(self, settings):
+               self._settings = settings
+               self._features = set()
+
+       def __contains__(self, k):
+               return k in self._features
+
+       def __iter__(self):
+               return iter(self._features)
+
+       def _sync_env_var(self):
+               self._settings['FEATURES'] = ' '.join(sorted(self._features))
+
+       def add(self, k):
+               self._settings.modifying()
+               self._settings._features_overrides.append(k)
+               if k not in self._features:
+                       self._features.add(k)
+                       self._sync_env_var()
+
+       def update(self, values):
+               self._settings.modifying()
+               values = list(values)
+               self._settings._features_overrides.extend(values)
+               need_sync = False
+               for k in values:
+                       if k in self._features:
+                               continue
+                       self._features.add(k)
+                       need_sync = True
+               if need_sync:
+                       self._sync_env_var()
+
+       def remove(self, k):
+               """
+               This never raises KeyError, since it records a permanent override
+               that will prevent the given flag from ever being added again by
+               incremental stacking in config.regenerate().
+               """
+               self.discard(k)
+
+       def discard(self, k):
+               self._settings.modifying()
+               self._settings._features_overrides.append('-' + k)
+               if k in self._features:
+                       self._features.remove(k)
+                       self._sync_env_var()
index 31516665918de8896e10603b26bb51b1c4eb1d08..ffff8c02968f7c8c2ed77205e7465119203619b6 100644 (file)
@@ -47,6 +47,7 @@ from portage.util import ensure_dirs, getconfig, grabdict, \
        writemsg, writemsg_level
 from portage.versions import catpkgsplit, catsplit, cpv_getkey
 
+from portage.package.ebuild._config.features_set import features_set
 from portage.package.ebuild._config.LicenseManager import LicenseManager
 from portage.package.ebuild._config.helper import ordered_by_atom_specificity
 
@@ -98,67 +99,6 @@ def best_from_dict(key, top_dict, key_order, EmptyOnError=1, FullCopy=1, AllowEm
        else:
                raise KeyError("Key not found in list; '%s'" % key)
 
-class _features_set(object):
-       """
-       Provides relevant set operations needed for access and modification of
-       config.features. The FEATURES variable is automatically synchronized
-       upon modification.
-
-       Modifications result in a permanent override that will cause the change
-       to propagate to the incremental stacking mechanism in config.regenerate().
-       This eliminates the need to call config.backup_changes() when FEATURES
-       is modified, since any overrides are guaranteed to persist despite calls
-       to config.reset().
-       """
-
-       def __init__(self, settings):
-               self._settings = settings
-               self._features = set()
-
-       def __contains__(self, k):
-               return k in self._features
-
-       def __iter__(self):
-               return iter(self._features)
-
-       def _sync_env_var(self):
-               self._settings['FEATURES'] = ' '.join(sorted(self._features))
-
-       def add(self, k):
-               self._settings.modifying()
-               self._settings._features_overrides.append(k)
-               if k not in self._features:
-                       self._features.add(k)
-                       self._sync_env_var()
-
-       def update(self, values):
-               self._settings.modifying()
-               values = list(values)
-               self._settings._features_overrides.extend(values)
-               need_sync = False
-               for k in values:
-                       if k in self._features:
-                               continue
-                       self._features.add(k)
-                       need_sync = True
-               if need_sync:
-                       self._sync_env_var()
-
-       def remove(self, k):
-               """
-               This never raises KeyError, since it records a permanent override
-               that will prevent the given flag from ever being added again by
-               incremental stacking in config.regenerate().
-               """
-               self.discard(k)
-
-       def discard(self, k):
-               self._settings.modifying()
-               self._settings._features_overrides.append('-' + k)
-               if k in self._features:
-                       self._features.remove(k)
-                       self._sync_env_var()
-
 def _lazy_iuse_regex(iuse_implicit):
        """
        The PORTAGE_IUSE value is lazily evaluated since re.escape() is slow
@@ -514,7 +454,7 @@ class config(object):
                        self.punmaskdict = copy.deepcopy(clone.punmaskdict)
                        self.prevmaskdict = copy.deepcopy(clone.prevmaskdict)
                        self.pprovideddict = copy.deepcopy(clone.pprovideddict)
-                       self.features = _features_set(self)
+                       self.features = features_set(self)
                        self.features._features = copy.deepcopy(clone.features._features)
                        self._features_overrides = copy.deepcopy(clone._features_overrides)
 
@@ -2457,7 +2397,7 @@ class config(object):
                if hasattr(self, "features"):
                        self.features._features.clear()
                else:
-                       self.features = _features_set(self)
+                       self.features = features_set(self)
                self.features._features.update(self.get('FEATURES', '').split())
                self.features._sync_env_var()