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

Contents of /udd/udd/ldap_gatherer.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1764 - (show annotations) (download) (as text)
Mon Aug 2 18:15:59 2010 UTC (2 years, 9 months ago) by lucas
File MIME type: text/x-python
File size: 2321 byte(s)
various udd changes
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 ldap
10 import re
11
12 def get_gatherer(connection, config, source):
13 return ldap_gatherer(connection, config, source)
14
15 class ldap_gatherer(gatherer):
16
17 def __init__(self, connection, config, source):
18 gatherer.__init__(self, connection, config, source)
19 self.assert_my_config()
20
21 def run(self):
22 #start harassing the DB, preparing the final inserts and making place
23 #for the new data:
24 cur = self.cursor()
25
26 cur.execute("DELETE FROM ldap")
27
28 cur.execute("""PREPARE ldap_insert
29 AS INSERT INTO ldap
30 (uid, login, cn, sn, expire, location, country, activity_from, activity_from_info, activity_pgp, activity_pgp_info, gecos, birthdate, gender, fingerprint)
31 VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15)""")
32
33 entries = []
34 con = ldap.initialize('ldap://db.debian.org')
35 for e in con.search_s('ou=users,dc=debian,dc=org', ldap.SCOPE_SUBTREE, '(&(objectclass=debianAccount)(objectclass=debianDeveloper))'):
36 f = e[1]
37 if 'activity-from' in f:
38 af_date, af_info = f['activity-from'][0].split('] ',2)
39 af_date = af_date[1:]
40 else:
41 af_date = None
42 af_info = None
43 if 'activity-pgp' in f:
44 ag_date, ag_info = f['activity-pgp'][0].split('] ',2)
45 ag_date = ag_date[1:]
46 else:
47 ag_date = None
48 ag_info = None
49
50
51 birthdate = f['birthDate'][0] if 'birthDate' in f else None
52 gecos = f['gecos'][0] if 'gecos' in f else None
53 gender = int(f['gender'][0]) if 'gender' in f else None
54 loc = f['l'][0] if 'l' in f else None
55 country = f['c'][0] if 'c' in f else None
56 fp = f['keyFingerPrint'][0] if 'keyFingerPrint' in f else None
57 expired = ('shadowExpire' in f)
58
59 entries.append((int(f['uidNumber'][0]), f['uid'][0], f['cn'][0], f['sn'][0], expired, loc, country, af_date, af_info, ag_date, ag_info, gecos, birthdate, gender, fp))
60
61 cur.executemany("EXECUTE ldap_insert (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)", entries)
62 cur.execute("DEALLOCATE ldap_insert")
63 cur.execute("ANALYZE ldap")
64
65 if __name__ == '__main__':
66 main()
67
68 # vim:set et tabstop=2:

  ViewVC Help
Powered by ViewVC 1.1.5