From 3dec70f6e1c7dcf1b345ea6faffc26e12b0daac6 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Fri, 29 Jan 2010 18:51:56 +0000 Subject: [PATCH] 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 --- bin/portageq | 47 ++++++++++++++++++++++++++++++++++++----------- 1 file 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) -- 2.26.2