/[qa]/trunk/carnivore/carnivore.py
ViewVC logotype

Contents of /trunk/carnivore/carnivore.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1481 - (show annotations) (download) (as text)
Thu Dec 28 15:00:14 2006 UTC (6 years, 4 months ago) by myon
File MIME type: text/x-python
File size: 4093 byte(s)
move carnivore out of data/
1 #!/usr/bin/python
2
3 # Utility functions to use carnivore
4 # Copyright (C) 2006 Jeroen van Wolffelaar <jeroen@wolffelaar.nl>
5 # $Id$
6
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
11
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
21 import os, sys, bsddb, sets
22 import apt_pkg
23
24 carnivore = bsddb.btopen("/org/qa.debian.org/data/carnivore/result.db", "r")
25
26 def join(sep, items):
27 return reduce(lambda a, b: a+sep+b, items)
28
29 class carnivoreEntry:
30 def __init__(self, v):
31 if not isinstance(v, tuple):
32 raise "Not a carnivore typle"
33
34 self.id = v[0]
35 (self.ldap, self.realname, self.gpg, self.email, self.package) = [], [], [], [], []
36 (self.extra, self.expl, self.warnings, self.mia) = [], [], [], []
37 self.gecos = ""
38 self.keyring = {'keyring': [], 'emeritus': [], 'removed': [], 'ldap': []}
39 for item in sets.Set(v[1]+v[2]):
40 if item.startswith("ldap:"):
41 self.ldap.append(item[5:])
42 elif item.startswith("email:"):
43 self.email.append(item[6:])
44 elif item.startswith("realname:"):
45 self.realname.append(item[9:])
46 elif item.startswith("maint:"):
47 self.package.append(item[6:])
48 elif item.startswith("gpg:"):
49 self.gpg.append(item[4:])
50 elif item.startswith("x:"):
51 self.expl.append(item[2:])
52 if item.startswith("x:ldap:gpg:"):
53 self.keyring['ldap'].append(item[11:].split(':')[1])
54 if item.startswith("x:gpg:keyring:"):
55 gpg, ring = item[14:].split(':')
56 self.keyring[ring].append(gpg)
57 if item.startswith("x:ldap:realname:"):
58 self.gecos = item[16:].split(':')[1]
59 else:
60 self.extra.append(item)
61 for ring in self.keyring.values(): ring.sort()
62
63 def getPrettyprintedText(self):
64 text = ""
65 if self.ldap: text += "DD: "+self.gecos+" <"+self.ldap[0]+"@debian.org>\n"
66 if self.realname: text += "Known as: "+", ".join(self.realname)+"\n"
67 if self.email: text += "Using emails: "+", ".join(self.email)+"\n"
68 for k, v in self.keyring.iteritems():
69 for key in v:
70 text += "Key in "+k+": "+key+"\n"
71 p = "0"
72 if self.package and len(self.package) <= 5:
73 p = "%s (%s)" % (len(self.package), ", ".join(self.package))
74 elif self.package:
75 p = "%s (%s)" % (len(self.package), ", ".join(self.package[:4]+["..."]))
76 text += "Packages: %s\n" % p
77 if self.extra:
78 for i in self.extra:
79 text += i + "\n"
80
81 return text
82
83 def search(key):
84 if not carnivore.has_key(key):
85 return []
86 while 1:
87 lastkey = key
88 key = carnivore[key]
89 if key[0] == "(":
90 return [lastkey]
91 elif key[0] == "[":
92 return eval(key)
93
94 def get(key):
95 while 1:
96 key = carnivore[key]
97 if key[0] == "(":
98 return carnivoreEntry(eval(key))
99 elif key[0] == "[":
100 raise "%s is not an id of a real carnivore entry" % key
101
102 class iteritems:
103 def __init__(this):
104 this.iter = carnivore.iteritems()
105 def __iter__(this): return this
106 def next(this):
107 while 1:
108 key, val = this.iter.next()
109 if val[0] == '(':
110 return key, carnivoreEntry(eval(val))
111
112 # vim: et

Properties

Name Value
svn:eol-style native
svn:executable *
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.5