95 # the namespace of objects represented by a particular action. For |
95 # the namespace of objects represented by a particular action. For |
96 # instance, a file's key_attr would be its pathname. Or a driver's |
96 # instance, a file's key_attr would be its pathname. Or a driver's |
97 # key_attr would be the driver name. When 'key_attr' is None, it means |
97 # key_attr would be the driver name. When 'key_attr' is None, it means |
98 # that all attributes of the action are distinguishing. |
98 # that all attributes of the action are distinguishing. |
99 key_attr = None |
99 key_attr = None |
|
100 # 'key_attr_opt' indicates if the 'key_attr' attribute is optional. |
|
101 key_attr_opt = False |
100 # 'globally_identical' is True if all actions representing a single |
102 # 'globally_identical' is True if all actions representing a single |
101 # object on a system must be identical. |
103 # object on a system must be identical. |
102 globally_identical = False |
104 globally_identical = False |
103 # 'refcountable' is True if the action type can safely be delivered |
105 # 'refcountable' is True if the action type can safely be delivered |
104 # multiple times. |
106 # multiple times. |
150 self.orderdict.update(dict(( |
152 self.orderdict.update(dict(( |
151 (pkg.actions.types[t], i) for i, t in enumerate(ol) |
153 (pkg.actions.types[t], i) for i, t in enumerate(ol) |
152 ))) |
154 ))) |
153 self.__class__.unknown = \ |
155 self.__class__.unknown = \ |
154 self.orderdict[pkg.actions.types["unknown"]] |
156 self.orderdict[pkg.actions.types["unknown"]] |
|
157 |
|
158 def __getstate__(self): |
|
159 """This object doesn't have a default __dict__, instead it |
|
160 stores its contents via __slots__. Hence, this routine must |
|
161 be provide to translate this object's contents into a |
|
162 dictionary for pickling""" |
|
163 |
|
164 state = {} |
|
165 for name in Action.__slots__: |
|
166 if not hasattr(self, name): |
|
167 continue |
|
168 state[name] = getattr(self, name) |
|
169 return state |
|
170 |
|
171 def __setstate__(self, state): |
|
172 """This object doesn't have a default __dict__, instead it |
|
173 stores its contents via __slots__. Hence, this routine must |
|
174 be provide to translate a pickled dictionary copy of this |
|
175 object's contents into a real in-memory object.""" |
|
176 |
|
177 for name in state: |
|
178 setattr(self, name, state[name]) |
155 |
179 |
156 def __init__(self, data=None, **attrs): |
180 def __init__(self, data=None, **attrs): |
157 """Action constructor. |
181 """Action constructor. |
158 |
182 |
159 The optional 'data' argument may be either a string, a file-like |
183 The optional 'data' argument may be either a string, a file-like |
486 key_attr. So, the distinguished name might be |
510 key_attr. So, the distinguished name might be |
487 "path: usr/lib/libc.so.1". |
511 "path: usr/lib/libc.so.1". |
488 """ |
512 """ |
489 |
513 |
490 if self.key_attr is None: |
514 if self.key_attr is None: |
|
515 return str(self) |
|
516 if self.key_attr_opt and self.key_attr not in self.attrs: |
491 return str(self) |
517 return str(self) |
492 return "%s: %s" % \ |
518 return "%s: %s" % \ |
493 (self.name, self.attrs.get(self.key_attr, "???")) |
519 (self.name, self.attrs.get(self.key_attr, "???")) |
494 |
520 |
495 def makedirs(self, path, **kw): |
521 def makedirs(self, path, **kw): |