diff options
author | Sebastian Luther <SebastianLuther@gmx.de> | 2010-08-24 10:26:54 +0200 |
---|---|---|
committer | Zac Medico <zmedico@gentoo.org> | 2010-08-24 06:13:39 -0700 |
commit | ee6bf1af1ed111602cbe8a8fd4b9b8d5ab47f32f (patch) | |
tree | 78f905f8f0af5359802ebec20c2d58d19fe235c5 /pym/portage | |
parent | ddf9076d05b3ca787e209c1dd996d0d11c41290b (diff) | |
download | portage-ee6bf1af1ed111602cbe8a8fd4b9b8d5ab47f32f.tar.gz portage-ee6bf1af1ed111602cbe8a8fd4b9b8d5ab47f32f.tar.bz2 portage-ee6bf1af1ed111602cbe8a8fd4b9b8d5ab47f32f.zip |
config: Move features_set into its own file
Diffstat (limited to 'pym/portage')
-rw-r--r-- | pym/portage/package/ebuild/_config/features_set.py | 69 | ||||
-rw-r--r-- | pym/portage/package/ebuild/config.py | 66 |
2 files changed, 72 insertions, 63 deletions
diff --git a/pym/portage/package/ebuild/_config/features_set.py b/pym/portage/package/ebuild/_config/features_set.py new file mode 100644 index 000000000..e53c2027e --- /dev/null +++ b/pym/portage/package/ebuild/_config/features_set.py @@ -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() diff --git a/pym/portage/package/ebuild/config.py b/pym/portage/package/ebuild/config.py index 315166659..ffff8c029 100644 --- a/pym/portage/package/ebuild/config.py +++ b/pym/portage/package/ebuild/config.py @@ -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() |