View previous topic :: View next topic |
Author |
Message |
Slippery Jim Apprentice
Joined: 08 Jan 2005 Posts: 284
|
Posted: Fri Jan 03, 2025 12:19 pm Post subject: how to convert a package atom to canonical form |
|
|
I have a script that takes a package atom and returns its fully qualified identifier, i.e. $CATEGORY/$PF.
For example, if I say canonicalize perl, it returns dev-lang/perl-5.40.0
It seems to work, but I feel like this is something that there should already be a tool for. Here's my script. Does anyone have a simpler solution?
Code: |
#!/bin/sh
# usage: canonicalize atom
# returns: canonical package identifier for the given atom, i.e. $CATEGORY/$PF
STRIP_VERSION="
s/\-r[0-9]+$//
:x
s/_alpha[0-9]*$//
s/_beta[0-9]*$//
s/_pre[0-9]*$//
s/_rc[0-9]*$//
s/_p[0-9]*$//
tx
s/\-[0-9]+(\.[0-9]+)*[a-z]{0,1}$//
"
# get the canonical package atom of the first parameter (@sets pass through unchanged):
canonicalize () {
MYATOM=`echo ${1} | sed -e '/^@/!d'`
[ ! ${MYATOM} ] && {
emerge -q1p ${1} | grep -o -e '[[:alnum:]-]*/[.[:alnum:]_-]*' > tmp.list
N=`sed -E -e "${STRIP_VERSION}" tmp.list | sed -n -e "/\/${1}$/="`
MYATOM=`sed -n "${N}p" tmp.list`
rm -f tmp.list
}
}
canonicalize ${@}
echo ${MYATOM}
|
Output:
Code: |
james@Two-Spear ~/software/gentoo-target $ ./canonicalize mpv
media-video/mpv-0.39.0
james@Two-Spear ~/software/gentoo-target $ ./canonicalize perl
dev-lang/perl-5.40.0
james@Two-Spear ~/software/gentoo-target $ ./canonicalize blender 2>/dev/null
media-gfx/blender-4.2.1
james@Two-Spear ~/software/gentoo-target $ ./canonicalize gvim
app-editors/gvim-9.0.0099-r1
james@Two-Spear ~/software/gentoo-target $
|
|
|
Back to top |
|
|
fedeliallalinea Administrator
Joined: 08 Mar 2003 Posts: 31387 Location: here
|
Posted: Fri Jan 03, 2025 12:43 pm Post subject: |
|
|
With qsearch in app-portage/portage-utils:
Code: | $ qsearch -N --format='%{CATEGORY}/%{P}' '^perl$'
dev-lang/perl-5.40.0 |
If package is installed you can use qlist
Code: | $ qlist -Ive perl
dev-lang/perl-5.40.0 |
Even with app-portage/eix you can do something like this _________________ Questions are guaranteed in life; Answers aren't. |
|
Back to top |
|
|
Josef.95 Advocate
Joined: 03 Sep 2007 Posts: 4683 Location: Germany
|
Posted: Fri Jan 03, 2025 12:58 pm Post subject: |
|
|
Or, for installed packages it works with portage too. Code: | # portageq match / '*/perl'
dev-lang/perl-5.40.0-r1 |
|
|
Back to top |
|
|
sam_ Developer
Joined: 14 Aug 2020 Posts: 2067
|
Posted: Fri Jan 03, 2025 1:03 pm Post subject: |
|
|
I think what you're looking for is atomf from iwdevtools, qatom from portage-utils, or patom from pkgcore?
EDIT: Ah, maybe not, but maybe those mentions will be useful for you anyway (or someone else). |
|
Back to top |
|
|
|