1 |
Author: zmedico |
2 |
Date: 2008-04-22 23:40:34 +0000 (Tue, 22 Apr 2008) |
3 |
New Revision: 9945 |
4 |
|
5 |
Modified: |
6 |
main/trunk/pym/_emerge/__init__.py |
7 |
Log: |
8 |
Bug #172812 - Add an Uninstall class derived from the Package class, for |
9 |
packages that may need to be uninstalled to avoid conflicts. |
10 |
|
11 |
|
12 |
Modified: main/trunk/pym/_emerge/__init__.py |
13 |
=================================================================== |
14 |
--- main/trunk/pym/_emerge/__init__.py 2008-04-22 18:30:54 UTC (rev 9944) |
15 |
+++ main/trunk/pym/_emerge/__init__.py 2008-04-22 23:40:34 UTC (rev 9945) |
16 |
@@ -1201,10 +1201,9 @@ |
17 |
shown_licenses.add(l) |
18 |
return have_eapi_mask |
19 |
|
20 |
-class Package(object): |
21 |
- __slots__ = ("__weakref__", "built", "cpv", "depth", |
22 |
- "installed", "metadata", "root", "onlydeps", "type_name", |
23 |
- "cp", "cpv_slot", "slot_atom", "_digraph_node") |
24 |
+class Task(object): |
25 |
+ __slots__ = ("__weakref__", "_hash_key",) |
26 |
+ |
27 |
def __init__(self, **kwargs): |
28 |
for myattr in self.__slots__: |
29 |
if myattr == "__weakref__": |
30 |
@@ -1212,14 +1211,56 @@ |
31 |
myvalue = kwargs.get(myattr, None) |
32 |
setattr(self, myattr, myvalue) |
33 |
|
34 |
+ def _get_hash_key(self): |
35 |
+ try: |
36 |
+ return self._hash_key |
37 |
+ except AttributeError: |
38 |
+ raise NotImplementedError(self) |
39 |
+ |
40 |
+ def __eq__(self, other): |
41 |
+ return self._get_hash_key() == other |
42 |
+ |
43 |
+ def __ne__(self, other): |
44 |
+ return self._get_hash_key() != other |
45 |
+ |
46 |
+ def __hash__(self): |
47 |
+ return hash(self._get_hash_key()) |
48 |
+ |
49 |
+ def __len__(self): |
50 |
+ return len(self._get_hash_key()) |
51 |
+ |
52 |
+ def __getitem__(self, key): |
53 |
+ return self._get_hash_key()[key] |
54 |
+ |
55 |
+ def __iter__(self): |
56 |
+ return iter(self._get_hash_key()) |
57 |
+ |
58 |
+ def __contains__(self, key): |
59 |
+ return key in self._get_hash_key() |
60 |
+ |
61 |
+ def __str__(self): |
62 |
+ return str(self._get_hash_key()) |
63 |
+ |
64 |
+class Package(Task): |
65 |
+ __slots__ = ("built", "cpv", "depth", |
66 |
+ "installed", "metadata", "root", "onlydeps", "type_name", |
67 |
+ "cp", "cpv_slot", "slot_atom") |
68 |
+ def __init__(self, **kwargs): |
69 |
+ Task.__init__(self, **kwargs) |
70 |
self.cp = portage.cpv_getkey(self.cpv) |
71 |
self.slot_atom = "%s:%s" % (self.cp, self.metadata["SLOT"]) |
72 |
self.cpv_slot = "%s:%s" % (self.cpv, self.metadata["SLOT"]) |
73 |
|
74 |
- status = "merge" |
75 |
- if self.onlydeps or self.installed: |
76 |
- status = "nomerge" |
77 |
- self._digraph_node = (self.type_name, self.root, self.cpv, status) |
78 |
+ def _get_hash_key(self): |
79 |
+ try: |
80 |
+ return self._hash_key |
81 |
+ except AttributeError: |
82 |
+ operation = "merge" |
83 |
+ if self.onlydeps or self.installed: |
84 |
+ operation = "nomerge" |
85 |
+ self._hash_key = \ |
86 |
+ (self.type_name, self.root, self.cpv, operation) |
87 |
+ return self._hash_key |
88 |
|
89 |
def __lt__(self, other): |
90 |
other_split = portage.catpkgsplit(other.cpv) |
91 |
@@ -1239,22 +1280,14 @@ |
92 |
return True |
93 |
return False |
94 |
|
95 |
- def __eq__(self, other): |
96 |
- return self._digraph_node == other |
97 |
- def __ne__(self, other): |
98 |
- return self._digraph_node != other |
99 |
- def __hash__(self): |
100 |
- return hash(self._digraph_node) |
101 |
- def __len__(self): |
102 |
- return len(self._digraph_node) |
103 |
- def __getitem__(self, key): |
104 |
- return self._digraph_node[key] |
105 |
- def __iter__(self): |
106 |
- return iter(self._digraph_node) |
107 |
- def __contains__(self, key): |
108 |
- return key in self._digraph_node |
109 |
- def __str__(self): |
110 |
- return str(self._digraph_node) |
111 |
+class Uninstall(Package): |
112 |
+ def _get_hash_key(self): |
113 |
+ try: |
114 |
+ return self._hash_key |
115 |
+ except AttributeError: |
116 |
+ self._hash_key = \ |
117 |
+ (self.type_name, self.root, self.cpv, "unmerge") |
118 |
+ return self._hash_key |
119 |
|
120 |
class DependencyArg(object): |
121 |
def __init__(self, arg=None, root_config=None): |
122 |
|
123 |
-- |
124 |
gentoo-commits@l.g.o mailing list |