/[gentoo-src]/portage/pym/portagedb.py
Gentoo

Contents of /portage/pym/portagedb.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (show annotations) (download) (as text)
Thu Jan 22 05:51:45 2004 UTC (10 years, 6 months ago) by carpaski
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +1 -1 lines
File MIME type: text/x-python
FILE REMOVED
portage-2.0.50_pre19 (post)
Lots of updates... Module loading code mostly done/ready.
Inherited profiles, major config modifications.

1 # portagedb.py -- module to maintain portage package databases, used by pdb
2 # Copyright (C) Sept 2001, Chris Houser <chouser@bluweb.com>
3 # Distributed under the GNU General Public License
4 # $Header: /home/cvsroot/gentoo-src/portage/pym/portagedb.py,v 1.1 2001/09/15 21:32:21 chouser Exp $
5
6 import string
7 import dbm
8 import pprint
9
10 class DB:
11 def __init__(self, dbfile):
12 self.dbfile = dbfile
13 self.db = None
14
15 def doquery(self, queries):
16 if not self.db: self.db = dbm.open(self.dbfile, 'r') # open db
17 pkghash = {}
18 for query in queries:
19 # look up query
20 try:
21 rec = eval(self.db[query], {}, {})
22 except KeyError:
23 print "Not found: '%s'" % query
24 continue
25 # build original CONTENTS line
26 line = string.join([rec[1]] + [query] + rec[2:], ' ')
27 # store result to return later
28 if pkghash.has_key(rec[0]):
29 pkghash[rec[0]].append(line)
30 else:
31 pkghash[rec[0]] = [line]
32 # print results
33 names = pkghash.keys()
34 names.sort()
35 for pkgname in names:
36 print "%s:" % pkgname
37 for line in pkghash[pkgname]:
38 print " %s" % line
39
40 def storestream(self, stream, pkgname = None):
41 if not self.db: self.db = dbm.open(self.dbfile, 'c') # open db
42 if pkgname: print "Storing %s" % pkgname
43 while 1:
44 line = stream.readline()
45 if line == '': break
46 # parse the CONTENTS line
47 words = string.split(line)
48 # store the package name and CONTENTS line
49 if words[0] == 'pkgname':
50 pkgname = words[1]
51 print "Storing %s" % pkgname
52 elif words[0] != 'dir':
53 rec = [pkgname] + [words[0]] + words[2:]
54 self.db[words[1]] = pprint.pformat(rec)

  ViewVC Help
Powered by ViewVC 1.1.20