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

Contents of /udd/udd/orphaned_packages_gatherer.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1531 - (show annotations) (download) (as text)
Thu Jul 23 14:05:39 2009 UTC (3 years, 9 months ago) by lucas
File MIME type: text/x-python
File size: 2828 byte(s)
add ANALYZE at the end of all importers to teach pgsql some stats about the data we just imported
1 #!/usr/bin/env python
2
3 """
4 This script imports the list of orphaned, ITAed and RFAed packages into the DB
5 """
6
7 import aux
8 from gatherer import gatherer
9 import re
10 from psycopg2 import IntegrityError
11
12 def get_gatherer(connection, config, source):
13 return orphaned_packages_gatherer(connection, config, source)
14
15 class orphaned_packages_gatherer(gatherer):
16 def __init__(self, connection, config, source):
17 gatherer.__init__(self, connection, config, source)
18 self.assert_my_config('bugs-path', 'table', 'unarchived-table')
19
20 title_re = re.compile('^(ITA|RFA|O): ([^\s]*)( [-]+ (.*))?$')
21 otime_re = re.compile('^<!-- time:([0-9]+) ')
22 chtitle_re = re.compile('^<strong>Changed Bug title to `O:.*$')
23
24 def get_time_orphaned(self, bug):
25 bug = str(bug)
26 dir = bug[4:6]
27 f = open(self.my_config['bugs-path'] + '/spool/db-h/' + dir + '/' + bug + '.log', 'r')
28 otime = None
29 for l in f:
30 m = self.chtitle_re.match(l)
31 if m:
32 return otime
33 m = self.otime_re.match(l)
34 if m:
35 otime = int(m.group(1))
36 return None
37
38 def run(self):
39 #check that the config contains everything we need:
40 for key in ['bugs-path']:
41 if not key in self.my_config:
42 raise aux.ConfigException, "%s not configured for source %s" % (key, source)
43
44 #start harassing the DB, preparing the final inserts and making place
45 #for the new data:
46 cur = self.cursor()
47 cur2 = self.cursor()
48 cur.execute("SELECT id, title, arrival FROM %s WHERE package = 'wnpp' AND status != 'done' AND title ~* '^(ITA|RFA|O):' AND id NOT IN (SELECT id from %s WHERE id > merged_with)" % (self.my_config['unarchived-table'], self.my_config['unarchived-table'] + '_merged_with'))
49 rows = cur.fetchall()
50
51 cur2.execute("DELETE FROM %s" % self.my_config['table'])
52 cur2.execute("PREPARE opkgs_insert AS INSERT INTO %s (source, type, bug, description, orphaned_time) VALUES ($1, $2, $3, $4, $5)" % self.my_config['table'])
53
54 for row in rows:
55 m = self.title_re.match(row[1])
56 if m == None:
57 print "Invalid bug: #" + str(row[0]) + ": " + row[1]
58 else:
59 #print "bug: #" + str(row[0]) + ": " + row[1]
60 time_orphaned = self.get_time_orphaned(row[0])
61 try:
62 if time_orphaned == None:
63 cur2.execute("EXECUTE opkgs_insert(%s,%s,%s,%s,%s)", (
64 m.group(2), m.group(1), row[0],
65 m.group(4), row[2]))
66 else:
67 cur2.execute("EXECUTE opkgs_insert(%s,%s,%s,%s,%s::abstime)", (
68 m.group(2), m.group(1), row[0],
69 m.group(4), time_orphaned))
70 except IntegrityError, message:
71 print "Integrity Error inserting bug " + str(row[0]) + " " + m.group(2)
72 continue
73 cur2.execute("ANALYZE %s" % self.my_config['table'])
74
75 # vim:set et tabstop=2:

  ViewVC Help
Powered by ViewVC 1.1.5