summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2010-01-29 18:51:56 +0000
committerZac Medico <zmedico@gentoo.org>2010-01-29 18:51:56 +0000
commit3dec70f6e1c7dcf1b345ea6faffc26e12b0daac6 (patch)
tree20141bd25405b3832e9bc693eed0d74ea32a3d23 /bin
parent2a45859c02ff2aee0f0d1d21a68ddf5cb28dd2dc (diff)
downloadportage-3dec70f6e1c7dcf1b345ea6faffc26e12b0daac6.tar.gz
portage-3dec70f6e1c7dcf1b345ea6faffc26e12b0daac6.tar.bz2
portage-3dec70f6e1c7dcf1b345ea6faffc26e12b0daac6.zip
Add support for evaluation of conditional USE atoms in has_version and
best_version arguments, using the USE environment variable. (trunk r15211) svn path=/main/branches/2.1.7/; revision=15262
Diffstat (limited to 'bin')
-rwxr-xr-xbin/portageq47
1 files changed, 36 insertions, 11 deletions
diff --git a/bin/portageq b/bin/portageq
index 972e78e2a..9fbf3c9bc 100755
--- a/bin/portageq
+++ b/bin/portageq
@@ -46,6 +46,16 @@ del pym_path
from portage import os
from portage.util import writemsg, writemsg_stdout
+def eval_atom_use(atom):
+ if atom.use.conditional and 'USE' in os.environ:
+ use = os.environ['USE'].split()
+ evaluated_atom = portage.dep.remove_slot(atom)
+ if atom.slot:
+ evaluated_atom += ":%s" % atom.slot
+ evaluated_atom += str(atom.use.evaluate_conditionals(use))
+ atom = portage.dep.Atom(evaluated_atom)
+ return atom
+
#-----------------------------------------------------------------------------
#
# To add functionality to this tool, add a function below.
@@ -74,12 +84,20 @@ def has_version(argv):
if (len(argv) < 2):
print("ERROR: insufficient parameters!")
sys.exit(2)
- if atom_validate_strict and not portage.isvalidatom(argv[1]):
- portage.writemsg("ERROR: Invalid atom: '%s'\n" % argv[1],
- noiselevel=-1)
- return 2
try:
- mylist=portage.db[argv[0]]["vartree"].dbapi.match(argv[1])
+ atom = portage.dep.Atom(argv[1])
+ except portage.exception.InvalidAtom:
+ if atom_validate_strict:
+ portage.writemsg("ERROR: Invalid atom: '%s'\n" % argv[1],
+ noiselevel=-1)
+ return 2
+ else:
+ atom = argv[1]
+ else:
+ atom = eval_atom_use(atom)
+
+ try:
+ mylist = portage.db[argv[0]]["vartree"].dbapi.match(atom)
if mylist:
sys.exit(0)
else:
@@ -96,12 +114,19 @@ def best_version(argv):
if (len(argv) < 2):
print("ERROR: insufficient parameters!")
sys.exit(2)
- if atom_validate_strict and not portage.isvalidatom(argv[1]):
- portage.writemsg("ERROR: Invalid atom: '%s'\n" % argv[1],
- noiselevel=-1)
- return 2
try:
- mylist=portage.db[argv[0]]["vartree"].dbapi.match(argv[1])
+ atom = portage.dep.Atom(argv[1])
+ except portage.exception.InvalidAtom:
+ if atom_validate_strict:
+ portage.writemsg("ERROR: Invalid atom: '%s'\n" % argv[1],
+ noiselevel=-1)
+ return 2
+ else:
+ atom = argv[1]
+ else:
+ atom = eval_atom_use(atom)
+ try:
+ mylist = portage.db[argv[0]]["vartree"].dbapi.match(atom)
print(portage.best(mylist))
except KeyError:
sys.exit(1)
@@ -535,7 +560,7 @@ def usage(argv):
# Show our commands -- we do this by scanning the functions in this
# file, and formatting each functions documentation.
#
- non_commands = frozenset(['exithandler', 'main',
+ non_commands = frozenset(['eval_atom_use', 'exithandler', 'main',
'usage', 'writemsg', 'writemsg_stdout'])
commands = sorted(k for k, v in globals().items() \
if type(v) is types.FunctionType and k not in non_commands)