Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
python module portage raise InvalidPackageName(mycpv)
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
jonasstein
n00b
n00b


Joined: 03 Mar 2013
Posts: 31

PostPosted: Fri Mar 29, 2013 12:14 am    Post subject: python module portage raise InvalidPackageName(mycpv) Reply with quote

porttree.dbapi.aux_get(XX, ["HOMEPAGE"])[0] fails, with some package names like:

The first two work, the third kills the program.

Code:
$ python2.7 test.py
(u'app-accessibility/accerciser', u'app-accessibility/accerciser-1.12.1')
(u'app-accessibility/at-spi2-atk', u'app-accessibility/at-spi2-atk')
Traceback (most recent call last):
  File "test.py", line 25, in <module>
    main()
  File "test.py", line 21, in main
    'homepage':porttree.dbapi.aux_get(bestcpv, ["HOMEPAGE"])[0]}
  File "/usr/lib/portage/pym/portage/dbapi/porttree.py", line 455, in aux_get
    myebuild, mylocation = self.findname2(mycpv, mytree)
  File "/usr/lib/portage/pym/portage/dbapi/porttree.py", line 328, in findname2
    raise InvalidPackageName(mycpv)
portage.exception.InvalidPackageName: app-accessibility/at-spi2-atk


test.py contains the following lines. Is it a bug, or did I misunderstand portage?

Code:
#!/usr/bin/python2.7
import portage

def main():
    porttree = portage.db[portage.root]['porttree']
    all_cps = porttree.dbapi.cp_all()[1:30]

    for cp in all_cps:
        if (porttree.dep_bestmatch(cp)== "" ):
            bestcpv = cp
        else:
            bestcpv = porttree.dep_bestmatch(cp)

        print(cp, bestcpv)
        package = {'name':cp,
                   'version':cp,
                   'homepage':porttree.dbapi.aux_get(bestcpv, ["HOMEPAGE"])[0]}


if __name__ == '__main__':
    main()
Back to top
View user's profile Send private message
dol-sen
Developer
Developer


Joined: 30 Jun 2002
Posts: 2503
Location: Richmond, BC, Canada

PostPosted: Fri Mar 29, 2013 2:21 am    Post subject: Reply with quote

The reason for failure is just like the error message says... portage.exception.InvalidPackageName: app-accessibility/at-spi2-atk

at-spi2-atk <== it is missing a proper version number. Following normal portage naming rules that name would break down into:

name: at-spi2
version: atk

Because it splits the name-version string on the last "-"

looking at your code
Code:
print(cp, bestcpv)
and the output
Code:
(u'app-accessibility/at-spi2-atk', u'app-accessibility/at-spi2-atk')
There is an ebuild that is missing the version. NOTE that both cp and bestcpv are the exact same. The v in bestcpv name should imply the version.
_________________
Brian
Porthole, the Portage GUI frontend irc@freenode: #gentoo-guis, #porthole, Blog
layman, gentoolkit, CoreBuilder, esearch...
Back to top
View user's profile Send private message
jonasstein
n00b
n00b


Joined: 03 Mar 2013
Posts: 31

PostPosted: Fri Mar 29, 2013 11:11 am    Post subject: Reply with quote

The if statement was a workaround, because
Code:
porttree.dep_bestmatch(cp)

returned an empty string, if no other versions were available.

Is it my fault, or a broken dep_bestmatch function?
Back to top
View user's profile Send private message
dol-sen
Developer
Developer


Joined: 30 Jun 2002
Posts: 2503
Location: Richmond, BC, Canada

PostPosted: Fri Mar 29, 2013 8:07 pm    Post subject: Reply with quote

Ah, I missed that. Yes, that is your fault. aux_get() takes a category/pkg-ver string. By supplying just a category/pkg string, it would cause the error.

It is likely that the ebuilds are masked for one reason or another. If you want it to return the best available working progressively through the masking reasons, then have a look at portholes backend code. In there I have a function that first attempts to get the best non-masked version, if that fails, then try's the best keyword masked, then the best hard-masked version. hmm, I don't remember, but I may have added it to the public api I've been working on for portage too.

There are also functions to get the masking reason for a cpv

portage backend

pay attention get_dep_ebuild() it uses the the portdbapi's xmatch() which is very flexible, check out it's options.
_________________
Brian
Porthole, the Portage GUI frontend irc@freenode: #gentoo-guis, #porthole, Blog
layman, gentoolkit, CoreBuilder, esearch...
Back to top
View user's profile Send private message
dol-sen
Developer
Developer


Joined: 30 Jun 2002
Posts: 2503
Location: Richmond, BC, Canada

PostPosted: Fri Mar 29, 2013 8:22 pm    Post subject: Reply with quote

oh, I forgot to mention. In the gentoo-guis overlay, there is an ebuild for app-portage/portage-public-api which will install the public api that we've been working on. It simplifies a number of the data query functions. It will eventually get the ability to perform merges, unmerges.

And join us in #gentoo-guis IRC channel
_________________
Brian
Porthole, the Portage GUI frontend irc@freenode: #gentoo-guis, #porthole, Blog
layman, gentoolkit, CoreBuilder, esearch...
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