* [gentoo-portage-dev] [PATCH] emerge --info: show /bin/sh provider (527996)
@ 2014-11-28 21:17 Zac Medico
2014-11-28 21:29 ` [gentoo-portage-dev] [PATCH v2] " Zac Medico
0 siblings, 1 reply; 4+ messages in thread
From: Zac Medico @ 2014-11-28 21:17 UTC (permalink / raw
To: gentoo-portage-dev; +Cc: Zac Medico
Searching contents for the /bin/sh provider is somewhat slow.
Therefore, use the basename of the symlink target to locate the
package. If this fails, then only the basename of the symlink target
will be displayed. So, typical output is something like
"sh bash 4.2_p53", or "sh bb" if /bin/sh points to something like bb
that doesn't map to a package name. Note that we do not parse the
output of "/bin/sh --version" because many shells do not have
a --version option.
The relevant section of the emerge --info output will now look
something like this:
Timestamp of tree: Fri, 28 Nov 2014 00:45:01 +0000
sh bash 4.2_p53
ld GNU ld (Gentoo 2.23.2 p1.0) 2.23.2
X-Gentoo-Bug: 527996
X-Gentoo-Url: https://bugs.gentoo.org/show_bug.cgi?id=527996
---
pym/_emerge/actions.py | 35 +++++++++++++++++++++++++++++++++++
1 file changed, 35 insertions(+)
diff --git a/pym/_emerge/actions.py b/pym/_emerge/actions.py
index dec5b04..bd88547 100644
--- a/pym/_emerge/actions.py
+++ b/pym/_emerge/actions.py
@@ -1556,6 +1556,41 @@ def action_info(settings, trees, myopts, myfiles):
lastSync = "Unknown"
append("Timestamp of tree: %s" % (lastSync,))
+ # Searching contents for the /bin/sh provider is somewhat
+ # slow. Therefore, use the basename of the symlink target
+ # to locate the package. If this fails, then only the
+ # basename of the symlink target will be displayed. So,
+ # typical output is something like "sh bash 4.2_p53", or
+ # "sh bb" if /bin/sh points to something like bb that
+ # doesn't map to a package name. Note that we do not parse
+ # the output of "/bin/sh --version" because many shells
+ # do not have a --version option.
+ basename = os.path.basename(os.path.realpath(os.path.join(
+ os.sep, portage.const.EPREFIX, "bin", "sh")))
+ try:
+ # Try a match against the basename, which should work for
+ # busybox and most shells.
+ matches = (trees[trees._running_eroot]["vartree"].dbapi.
+ match(basename))
+ except portage.exception.AmbiguousPackageName:
+ # If the name is ambiguous, then restrict our match
+ # to the app-shells category.
+ matches = (trees[trees._running_eroot]["vartree"].dbapi.
+ match("app-shells/%s" % basename))
+
+ if matches:
+ pkg = matches[-1]
+ name = pkg.cp
+ version = pkg.version
+ # Omit app-shells category from the output.
+ if name.startswith("app-shells/"):
+ name = name[len("app-shells/"):]
+ sh_str = "%s %s" % (name, version)
+ else:
+ sh_str = basename
+
+ append("sh %s" % sh_str)
+
ld_names = []
if chost:
ld_names.append(chost + "-ld")
--
2.0.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [gentoo-portage-dev] [PATCH v2] emerge --info: show /bin/sh provider (527996)
2014-11-28 21:17 [gentoo-portage-dev] [PATCH] emerge --info: show /bin/sh provider (527996) Zac Medico
@ 2014-11-28 21:29 ` Zac Medico
2014-11-29 1:14 ` [gentoo-portage-dev] [PATCH v3] " Zac Medico
0 siblings, 1 reply; 4+ messages in thread
From: Zac Medico @ 2014-11-28 21:29 UTC (permalink / raw
To: gentoo-portage-dev; +Cc: Zac Medico
Searching contents for the /bin/sh provider is somewhat slow.
Therefore, use the basename of the symlink target to locate the
package. If this fails, then only the basename of the symlink target
will be displayed. So, typical output is something like
"sh bash 4.2_p53", or "sh bb" if /bin/sh points to something like bb
that doesn't map to a package name. Note that we do not parse the
output of "/bin/sh --version" because many shells do not have
a --version option.
The relevant section of the emerge --info output will now look
something like this:
Timestamp of tree: Fri, 28 Nov 2014 00:45:01 +0000
sh bash 4.2_p53
ld GNU ld (Gentoo 2.23.2 p1.0) 2.23.2
X-Gentoo-Bug: 527996
X-Gentoo-Url: https://bugs.gentoo.org/show_bug.cgi?id=527996
---
PATCH v2 handles a possible InvalidAtom exception.
pym/_emerge/actions.py | 40 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 40 insertions(+)
diff --git a/pym/_emerge/actions.py b/pym/_emerge/actions.py
index dec5b04..f14a27d 100644
--- a/pym/_emerge/actions.py
+++ b/pym/_emerge/actions.py
@@ -1556,6 +1556,46 @@ def action_info(settings, trees, myopts, myfiles):
lastSync = "Unknown"
append("Timestamp of tree: %s" % (lastSync,))
+ # Searching contents for the /bin/sh provider is somewhat
+ # slow. Therefore, use the basename of the symlink target
+ # to locate the package. If this fails, then only the
+ # basename of the symlink target will be displayed. So,
+ # typical output is something like "sh bash 4.2_p53", or
+ # "sh bb" if /bin/sh points to something like bb that
+ # doesn't map to a package name. Note that we do not parse
+ # the output of "/bin/sh --version" because many shells
+ # do not have a --version option.
+ basename = os.path.basename(os.path.realpath(os.path.join(
+ os.sep, portage.const.EPREFIX, "bin", "sh")))
+ try:
+ Atom("null/%s" % basename)
+ except InvalidAtom:
+ matches = None
+ else:
+ try:
+ # Try a match against the basename, which should work for
+ # busybox and most shells.
+ matches = (trees[trees._running_eroot]["vartree"].dbapi.
+ match(basename))
+ except portage.exception.AmbiguousPackageName:
+ # If the name is ambiguous, then restrict our match
+ # to the app-shells category.
+ matches = (trees[trees._running_eroot]["vartree"].dbapi.
+ match("app-shells/%s" % basename))
+
+ if matches:
+ pkg = matches[-1]
+ name = pkg.cp
+ version = pkg.version
+ # Omit app-shells category from the output.
+ if name.startswith("app-shells/"):
+ name = name[len("app-shells/"):]
+ sh_str = "%s %s" % (name, version)
+ else:
+ sh_str = basename
+
+ append("sh %s" % sh_str)
+
ld_names = []
if chost:
ld_names.append(chost + "-ld")
--
2.0.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [gentoo-portage-dev] [PATCH v3] emerge --info: show /bin/sh provider (527996)
2014-11-28 21:29 ` [gentoo-portage-dev] [PATCH v2] " Zac Medico
@ 2014-11-29 1:14 ` Zac Medico
2014-12-02 13:09 ` Alexander Berntsen
0 siblings, 1 reply; 4+ messages in thread
From: Zac Medico @ 2014-11-29 1:14 UTC (permalink / raw
To: gentoo-portage-dev; +Cc: Zac Medico
Searching contents for the /bin/sh provider is somewhat slow.
Therefore, use the basename of the symlink target to locate the
package. If this fails, then only the basename of the symlink target
will be displayed. So, typical output is something like
"sh bash 4.2_p53". Since realpath is used to resolve symlinks
recursively, this approach is also able to handle multiple levels of
symlinks such as /bin/sh -> bb -> busybox. Note that we do not parse
the output of "/bin/sh --version" because many shells do not have
a --version option.
The relevant section of the emerge --info output will now look
something like this:
Timestamp of tree: Fri, 28 Nov 2014 00:45:01 +0000
sh bash 4.2_p53
ld GNU ld (Gentoo 2.23.2 p1.0) 2.23.2
X-Gentoo-Bug: 527996
X-Gentoo-Url: https://bugs.gentoo.org/show_bug.cgi?id=527996
---
PATCH v3 updates comments to note that recursive symlink resolution
via realpath handles cases like /bin/sh -> bb -> busybox.
pym/_emerge/actions.py | 41 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 41 insertions(+)
diff --git a/pym/_emerge/actions.py b/pym/_emerge/actions.py
index dec5b04..90aed23 100644
--- a/pym/_emerge/actions.py
+++ b/pym/_emerge/actions.py
@@ -1556,6 +1556,47 @@ def action_info(settings, trees, myopts, myfiles):
lastSync = "Unknown"
append("Timestamp of tree: %s" % (lastSync,))
+ # Searching contents for the /bin/sh provider is somewhat
+ # slow. Therefore, use the basename of the symlink target
+ # to locate the package. If this fails, then only the
+ # basename of the symlink target will be displayed. So,
+ # typical output is something like "sh bash 4.2_p53". Since
+ # realpath is used to resolve symlinks recursively, this
+ # approach is also able to handle multiple levels of symlinks
+ # such as /bin/sh -> bb -> busybox. Note that we do not parse
+ # the output of "/bin/sh --version" because many shells
+ # do not have a --version option.
+ basename = os.path.basename(os.path.realpath(os.path.join(
+ os.sep, portage.const.EPREFIX, "bin", "sh")))
+ try:
+ Atom("null/%s" % basename)
+ except InvalidAtom:
+ matches = None
+ else:
+ try:
+ # Try a match against the basename, which should work for
+ # busybox and most shells.
+ matches = (trees[trees._running_eroot]["vartree"].dbapi.
+ match(basename))
+ except portage.exception.AmbiguousPackageName:
+ # If the name is ambiguous, then restrict our match
+ # to the app-shells category.
+ matches = (trees[trees._running_eroot]["vartree"].dbapi.
+ match("app-shells/%s" % basename))
+
+ if matches:
+ pkg = matches[-1]
+ name = pkg.cp
+ version = pkg.version
+ # Omit app-shells category from the output.
+ if name.startswith("app-shells/"):
+ name = name[len("app-shells/"):]
+ sh_str = "%s %s" % (name, version)
+ else:
+ sh_str = basename
+
+ append("sh %s" % sh_str)
+
ld_names = []
if chost:
ld_names.append(chost + "-ld")
--
2.0.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [gentoo-portage-dev] [PATCH v3] emerge --info: show /bin/sh provider (527996)
2014-11-29 1:14 ` [gentoo-portage-dev] [PATCH v3] " Zac Medico
@ 2014-12-02 13:09 ` Alexander Berntsen
0 siblings, 0 replies; 4+ messages in thread
From: Alexander Berntsen @ 2014-12-02 13:09 UTC (permalink / raw
To: gentoo-portage-dev
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256
I don't see any glaring errors here. Go ahead & merge.
- --
Alexander
bernalex@gentoo.org
https://secure.plaimi.net/~alexander
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/
iF4EAREIAAYFAlR9ufQACgkQRtClrXBQc7X+gwD9Hsgld/cVPFUnNkNnEpjFEt07
tee3CfTxkbtF900H00gA/1zgMXm7wwwBT+rXAQkGSW+8E3Vpx8gNaKb3TshsNYj8
=c8BO
-----END PGP SIGNATURE-----
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2014-12-02 13:09 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-11-28 21:17 [gentoo-portage-dev] [PATCH] emerge --info: show /bin/sh provider (527996) Zac Medico
2014-11-28 21:29 ` [gentoo-portage-dev] [PATCH v2] " Zac Medico
2014-11-29 1:14 ` [gentoo-portage-dev] [PATCH v3] " Zac Medico
2014-12-02 13:09 ` Alexander Berntsen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox