Gentoo Archives: gentoo-commits

From: "Zac Medico (zmedico)" <zmedico@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] portage r15211 - main/trunk/bin
Date: Wed, 27 Jan 2010 21:22:45
Message-Id: E1NaFLX-0001o3-4Z@stork.gentoo.org
1 Author: zmedico
2 Date: 2010-01-27 21:22:42 +0000 (Wed, 27 Jan 2010)
3 New Revision: 15211
4
5 Modified:
6 main/trunk/bin/portageq
7 Log:
8 Add support for evaluation of conditional USE atoms in has_version and
9 best_version arguments, using the USE environment variable.
10
11
12 Modified: main/trunk/bin/portageq
13 ===================================================================
14 --- main/trunk/bin/portageq 2010-01-26 17:53:51 UTC (rev 15210)
15 +++ main/trunk/bin/portageq 2010-01-27 21:22:42 UTC (rev 15211)
16 @@ -46,6 +46,16 @@
17 from portage import os
18 from portage.util import writemsg, writemsg_stdout
19
20 +def eval_atom_use(atom):
21 + if atom.use.conditional and 'USE' in os.environ:
22 + use = os.environ['USE'].split()
23 + evaluated_atom = portage.dep.remove_slot(atom)
24 + if atom.slot:
25 + evaluated_atom += ":%s" % atom.slot
26 + evaluated_atom += str(atom.use.evaluate_conditionals(use))
27 + atom = portage.dep.Atom(evaluated_atom)
28 + return atom
29 +
30 #-----------------------------------------------------------------------------
31 #
32 # To add functionality to this tool, add a function below.
33 @@ -74,12 +84,20 @@
34 if (len(argv) < 2):
35 print("ERROR: insufficient parameters!")
36 sys.exit(2)
37 - if atom_validate_strict and not portage.isvalidatom(argv[1]):
38 - portage.writemsg("ERROR: Invalid atom: '%s'\n" % argv[1],
39 - noiselevel=-1)
40 - return 2
41 try:
42 - mylist=portage.db[argv[0]]["vartree"].dbapi.match(argv[1])
43 + atom = portage.dep.Atom(argv[1])
44 + except portage.exception.InvalidAtom:
45 + if atom_validate_strict:
46 + portage.writemsg("ERROR: Invalid atom: '%s'\n" % argv[1],
47 + noiselevel=-1)
48 + return 2
49 + else:
50 + atom = argv[1]
51 + else:
52 + atom = eval_atom_use(atom)
53 +
54 + try:
55 + mylist = portage.db[argv[0]]["vartree"].dbapi.match(atom)
56 if mylist:
57 sys.exit(0)
58 else:
59 @@ -96,12 +114,19 @@
60 if (len(argv) < 2):
61 print("ERROR: insufficient parameters!")
62 sys.exit(2)
63 - if atom_validate_strict and not portage.isvalidatom(argv[1]):
64 - portage.writemsg("ERROR: Invalid atom: '%s'\n" % argv[1],
65 - noiselevel=-1)
66 - return 2
67 try:
68 - mylist=portage.db[argv[0]]["vartree"].dbapi.match(argv[1])
69 + atom = portage.dep.Atom(argv[1])
70 + except portage.exception.InvalidAtom:
71 + if atom_validate_strict:
72 + portage.writemsg("ERROR: Invalid atom: '%s'\n" % argv[1],
73 + noiselevel=-1)
74 + return 2
75 + else:
76 + atom = argv[1]
77 + else:
78 + atom = eval_atom_use(atom)
79 + try:
80 + mylist = portage.db[argv[0]]["vartree"].dbapi.match(atom)
81 print(portage.best(mylist))
82 except KeyError:
83 sys.exit(1)
84 @@ -558,7 +583,7 @@
85 # Show our commands -- we do this by scanning the functions in this
86 # file, and formatting each functions documentation.
87 #
88 - non_commands = frozenset(['exithandler', 'main',
89 + non_commands = frozenset(['eval_atom_use', 'exithandler', 'main',
90 'usage', 'writemsg', 'writemsg_stdout'])
91 commands = sorted(k for k, v in globals().items() \
92 if type(v) is types.FunctionType and k not in non_commands)