From 1edf9e3bd37fede61a21d3b6a84542d29d8f3021 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Thu, 2 Jun 2011 05:50:54 -0700 Subject: portageq: add new expand_virtual function Something like this was requested in bug #157357. Now that Gentoo has migrated all virtuals to GLEP 37 new-style virtuals, this kind of function may be helpful in order to resolve the currently installed provider of a particular virtual in scripts like bootstrap.sh. Usage: portageq expand_virtual Returns a \n separated list of atoms expanded from a given virtual atom, excluding blocker atoms. Satisfied virtual atoms are not included in the output, since they are expanded to real atoms which are displayed. Unsatisfied virtual atoms are displayed without any expansion. The "match" command can be used to resolve the returned atoms to specific installed packages. Example input/output: $ portageq expand_virtual / virtual/jre =dev-java/sun-jdk-1.6.0* $ portageq expand_virtual / virtual/jre:1.5 dev-java/gcj-jdk $ portageq expand_virtual / virtual/package-manager sys-apps/portage $ portageq expand_virtual / virtual/libc sys-libs/glibc:2.2 $ portageq expand_virtual / virtual/os-headers sys-kernel/linux-headers:0 --- bin/portageq | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'bin/portageq') diff --git a/bin/portageq b/bin/portageq index 069ece238..d6d9c170a 100755 --- a/bin/portageq +++ b/bin/portageq @@ -43,6 +43,7 @@ except ImportError: del pym_path from portage import os +from portage.dbapi._expand_new_virt import expand_new_virt from portage.util import writemsg, writemsg_stdout def eval_atom_use(atom): @@ -492,6 +493,40 @@ def match(argv): print(cpv) match.uses_root = True +def expand_virtual(argv): + """ + Returns a \\n separated list of atoms expanded from a + given virtual atom, excluding blocker atoms. Satisfied + virtual atoms are not included in the output, since + they are expanded to real atoms which are displayed. + Unsatisfied virtual atoms are displayed without + any expansion. The "match" command can be used to + resolve the returned atoms to specific installed + packages. + """ + if len(argv) != 2: + writemsg("ERROR: expected 2 parameters, got %d!\n" % len(argv), + noiselevel=-1) + return 2 + + root, atom = argv + + try: + results = list(expand_new_virt( + portage.db[root]["vartree"].dbapi, atom)) + except portage.exception.InvalidAtom: + writemsg("ERROR: Invalid atom: '%s'\n" % atom, + noiselevel=-1) + return 2 + + results.sort() + for x in results: + if not x.blocker: + writemsg_stdout("%s\n" % (x,)) + + return os.EX_OK + +expand_virtual.uses_root = True def vdb_path(argv): """ -- cgit v1.2.3-1-g7c22