Gentoo Archives: gentoo-commits

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