On Mon, Jun 29, 2009 at 05:00:10AM +0200, Sebastian Pipping wrote:
Hi,
first I should note that I'm not involved with the development of
portage so take everything I write with a good grain of salt ;)
I come here to ask for precise pointers related to
gathering these sets of data:
- publically known distfile mirror URLs
- publically known global use flags
I assume you mean only the stuff the user has overridden, not collapsed
together with the corresponding files in the profiles?
- entries for package.keywords
- entries for package.mask
- entries for package.unmask
- entries for package.use
- installed packages with version numbers
- entries for /var/lib/portage/world
- available local use for ebuild file F
- applied use flags for installed package P
As I had a few minutes of spare time, and I'm much better at writing
code than explaining stuff I hacked together a small script that
showcases the API's I would use to get at the above data. (see
attachment)
So my two questions are:
- Which of these sets of data can be obtained
through the Portage API, which of them not?
Unless I forgot something, or made some stupid mistake all of them ;)
- Which classes and functions should I look at?
As you can see in the attached script, most of the interesting stuff is
either available through a portage.config instance, or via the
applicable dbapi (porttree for anything that can be installed, vartree
for anything regarding installed packages, etc.)
Best regards,
Andy
--
We all know that no one understands anything that isn't funny.
import os, sys
from collections import defaultdict
try:
import portage
except ImportError:
sys.path.insert(0, /usr/lib/portage/pym)
import portage
import portage.sets
import portage.util
portage._disable_legacy_globals()
def dump_mirrors(settings):
# see portage.fetch(), snipped most of the interresting parts from there
thirdpartymirrors = settings.thirdpartymirrors().items()
thirdpartymirrors.sort(key = lambda x: x[0])
custommirrors = portage.grabdict(os.path.join(settings[PORTAGE_CONFIGROOT],
portage.CUSTOM_MIRRORS_FILE.lstrip(os.path.sep)), recursive = 1).items()
custommirrors.sort(key = lambda x: x[0])
gentoomirrors = [x.rstrip(/) for x in settings[GENTOO_MIRRORS].split() if x]
gentoomirrors.sort()
print(thirdpartymirrors:)
for name, mirrors in thirdpartymirrors:
print( %s % name)
print(\n.join(4* + x for x in mirrors))
print()
print(custom mirrors:)
for name, mirrors in custommirrors:
print( %s % name)
print(\n.join(4* + x for x in mirrors))
print()
print(gentoo mirrors:)
print(\n.join( %s % x for x in gentoomirrors))
print()
def dump_global_use(settings):
# not sure wether there is a better way, but AFAIK portage doesn't really
# care wether a flag is 'global' and use.desc is the only place I
# know of that should contain all global use flags
fp = os.path.join(settings[PORTDIR], profiles, use.desc)
with open(fp) as f:
for l in f:
if not l.strip() or l[0] == #:
continue
s = l.split(None, 1)
print(l.split(None, 1)[0])
def dump_package_foo(settings):
# stacked together with the active profiles this is available in
# settings.pusedict, settings.pkeywordsdict, settings.p(un)maskdict
# suspecting you only want the local config of the user it is probably
# easiest to use grabdict etc. directly (see portage.config.__init__)
abs_user_config = os.path.join(
settings[PORTAGE_CONFIGROOT],
portage.USER_CONFIG_PATH.lstrip(os.path.sep))
puse = portage.grabdict_package(
os.path.join(abs_user_config, package.use), recursive = 1)
pkeywords = portage.grabdict_package(
os.path.join(abs_user_config, package.keywords), recursive = 1)
pmask = defaultdict(list)
punmask = defaultdict(list)
for x in portage.grabfile_package(
os.path.join(abs_user_config, package.mask), recursive = 1):
cp = portage.dep_getkey(x)
pmask[cp].append(x)
for x in portage.grabfile_package(
os.path.join(abs_user_config, package.unmask), recursive = 1):
cp = portage.dep_getkey(x)
punmask[cp].append(x)
print(package.use:)
for atom, flags in sorted(puse.items(), key = lambda x: x[0]):
print( %s %s % (atom, .join(flags)))
print()
print(package.keywords:)
for atom, kw in sorted(pkeywords.items(), key = lambda x: x[0]):
print( %s %s % (atom, .join(kw)))
print()
print(package.mask:)
for cp, atoms in sorted(pmask.items(), key = lambda x: x[0]):
print( %s %s % (cp, .join(atoms)))
print()
print(package.unmask:)
for cp, atoms in sorted(punmask.items(), key = lambda x: x[0]):
print( %s %s % (cp, .join(atoms)))
print()
def dump_world_set(settings, db):
setconf =