Gentoo Archives: gentoo-dev

From: bdharring <bdharring@××××.edu>
To: lafou@×××××××.fr
Cc: gentoo-dev@g.o
Subject: Re: [gentoo-dev] Shell script help - emerge frontend.
Date: Fri, 20 Jun 2003 21:33:46
Message-Id: C558DEB3-A366-11D7-98BE-00306580AC5C@wisc.edu
In Reply to: Re: [gentoo-dev] Shell script help - emerge frontend. by "Philippe Lafoucrière"
1 On Friday, June 20, 2003, at 03:31 PM, Philippe Lafoucrière wrote:
2
3 > Already seen pydoc portage. but many functions aren't documented, and
4 > there's a lot on
5 > info at a time.
6 >
7 > How can I get all the categories (without subpackages)? I mean, I want
8 >
9 > app-emacs
10 > app-emulation
11 > ...
12 >
13 > and not app-emacs/analog app-emacs/apache-mode etc.
14 I'd start pulling apart the various sections of emerge to figure out
15 how it accomplishes everything, but this code (while not guaranteed to
16 be the best way) ought to be what you're after.
17 `
18 #!/usr/bin/python
19 import portage
20 global pdict; pdict = {}
21 global ptree
22 ptree = portage.portagetree()
23 temp = ptree.getallnodes()
24 for entry in temp:
25 base = ''; package = ''
26 (base, package) = string.split(entry, '/')
27 if pdict.has_key(base):
28 pdict[base].append(package)
29 else:
30 pdict[base] = [package]
31 for entry in pdict:
32 print entry
33 `
34 While this is a bit more then you were after (you seemed after just
35 categories), you can isolate out what you need by just grabbing the
36 keys of pdict. This leaves you w/ a hash, w/ lists of each package
37 w/in each key.
38 ~Brian
39
40
41 --
42 gentoo-dev@g.o mailing list