Gentoo Archives: gentoo-portage-dev

From: Jason Stubbs <jstubbs@g.o>
To: gentoo-portage-dev@l.g.o
Subject: Re: [gentoo-portage-dev] accessing portage updates through it's data structures
Date: Tue, 18 Apr 2006 11:58:58
Message-Id: 200604182050.37975.jstubbs@gentoo.org
In Reply to: [gentoo-portage-dev] accessing portage updates through it's data structures by Tom Hosiawa
1 On Tuesday 18 April 2006 13:20, Tom Hosiawa wrote:
2 > Anybody have any ideas how I can basically do 'emerge -puDNv' directly
3 > from my superkaramba python program, and get the updates available
4 > directly from the portage data structures?
5
6 What is needed for -uDNv is mostly locked away in emerge, unfortunately.
7 The following couple of lines should get you everything other than --newuse
8 though. As you only seem to be interested in what packages are available
9 for updating, the ordering shouldn't really matter.
10
11
12 import portage
13
14 pdb = portage.db["/"]["porttree"].dbapi
15 vdb = portage.db["/"]["vartree"].dbapi
16
17 installed_pkgs = dict([(key, vdb.match(key)) for key in vdb.cp_all()])
18 latest_pkgs = dict([(key, portage.best(pdb.match(key))) for key in installed_pkgs])
19 updatable_pkgs = [latest_pkgs[key] for key in latest_pkgs if latest_pkgs[key] not in installed_pkgs[key]]
20 updatable_pkgs = [pkg for pkg in updatable_pkgs if pkg]
21
22
23 That last line there is to kill off the None elements that end up in
24 updatable_pkgs when there is a package installed that has no versions
25 available in the rsync tree. Other than that, portage.catpkgsplit() will
26 split a package identifier into [cat, pkg, ver, rev].
27
28 --
29 Jason Stubbs
30 --
31 gentoo-portage-dev@g.o mailing list

Replies

Subject Author
Re: [gentoo-portage-dev] accessing portage updates through it's data structures Tom Hosiawa <tomek32@×××××.com>