1 |
Author: grobian |
2 |
Date: 2010-01-28 18:01:56 +0000 (Thu, 28 Jan 2010) |
3 |
New Revision: 15215 |
4 |
|
5 |
Modified: |
6 |
main/branches/prefix/bin/portageq |
7 |
main/branches/prefix/pym/portage/__init__.py |
8 |
main/branches/prefix/pym/portage/dep.py |
9 |
Log: |
10 |
Merged from trunk -r15210:15214 |
11 |
|
12 |
| 15211 | Add support for evaluation of conditional USE atoms in | |
13 |
| zmedico | has_version and best_version arguments, using the USE | |
14 |
| | environment variable. | |
15 |
|
16 |
| 15212 | Add an Atom.evaluate_conditionals() method and use where | |
17 |
| zmedico | appropriate. | |
18 |
|
19 |
| 15213 | Fix typo in docstring. | |
20 |
| zmedico | | |
21 |
|
22 |
| 15214 | Fix AttributeError from has_versions for atoms with no USE | |
23 |
| zmedico | deps. Thanks to Arfrever for reporting. | |
24 |
|
25 |
|
26 |
Modified: main/branches/prefix/bin/portageq |
27 |
=================================================================== |
28 |
--- main/branches/prefix/bin/portageq 2010-01-28 14:48:58 UTC (rev 15214) |
29 |
+++ main/branches/prefix/bin/portageq 2010-01-28 18:01:56 UTC (rev 15215) |
30 |
@@ -50,6 +50,12 @@ |
31 |
from portage import os |
32 |
from portage.util import writemsg, writemsg_stdout |
33 |
|
34 |
+def eval_atom_use(atom): |
35 |
+ if 'USE' in os.environ: |
36 |
+ use = frozenset(os.environ['USE'].split()) |
37 |
+ atom = atom.evaluate_conditionals(use) |
38 |
+ return atom |
39 |
+ |
40 |
#----------------------------------------------------------------------------- |
41 |
# |
42 |
# To add functionality to this tool, add a function below. |
43 |
@@ -78,12 +84,20 @@ |
44 |
if (len(argv) < 2): |
45 |
print("ERROR: insufficient parameters!") |
46 |
sys.exit(2) |
47 |
- if atom_validate_strict and not portage.isvalidatom(argv[1]): |
48 |
- portage.writemsg("ERROR: Invalid atom: '%s'\n" % argv[1], |
49 |
- noiselevel=-1) |
50 |
- return 2 |
51 |
try: |
52 |
- mylist=portage.db[argv[0]]["vartree"].dbapi.match(argv[1]) |
53 |
+ atom = portage.dep.Atom(argv[1]) |
54 |
+ except portage.exception.InvalidAtom: |
55 |
+ if atom_validate_strict: |
56 |
+ portage.writemsg("ERROR: Invalid atom: '%s'\n" % argv[1], |
57 |
+ noiselevel=-1) |
58 |
+ return 2 |
59 |
+ else: |
60 |
+ atom = argv[1] |
61 |
+ else: |
62 |
+ atom = eval_atom_use(atom) |
63 |
+ |
64 |
+ try: |
65 |
+ mylist = portage.db[argv[0]]["vartree"].dbapi.match(atom) |
66 |
if mylist: |
67 |
sys.exit(0) |
68 |
else: |
69 |
@@ -100,12 +114,19 @@ |
70 |
if (len(argv) < 2): |
71 |
print("ERROR: insufficient parameters!") |
72 |
sys.exit(2) |
73 |
- if atom_validate_strict and not portage.isvalidatom(argv[1]): |
74 |
- portage.writemsg("ERROR: Invalid atom: '%s'\n" % argv[1], |
75 |
- noiselevel=-1) |
76 |
- return 2 |
77 |
try: |
78 |
- mylist=portage.db[argv[0]]["vartree"].dbapi.match(argv[1]) |
79 |
+ atom = portage.dep.Atom(argv[1]) |
80 |
+ except portage.exception.InvalidAtom: |
81 |
+ if atom_validate_strict: |
82 |
+ portage.writemsg("ERROR: Invalid atom: '%s'\n" % argv[1], |
83 |
+ noiselevel=-1) |
84 |
+ return 2 |
85 |
+ else: |
86 |
+ atom = argv[1] |
87 |
+ else: |
88 |
+ atom = eval_atom_use(atom) |
89 |
+ try: |
90 |
+ mylist = portage.db[argv[0]]["vartree"].dbapi.match(atom) |
91 |
print(portage.best(mylist)) |
92 |
except KeyError: |
93 |
sys.exit(1) |
94 |
@@ -562,7 +583,7 @@ |
95 |
# Show our commands -- we do this by scanning the functions in this |
96 |
# file, and formatting each functions documentation. |
97 |
# |
98 |
- non_commands = frozenset(['exithandler', 'main', |
99 |
+ non_commands = frozenset(['eval_atom_use', 'exithandler', 'main', |
100 |
'usage', 'writemsg', 'writemsg_stdout']) |
101 |
commands = sorted(k for k, v in globals().items() \ |
102 |
if type(v) is types.FunctionType and k not in non_commands) |
103 |
|
104 |
Modified: main/branches/prefix/pym/portage/__init__.py |
105 |
=================================================================== |
106 |
--- main/branches/prefix/pym/portage/__init__.py 2010-01-28 14:48:58 UTC (rev 15214) |
107 |
+++ main/branches/prefix/pym/portage/__init__.py 2010-01-28 18:01:56 UTC (rev 15215) |
108 |
@@ -7832,11 +7832,7 @@ |
109 |
if not repoman and \ |
110 |
myuse is not None and isinstance(x, portage.dep.Atom) and x.use: |
111 |
if x.use.conditional: |
112 |
- evaluated_atom = portage.dep.remove_slot(x) |
113 |
- if x.slot: |
114 |
- evaluated_atom += ":%s" % x.slot |
115 |
- evaluated_atom += str(x.use.evaluate_conditionals(myuse)) |
116 |
- x = portage.dep.Atom(evaluated_atom) |
117 |
+ x = x.evaluate_conditionals(myuse) |
118 |
|
119 |
mykey = x.cp |
120 |
if not mykey.startswith("virtual/"): |
121 |
|
122 |
Modified: main/branches/prefix/pym/portage/dep.py |
123 |
=================================================================== |
124 |
--- main/branches/prefix/pym/portage/dep.py 2010-01-28 14:48:58 UTC (rev 15214) |
125 |
+++ main/branches/prefix/pym/portage/dep.py 2010-01-28 18:01:56 UTC (rev 15215) |
126 |
@@ -612,6 +612,22 @@ |
127 |
|
128 |
return False |
129 |
|
130 |
+ def evaluate_conditionals(self, use): |
131 |
+ """ |
132 |
+ Create an atom instance with any USE conditionals evaluated. |
133 |
+ @param use: The set of enabled USE flags |
134 |
+ @type use: set |
135 |
+ @rtype: Atom |
136 |
+ @return: an atom instance with any USE conditionals evaluated |
137 |
+ """ |
138 |
+ if not (self.use and self.use.conditional): |
139 |
+ return self |
140 |
+ atom = remove_slot(self) |
141 |
+ if self.slot: |
142 |
+ atom += ":%s" % self.slot |
143 |
+ atom += str(self.use.evaluate_conditionals(use)) |
144 |
+ return Atom(atom) |
145 |
+ |
146 |
def __copy__(self): |
147 |
"""Immutable, so returns self.""" |
148 |
return self |