summaryrefslogtreecommitdiffstats
path: root/bin/portageq
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2011-06-02 05:50:54 -0700
committerZac Medico <zmedico@gentoo.org>2011-06-02 05:50:54 -0700
commit1edf9e3bd37fede61a21d3b6a84542d29d8f3021 (patch)
tree58a323ba5fb8792baae6a8def80a26f457448e6c /bin/portageq
parent10f6c6d3c028a509ed943ef76633c72dbbcff7f6 (diff)
downloadportage-1edf9e3bd37fede61a21d3b6a84542d29d8f3021.tar.gz
portage-1edf9e3bd37fede61a21d3b6a84542d29d8f3021.tar.bz2
portage-1edf9e3bd37fede61a21d3b6a84542d29d8f3021.zip
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 <root> <atom> 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
Diffstat (limited to 'bin/portageq')
-rwxr-xr-xbin/portageq35
1 files changed, 35 insertions, 0 deletions
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):
+ """<root> <atom>
+ 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):
"""