Gentoo Archives: gentoo-commits

From: Zac Medico <zmedico@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/portage:master commit in: bin/
Date: Thu, 02 Jun 2011 13:06:56
Message-Id: 1edf9e3bd37fede61a21d3b6a84542d29d8f3021.zmedico@gentoo
1 commit: 1edf9e3bd37fede61a21d3b6a84542d29d8f3021
2 Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
3 AuthorDate: Thu Jun 2 12:50:54 2011 +0000
4 Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
5 CommitDate: Thu Jun 2 12:50:54 2011 +0000
6 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=1edf9e3b
7
8 portageq: add new expand_virtual function
9
10 Something like this was requested in bug #157357. Now that Gentoo has
11 migrated all virtuals to GLEP 37 new-style virtuals, this kind of
12 function may be helpful in order to resolve the currently installed
13 provider of a particular virtual in scripts like bootstrap.sh.
14
15 Usage:
16
17 portageq expand_virtual <root> <atom>
18
19 Returns a \n separated list of atoms expanded from a
20 given virtual atom, excluding blocker atoms. Satisfied
21 virtual atoms are not included in the output, since
22 they are expanded to real atoms which are displayed.
23 Unsatisfied virtual atoms are displayed without
24 any expansion. The "match" command can be used to
25 resolve the returned atoms to specific installed
26 packages.
27
28 Example input/output:
29
30 $ portageq expand_virtual / virtual/jre
31 =dev-java/sun-jdk-1.6.0*
32
33 $ portageq expand_virtual / virtual/jre:1.5
34 dev-java/gcj-jdk
35
36 $ portageq expand_virtual / virtual/package-manager
37 sys-apps/portage
38
39 $ portageq expand_virtual / virtual/libc
40 sys-libs/glibc:2.2
41
42 $ portageq expand_virtual / virtual/os-headers
43 sys-kernel/linux-headers:0
44
45 ---
46 bin/portageq | 35 +++++++++++++++++++++++++++++++++++
47 1 files changed, 35 insertions(+), 0 deletions(-)
48
49 diff --git a/bin/portageq b/bin/portageq
50 index 069ece2..d6d9c17 100755
51 --- a/bin/portageq
52 +++ b/bin/portageq
53 @@ -43,6 +43,7 @@ except ImportError:
54 del pym_path
55
56 from portage import os
57 +from portage.dbapi._expand_new_virt import expand_new_virt
58 from portage.util import writemsg, writemsg_stdout
59
60 def eval_atom_use(atom):
61 @@ -492,6 +493,40 @@ def match(argv):
62 print(cpv)
63 match.uses_root = True
64
65 +def expand_virtual(argv):
66 + """<root> <atom>
67 + Returns a \\n separated list of atoms expanded from a
68 + given virtual atom, excluding blocker atoms. Satisfied
69 + virtual atoms are not included in the output, since
70 + they are expanded to real atoms which are displayed.
71 + Unsatisfied virtual atoms are displayed without
72 + any expansion. The "match" command can be used to
73 + resolve the returned atoms to specific installed
74 + packages.
75 + """
76 + if len(argv) != 2:
77 + writemsg("ERROR: expected 2 parameters, got %d!\n" % len(argv),
78 + noiselevel=-1)
79 + return 2
80 +
81 + root, atom = argv
82 +
83 + try:
84 + results = list(expand_new_virt(
85 + portage.db[root]["vartree"].dbapi, atom))
86 + except portage.exception.InvalidAtom:
87 + writemsg("ERROR: Invalid atom: '%s'\n" % atom,
88 + noiselevel=-1)
89 + return 2
90 +
91 + results.sort()
92 + for x in results:
93 + if not x.blocker:
94 + writemsg_stdout("%s\n" % (x,))
95 +
96 + return os.EX_OK
97 +
98 +expand_virtual.uses_root = True
99
100 def vdb_path(argv):
101 """