blob: 7ab148fc8162361e1f999e9c91b3509edf6a178f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
# Copyright 2010 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
__all__ = (
'features_set',
)
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()
|