/[collab-qa]/udd/udd/upload_history_gatherer.py
ViewVC logotype

Contents of /udd/udd/upload_history_gatherer.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1037 - (show annotations) (download) (as text)
Sat Aug 9 16:32:42 2008 UTC (4 years, 10 months ago) by neronus-guest
Original Path: udd/src/udd/upload_history_gatherer.py
File MIME type: text/x-python
File size: 1977 byte(s)
Configuration checking is a little less ugly now
1 # Last-Modified: <Sat 09 Aug 2008 18:32:29 CEST>
2 # This file is part of the Ultimate Debian Database Project
3
4 from gatherer import gatherer
5 import aux
6 from glob import glob
7 import gzip
8 import psycopg2
9 import sys
10
11 date_translation = {
12 'Deb': 'Feb',
13 'Augl': 'Aug',
14 'Fev': 'Feb' }
15
16 def get_gatherer(config, connection):
17 return upload_history_gatherer(config, connection)
18
19 class upload_history_gatherer(gatherer):
20 def __init__(self, connection, config):
21 gatherer.__init__(self, connection, config)
22
23 def run(self, source):
24 if not 'path' in self.config[source]:
25 raise aux.ConfigException('path not specified for source ' + source)
26 path = self.config[source]['path']
27
28 cursor = self.cursor()
29
30 cursor.execute("DELETE FROM upload_history")
31
32 cursor.execute("PREPARE uh_insert AS INSERT INTO upload_history VALUES \
33 ($1, $2, $3, $4, $5, $6, $7, $8)")
34
35 for name in glob(path + '/debian-devel-*'):
36 print name
37 f = None
38 if name.endswith(".gz"):
39 f = gzip.open(name)
40 else:
41 f = open(name)
42
43 current = {}
44 last_field = None
45 line_count = 0
46 for line in f:
47 line_count += 1
48 line = line.strip()
49 # Stupid multi-line maintainer fields *grml*
50 if line == '':
51 query = "EXECUTE uh_insert(%(Source)s, %(Version)s, %(Date)s, %(Changed-By)s, \
52 %(Maintainer)s, %(NMU)s, %(Key)s, %(Signed-By)s)" % current
53 try:
54 cursor.execute(query)
55 except psycopg2.ProgrammingError, s:
56 print "Error at line %d of file %s" % (line_count, name)
57 raise
58 current = {}
59 last_field = None
60 continue
61
62 if line.find(':') == -1:
63 if not last_field:
64 raise Exception, "Format error on line " + line_count + "of file " + name
65 current[last_field] += line
66 continue
67
68
69 (field, data) = line.split(':', 1)
70 data = data.strip()
71
72 if field != 'NMU':
73 current[field] = aux.quote(data)
74 else:
75 current[field] = data
76
77 last_field = field
78
79 cursor.execute("DEALLOCATE uh_insert")

  ViewVC Help
Powered by ViewVC 1.1.5