Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
how to convert a package atom to canonical form
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
Slippery Jim
Apprentice
Apprentice


Joined: 08 Jan 2005
Posts: 284

PostPosted: Fri Jan 03, 2025 12:19 pm    Post subject: how to convert a package atom to canonical form Reply with quote

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
View user's profile Send private message
fedeliallalinea
Administrator
Administrator


Joined: 08 Mar 2003
Posts: 31387
Location: here

PostPosted: Fri Jan 03, 2025 12:43 pm    Post subject: Reply with quote

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
View user's profile Send private message
Josef.95
Advocate
Advocate


Joined: 03 Sep 2007
Posts: 4683
Location: Germany

PostPosted: Fri Jan 03, 2025 12:58 pm    Post subject: Reply with quote

Or, for installed packages it works with portage too.
Code:
# portageq match / '*/perl'
dev-lang/perl-5.40.0-r1
Back to top
View user's profile Send private message
sam_
Developer
Developer


Joined: 14 Aug 2020
Posts: 2067

PostPosted: Fri Jan 03, 2025 1:03 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum