Gentoo Archives: gentoo-portage-dev

From: Zac Medico <zmedico@g.o>
To: gentoo-portage-dev@l.g.o
Cc: Zac Medico <zmedico@g.o>
Subject: [gentoo-portage-dev] [PATCH v2] emerge --info: show /bin/sh provider (527996)
Date: Fri, 28 Nov 2014 21:29:46
Message-Id: 1417210178-11784-1-git-send-email-zmedico@gentoo.org
In Reply to: [gentoo-portage-dev] [PATCH] emerge --info: show /bin/sh provider (527996) by Zac Medico
1 Searching contents for the /bin/sh provider is somewhat slow.
2 Therefore, use the basename of the symlink target to locate the
3 package. If this fails, then only the basename of the symlink target
4 will be displayed. So, typical output is something like
5 "sh bash 4.2_p53", or "sh bb" if /bin/sh points to something like bb
6 that doesn't map to a package name. Note that we do not parse the
7 output of "/bin/sh --version" because many shells do not have
8 a --version option.
9
10 The relevant section of the emerge --info output will now look
11 something like this:
12
13 Timestamp of tree: Fri, 28 Nov 2014 00:45:01 +0000
14 sh bash 4.2_p53
15 ld GNU ld (Gentoo 2.23.2 p1.0) 2.23.2
16
17 X-Gentoo-Bug: 527996
18 X-Gentoo-Url: https://bugs.gentoo.org/show_bug.cgi?id=527996
19 ---
20 PATCH v2 handles a possible InvalidAtom exception.
21
22 pym/_emerge/actions.py | 40 ++++++++++++++++++++++++++++++++++++++++
23 1 file changed, 40 insertions(+)
24
25 diff --git a/pym/_emerge/actions.py b/pym/_emerge/actions.py
26 index dec5b04..f14a27d 100644
27 --- a/pym/_emerge/actions.py
28 +++ b/pym/_emerge/actions.py
29 @@ -1556,6 +1556,46 @@ def action_info(settings, trees, myopts, myfiles):
30 lastSync = "Unknown"
31 append("Timestamp of tree: %s" % (lastSync,))
32
33 + # Searching contents for the /bin/sh provider is somewhat
34 + # slow. Therefore, use the basename of the symlink target
35 + # to locate the package. If this fails, then only the
36 + # basename of the symlink target will be displayed. So,
37 + # typical output is something like "sh bash 4.2_p53", or
38 + # "sh bb" if /bin/sh points to something like bb that
39 + # doesn't map to a package name. Note that we do not parse
40 + # the output of "/bin/sh --version" because many shells
41 + # do not have a --version option.
42 + basename = os.path.basename(os.path.realpath(os.path.join(
43 + os.sep, portage.const.EPREFIX, "bin", "sh")))
44 + try:
45 + Atom("null/%s" % basename)
46 + except InvalidAtom:
47 + matches = None
48 + else:
49 + try:
50 + # Try a match against the basename, which should work for
51 + # busybox and most shells.
52 + matches = (trees[trees._running_eroot]["vartree"].dbapi.
53 + match(basename))
54 + except portage.exception.AmbiguousPackageName:
55 + # If the name is ambiguous, then restrict our match
56 + # to the app-shells category.
57 + matches = (trees[trees._running_eroot]["vartree"].dbapi.
58 + match("app-shells/%s" % basename))
59 +
60 + if matches:
61 + pkg = matches[-1]
62 + name = pkg.cp
63 + version = pkg.version
64 + # Omit app-shells category from the output.
65 + if name.startswith("app-shells/"):
66 + name = name[len("app-shells/"):]
67 + sh_str = "%s %s" % (name, version)
68 + else:
69 + sh_str = basename
70 +
71 + append("sh %s" % sh_str)
72 +
73 ld_names = []
74 if chost:
75 ld_names.append(chost + "-ld")
76 --
77 2.0.4

Replies