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 Provides the build configuration as special dictionaries that directly
37 export their namespaces.
38 """
39
40 import itertools
41
42
43 from conary.deps import arch, deps
44 from conary.lib import log
45 from conary.errors import CvcError
46
48
49 - def __init__(self, name, parent=None, value=False,
50 required=True, track=False, path=None, platform=False):
51 self._name = name
52 self._value = value
53 self._parent = parent
54 self._required = required
55 self._tracking = track
56 self._used = False
57 self._alias = None
58 self._path = path
59 self._platform = platform
60
62 if self._alias:
63 return "%s (alias %s): %s" % (self._name, self._alias, self._value)
64 else:
65 return "%s: %s" % (self._name, self._value)
66
68 if self._alias:
69 return "%s (alias %s): %s" % (self._fullName(), self._alias,
70 self._value)
71 else:
72 return "%s: %s" % (self._fullName(), self._value)
73
75
76 self._shortDoc = doc
77
79 self._required = value
80
83
86
87 - def _set(self, value=True):
89
91 """ Grab value without tracking """
92 return self._value
93
97
99 if self._parent is not None:
100 for parent in self._parent._reverseParents():
101 yield parent
102 yield self._parent
103
112
114 """ Returns an actual Dependency Set consisting of only this flag """
115 raise NotImplementedError
116
119
121 self._tracking = value
122
123
124
125
127 if self._tracking:
128 self._setUsed(True)
129 return self._value
130
133
135 if not isinstance(other, (Flag, bool)):
136 return False
137 return bool(self) == bool(other)
138
140 return not self.__eq__(other)
141
143 return bool(self) | other
144
147
149 return bool(self) & other
150
153
154
155
157
158 - def __init__(self, name, parent=None, track=False):
159 self._name = name
160 self._parent = parent
161 self._strictMode = True
162 self._tracking = track
163 self._attrs = {}
164
165
167 """ Add a second way to access the given item.
168 Necessary if the actual name for a flag is not a valid
169 python identifier.
170 """
171 if alias in self or alias in self._attrs:
172 raise RuntimeError, 'alias is already set'
173 elif self[realKey]._alias:
174 raise RuntimeError, 'key %s already has an alias' % realKey
175 else:
176 self._setAttr(alias, self[realKey])
177 self[realKey]._alias = alias
178
180 """ A generic way to add a temporary attribute to this collection.
181 Attributes stored in this manner will be removed when the
182 collection is cleared, but are not tracked like flags.
183 """
184 self._attrs[name] = value
185
187 del self._attrs[name]
188
190 return self._attrs[name]
191
193 if 'track' not in kw:
194 kw = kw.copy()
195 kw['track'] = self._tracking
196 dict.__setitem__(self, key, self._collectionType(key, self,
197 *args, **kw))
198
200 return "%s: {%s}" % (self._name,
201 ', '.join((repr(x) for x in self.values())))
202
204 raise RuntimeError(
205 'Cannot compare collection as True/False')
206
207
209 for flag in self.keys():
210 del self[flag]
211 for attr in self._attrs.keys():
212 del self._attrs[attr]
213
224
226 if key in self._attrs:
227 return self._attrs[key]
228 else:
229 return dict.__getitem__(self, key)
230
232 if key[0] == '_':
233 self.__dict__[key] = value
234 else:
235 raise RuntimeError, "Cannot set value of flags: %s" % key
236
238 """ Method that is called when a nonexistant key is accessed.
239 Overridden by subclasses to allow for useful error messages
240 or default key values to be supplied """
241 raise AttributeError, key
242
244 for child in self.itervalues():
245 if isinstance(child, Collection):
246 for flag in child._iterAll():
247 yield flag
248 else:
249 yield child
250
252 """ Strict mode determines whether you receive an error or
253 an empty flag upon accessing a nonexistant flag
254 """
255 self._strictMode = value
256
258 """ Traverse through the parents from the topmost parent down. """
259 if self._parent is not None:
260 for parent in self._parent._reverseParents():
261 yield parent
262 yield self._parent
263
264
265
270
274
277
279 for child in self.itervalues():
280 if isinstance(child, Collection):
281 for flag in child._iterUsed():
282 yield flag
283 else:
284 if child._used:
285 yield child
286
287
289 """ CollectionWithFlag. Currently only has one child class, MajorArch. """
290 - def __init__(self, name, parent, track=False):