| 1 |
#!/usr/bin/env python
|
| 2 |
|
| 3 |
"""
|
| 4 |
This script imports some fields from the Debian LDAP into the database
|
| 5 |
"""
|
| 6 |
|
| 7 |
from aux import quote
|
| 8 |
from gatherer import gatherer
|
| 9 |
import re
|
| 10 |
import psycopg2
|
| 11 |
import time
|
| 12 |
import locale
|
| 13 |
|
| 14 |
def get_gatherer(connection, config, source):
|
| 15 |
return wannabuild_gatherer(connection, config, source)
|
| 16 |
|
| 17 |
class wannabuild_gatherer(gatherer):
|
| 18 |
|
| 19 |
def __init__(self, connection, config, source):
|
| 20 |
gatherer.__init__(self, connection, config, source)
|
| 21 |
self.assert_my_config()
|
| 22 |
|
| 23 |
def run(self):
|
| 24 |
#start harassing the DB, preparing the final inserts and making place
|
| 25 |
#for the new data:
|
| 26 |
cur = self.cursor()
|
| 27 |
|
| 28 |
cur.execute("DELETE FROM wannabuild")
|
| 29 |
|
| 30 |
cur.execute("""PREPARE wb_insert
|
| 31 |
AS INSERT INTO wannabuild
|
| 32 |
(architecture, source, distribution, version, state, installed_version, previous_state, state_change, binary_nmu_version, notes)
|
| 33 |
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)""")
|
| 34 |
|
| 35 |
wbconn = psycopg2.connect(self.my_config['wbdb'])
|
| 36 |
wbcur = wbconn.cursor()
|
| 37 |
|
| 38 |
entries = []
|
| 39 |
for arch in self.my_config['archs']:
|
| 40 |
wbcur.execute("SELECT package, distribution, version, state, installed_version, previous_state, state_change, binary_nmu_version, notes FROM \"%s_public\".packages" % arch)
|
| 41 |
for row in wbcur.fetchall():
|
| 42 |
row = list(row)
|
| 43 |
if row[6] != None:
|
| 44 |
t = None
|
| 45 |
try:
|
| 46 |
t = time.strptime(row[6], "%Y %b %d %H:%M:%S")
|
| 47 |
except ValueError:
|
| 48 |
# we couldn't parse the date in english. But since Debian is
|
| 49 |
# the universal operating system, let's try a few other
|
| 50 |
# popular languages in Debian ;)
|
| 51 |
for lang in [ 'de_DE.UTF-8', 'fr_FR.UTF-8', 'fi_FI.UTF-8']:
|
| 52 |
try:
|
| 53 |
locale.setlocale(locale.LC_TIME, lang)
|
| 54 |
t = time.strptime(row[6], "%Y %b %d %H:%M:%S")
|
| 55 |
locale.resetlocale()
|
| 56 |
continue
|
| 57 |
except ValueError:
|
| 58 |
locale.resetlocale()
|
| 59 |
if t == None:
|
| 60 |
print "Parsing failed in all lang: %s %s - %s"%(row[0], row[1], row[6])
|
| 61 |
row[6] = None
|
| 62 |
else:
|
| 63 |
row[6] = time.strftime("%a, %d %b %Y %H:%M:%S +0000", t)
|
| 64 |
entries.append([arch] + row)
|
| 65 |
cur.executemany("EXECUTE wb_insert (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)", entries)
|
| 66 |
entries = []
|
| 67 |
cur.execute("DEALLOCATE wb_insert")
|
| 68 |
cur.execute("ANALYZE wannabuild")
|
| 69 |
|
| 70 |
if __name__ == '__main__':
|
| 71 |
main()
|
| 72 |
|
| 73 |
# vim:set et tabstop=2:
|