Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
use portage to split catagory package version and revision?
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
turtles
Veteran
Veteran


Joined: 31 Dec 2004
Posts: 1696

PostPosted: Sun Nov 03, 2024 10:26 pm    Post subject: use portage to split catagory package version and revision? Reply with quote

Greetings Gentooers I am atempting to write a small python program that will take a category/package[version][revision]
and split it into package version and revision revision (if any) on the command line
for this I am using use the function catpkgsplit from /usr/lib/python3.11/site-packages/portage/versions.py

I have the the folowing code saved as a file split_cpv.py:
Code:

#!/usr/bin/python

# use function from /usr/lib/python3.11/site-packages/portage/versions.py
# to split package version and revision revision (if any)
import sys
import portage

mysplit = None;

if len(sys.argv) > 1:
    mysplit = sys.argv[1]

if mysplit is None:
    sys.exit(0)
else:    print ('mysplit', mysplit)

p_split = portage.catpkgsplit(mysplit)

if isinstance(p_split, (list, tuple, dict, str)):
    print (p_split[0], ' ', p_split[1], ' ', p_split[2], ' ', p_split[3] )
else:
    print(f"The p_split object is not as exprected. It is of type: {type(p_split)}")

and if I run it like
Code:
split_cpv.py sys-apps/portage
I dont get anything
but if I have a version like so:
Code:
split_cpv.py sys-apps/portage-3.0.65

it works
Anyone have an Idea how I could get it to also work for pacakges without a version?
Thanks
_________________
Donate to Gentoo
Back to top
View user's profile Send private message
grknight
Retired Dev
Retired Dev


Joined: 20 Feb 2015
Posts: 1901

PostPosted: Sun Nov 03, 2024 11:10 pm    Post subject: Reply with quote

turtles wrote:
Anyone have an Idea how I could get it to also work for pacakges without a version?

Back it up with portage.catsplit when the other call does not return the expected split (portage.catpkgsplit always needs package and version, category and revision are optional)
Back to top
View user's profile Send private message
CaptainBlood
Advocate
Advocate


Joined: 24 Jan 2010
Posts: 3838

PostPosted: Sun Nov 03, 2024 11:20 pm    Post subject: Reply with quote

Code:
app-portage/portage-utils-0.97 (/usr/bin/qatom -> q)
Code:
qatom(1)                             qatom                             qatom(1)

NAME
       qatom - split atom strings

SYNOPSIS
       qatom [opts] <pkg>

DESCRIPTION
       qatom parses strings into atoms and optionally compares them.  The pars‐
       ing  into atoms results in CATEGORY, PN (package name), PV (package ver‐
       sion), PR (package revision), SLOT and  REPO.   Next  to  these  version
       qualifiers  (e.g. >,  <, or =) and optional * suffix are extracted.  All
       but PN are optional.

       Comparison of atoms returns the relationship between two  parsed  atoms.
       qatom does not allow to test conditions.  It is possible to perform mul‐
       tiple  comparisons  by  simply  adding more arguments.  Comparisons are,
       however, always performed two by two, so there must be an even count  of
       arguments to the compare function.

       The qatom applet is a direct wrapper around the atom parsing functional‐
       ities  used  by  various other applets.  As such this applet allows easy
       testing or atom parsing and comparison behaviour.

OPTIONS
       -F <arg>, --format <arg>
              Specify a custom  output  format.  The default format is
              %{CATEGORY} %{PN} %{PV} %[PR] %[SLOT] %[pfx] %[sfx]
              Conversion specifiers start with a % symbol and are  followed  by
              either { or [.  Next is the name of the field to expand, followed
              by a matching } or ].  The difference between { and [ is that the
              latter  is  only  printed if the field referred is set, while the
              former prints <unset> in that case.

              The following fields are supported, which  are  inline  with  the
              variables from ebuild(5).

              CATEGORY
                     The category of the package.

              P      The package name and version without the ebuild revision.

              PN     The package name.

              PV     The package version without the ebuild revision.

              PVR    The  package  version  including ebuild revision, which is
                     also printed when zero, unlike for PF.

              PF     The package name, version  and  revision  when  not  zero.
                     Thus, a zero revision -r0 is not printed.

              PR     The  ebuild revision, when force printed, outputs -r0 when
                     unset.

              SLOT   The package slot, when force printed, outputs -  when  un‐
                     set.

              REPO   The package repository.

              pfx    The package prefixes, that is version specifiers.

              sfx    The package suffices, currently that is just the asterisk.

       -c, --compare
              Compare two atoms.

       -s, --scompare
              Compare two atoms in the given order data, query.

       -p, --print
              Print reconstructed atom.

       -l, --lookup
              Lookup atom in tree.

       --root <arg>
              Set the ROOT env var.

       -v, --verbose
              Force all expansions, basically treat all [ like {.

       -q, --quiet
              Ignored for compatibility with other qapplets.

       -C, --nocolor
              Ignored for compatibility with other qapplets.

       --color
              Force color in output.

       -h, --help
              Print this help and exit.

       -V, --version
              Print version and exit.

ANTISLOT
       A feature present in portage-utils is the so-called antislot, and is ac‐
       tivated  by starting the atom with a carrot (ˆ), in place of the blocker
       bang (!).  The antislot is similar  to  the  inversing  behaviour  of  a
       blocker,  but only operates on SLOT and SUBSLOT, and requires SLOT to be
       available, e.g. it won’t match unset SLOT (NULL).

       The antislot is mostly useful with dependencies and  is  best  described
       with   an   example.   Consider  a  perl  upgrade  from  perl:0/5.28  to
       perl:0/5.30.  To find a consumer for perl:0/5.28 a simple match  can  be
       made, e.g. using qdepends
            $ qdepends -Q perl:0/5.28
            virtual/perl-ExtUtils-MakeMaker-7.340.0-r1: ... dev-lang/perl:0/5.28 ...
            ...

       However,  to  query  after  perl:0/5.30 is installed, which packages are
       still not rebuilt (e.g. depending on an older perl:  5.28,  5.26,  etc.)
       one can use the antislot:

            $ qdepends -Q ˆperl:0/5.30
            ...

       This  will  return any package that depends on perl:0 not having subslot
       5.30.

       Obviously this can be tested using qatom using the -c option:

            $ qatom -c ˆperl:0/5.30 perl-5.28.1:0/5.28
            ˆperl:0/5.30 == perl-5.28.1:0/5.28
may help.

Thks 4 ur attention, interest & support.
_________________
USE="-* ..." in /etc/portage/make.conf here, i.e. a countermeasure to portage implicit braces, belt & diaper paradigm
LT: "I've been doing a passable imitation of the Fontana di Trevi, except my medium is mucus. Sooo much mucus. "
Back to top
View user's profile Send private message
turtles
Veteran
Veteran


Joined: 31 Dec 2004
Posts: 1696

PostPosted: Mon Nov 04, 2024 2:46 am    Post subject: Reply with quote

grknight wrote:
turtles wrote:
Anyone have an Idea how I could get it to also work for pacakges without a version?

Back it up with portage.catsplit when the other call does not return the expected split (portage.catpkgsplit always needs package and version, category and revision are optional)


Thanks that did it
_________________
Donate to Gentoo
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