Re: [gentoo-portage-dev] Portage API questions

2009-07-10 Thread Sebastian Pipping
in case anybody wants to have a look what i made of that you can find my
current sources over here:

http://git.goodpoint.de/?p=smolt-gentoo.git;a=tree;f=client/distros/gentoo;hb=refs/heads/gentoo

thanks again to andy for his code and zac for help on IRC.
any feedback and code review is very welcome, better off-list though.



sebastian




Re: [gentoo-portage-dev] Portage API questions

2009-07-05 Thread Sebastian Pipping
Thanks guys, very helpful!

More questions later.



Sebastian



Re: [gentoo-portage-dev] Portage API questions

2009-06-29 Thread Mounir Lamouri
Hi,

My 2 cents:

Sebastian Pipping wrote:
   - installed packages with version numbers
   
vardb = portage.db[portage.settings[ROOT]][vartree].dbapi
vardb.cpv_all() will return cat/package-version
vardb.cp_all() will return cat/package
of installed packages

   - entries for /var/lib/portage/world
   
You should think about world + system :

for s in (system, world):
set = portage._sets.base.InternalPackageSet(
initial_atoms=rootconfig.setconfig.getSetAtoms(s))
for cp in set:
print cp # print cat/package in world/system

Good luck :)

Mounir




Re: [gentoo-portage-dev] Portage API questions

2009-06-29 Thread Andy Kittner

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 = 

[gentoo-portage-dev] Portage API questions

2009-06-28 Thread Sebastian Pipping
Hello!


As part of my Gentoo Google Summer of Code activities
I am making use of the Portage Python API.  As some of
you can tell much quicker than me

  - if the API can answer question X, and

  - where to find functionality for task Y

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
  - 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

So my two questions are:

  - Which of these sets of data can be obtained
through the Portage API, which of them not?

  - Which classes and functions should I look at?

That's it for now.
I'm thankful for any helpful bytes.



Sebastian