From: Fabian Groffen Date: Thu, 28 Jan 2010 18:01:56 +0000 (-0000) Subject: Merged from trunk -r15210:15214 X-Git-Url: http://git.tremily.us/gitweb.cgi?a=commitdiff_plain;h=8ac740c7a167bd2b81118cb8617f63e3e5a6d3c0;p=portage.git Merged from trunk -r15210:15214 | 15211 | Add support for evaluation of conditional USE atoms in | | zmedico | has_version and best_version arguments, using the USE | | | environment variable. | | 15212 | Add an Atom.evaluate_conditionals() method and use where | | zmedico | appropriate. | | 15213 | Fix typo in docstring. | | zmedico | | | 15214 | Fix AttributeError from has_versions for atoms with no USE | | zmedico | deps. Thanks to Arfrever for reporting. | svn path=/main/branches/prefix/; revision=15215 --- diff --git a/bin/portageq b/bin/portageq index c67ab1a10..4efefe51d 100755 --- a/bin/portageq +++ b/bin/portageq @@ -50,6 +50,12 @@ del pym_path from portage import os from portage.util import writemsg, writemsg_stdout +def eval_atom_use(atom): + if 'USE' in os.environ: + use = frozenset(os.environ['USE'].split()) + atom = atom.evaluate_conditionals(use) + return atom + #----------------------------------------------------------------------------- # # To add functionality to this tool, add a function below. @@ -78,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: @@ -100,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) @@ -562,7 +583,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) diff --git a/pym/portage/__init__.py b/pym/portage/__init__.py index 8290d0c1e..3c989d614 100644 --- a/pym/portage/__init__.py +++ b/pym/portage/__init__.py @@ -7832,11 +7832,7 @@ def _expand_new_virtuals(mysplit, edebug, mydbapi, mysettings, myroot="/", if not repoman and \ myuse is not None and isinstance(x, portage.dep.Atom) and x.use: if x.use.conditional: - evaluated_atom = portage.dep.remove_slot(x) - if x.slot: - evaluated_atom += ":%s" % x.slot - evaluated_atom += str(x.use.evaluate_conditionals(myuse)) - x = portage.dep.Atom(evaluated_atom) + x = x.evaluate_conditionals(myuse) mykey = x.cp if not mykey.startswith("virtual/"): diff --git a/pym/portage/dep.py b/pym/portage/dep.py index 70d95e484..fe3f04f59 100644 --- a/pym/portage/dep.py +++ b/pym/portage/dep.py @@ -612,6 +612,22 @@ class Atom(_atom_base): return False + def evaluate_conditionals(self, use): + """ + Create an atom instance with any USE conditionals evaluated. + @param use: The set of enabled USE flags + @type use: set + @rtype: Atom + @return: an atom instance with any USE conditionals evaluated + """ + if not (self.use and self.use.conditional): + return self + atom = remove_slot(self) + if self.slot: + atom += ":%s" % self.slot + atom += str(self.use.evaluate_conditionals(use)) + return Atom(atom) + def __copy__(self): """Immutable, so returns self.""" return self