1 |
commit: 0157fd160bb40c5039308d1947f2b9620e467514 |
2 |
Author: Slava Bacherikov <slava <AT> bacher09 <DOT> org> |
3 |
AuthorDate: Thu Jun 7 22:48:08 2012 +0000 |
4 |
Commit: Slava Bacherikov <slava <AT> bacherikov <DOT> org <DOT> ua> |
5 |
CommitDate: Thu Jun 7 22:48:08 2012 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/gentoo-packages.git;a=commit;h=0157fd16 |
7 |
|
8 |
Add droping repeating keyword in porttree |
9 |
|
10 |
--- |
11 |
gpackages/libs/porttree.py | 42 +++++++++++++++++++++++++++++++++++++++--- |
12 |
1 files changed, 39 insertions(+), 3 deletions(-) |
13 |
|
14 |
diff --git a/gpackages/libs/porttree.py b/gpackages/libs/porttree.py |
15 |
index 3bb6b6b..af7b513 100644 |
16 |
--- a/gpackages/libs/porttree.py |
17 |
+++ b/gpackages/libs/porttree.py |
18 |
@@ -1,3 +1,5 @@ |
19 |
+from functools import total_ordering |
20 |
+from collections import defaultdict |
21 |
import portage |
22 |
from portage.util.listdir import listdir |
23 |
from portage.dep import Atom |
24 |
@@ -74,15 +76,15 @@ class Use(ToStrMixin): |
25 |
return self.name |
26 |
|
27 |
def __eq__(self, other): |
28 |
- self.name == other.name |
29 |
+ return self.name == other.name |
30 |
|
31 |
def __ne__(self, other): |
32 |
- self.name != other.name |
33 |
+ return self.name != other.name |
34 |
|
35 |
def __hash__(self): |
36 |
return hash(self.name) |
37 |
|
38 |
- |
39 |
+@total_ordering |
40 |
class Keyword(ToStrMixin): |
41 |
"Represend ebuild Keyword as object" |
42 |
__slots__ = ('name', 'status') |
43 |
@@ -109,11 +111,42 @@ class Keyword(ToStrMixin): |
44 |
def __unicode__(self): |
45 |
return self.status_repr[self.status] + self.name |
46 |
|
47 |
+ def __hash__(self): |
48 |
+ return hash((self.name, self.status)) |
49 |
+ |
50 |
+ def is_same(self, other): |
51 |
+ return self.name == other.name |
52 |
+ |
53 |
+ def is_higer(self, other): |
54 |
+ return self.status < other.status |
55 |
+ |
56 |
+ def is_lower(self, other): |
57 |
+ return self.status > other.status |
58 |
+ |
59 |
+ def __eq__(self, other): |
60 |
+ return (self.arch, self.status) == (other.arch, other.status) |
61 |
+ |
62 |
+ def __lt__(self, other): |
63 |
+ return (self.status, self.arch) > (other.status, other.arch) |
64 |
+ |
65 |
@property |
66 |
def arch(self): |
67 |
"Return arch name" |
68 |
return self.name |
69 |
|
70 |
+class KeywordsSet(set): |
71 |
+ def __init__(self, init_list): |
72 |
+ start = defaultdict(list) |
73 |
+ for item in init_list: |
74 |
+ start[item.arch].append(item) |
75 |
+ |
76 |
+ to_create = [] |
77 |
+ for item in start.itervalues(): |
78 |
+ item.sort(reverse = True) |
79 |
+ if len(item)>=1: |
80 |
+ to_create.append(item[0]) |
81 |
+ super(KeywordsSet, self).__init__(to_create) |
82 |
+ |
83 |
def _gen_all_use(func, iterator): |
84 |
use_g = iterator |
85 |
use_all_dict = next(use_g) |
86 |
@@ -372,6 +405,9 @@ class Ebuild(ToStrMixin): |
87 |
l.append(keyword) |
88 |
return l |
89 |
|
90 |
+ def get_uniq_keywords(self): |
91 |
+ return KeywordsSet(self.get_keywords) |
92 |
+ |
93 |
def get_uses_names(self): |
94 |
return self.package_object.environment("IUSE").split() |