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

Replies