~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to utilities/list-person-references.py

merge from RF

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
import sys
 
3
from canonical.lp import initZopeless
 
4
from canonical.database import postgresql
 
5
from canonical.database.sqlbase import cursor
 
6
from canonical.launchpad.database import Person, TeamParticipation
 
7
 
 
8
person_handle = sys.argv[1]
 
9
txn = initZopeless()
 
10
try:
 
11
    int(person_handle)
 
12
except ValueError:
 
13
    if "@" in person_handle:
 
14
        person = Person.selectOne("EmailAddress.person = Person.id AND "
 
15
                               "emailaddress.email = %s" % person_handle)
 
16
    else:
 
17
        person = Person.selectOneBy(name=person_handle)
 
18
else:
 
19
    person = Person.selectOneBy(id=person_handle)
 
20
 
 
21
if person is None:
 
22
    print "Person %s not found" % person_handle
 
23
    sys.exit(1)
 
24
 
 
25
 
 
26
skip = []
 
27
cur = cursor()
 
28
references = list(postgresql.listReferences(cur, 'person', 'id'))
 
29
 
 
30
print ("Listing references for %s (ID %s, preferred email %s):\n" %
 
31
       (person.name, person.id,
 
32
        person.preferredemail and person.preferredemail.email))
 
33
for src_tab, src_col, ref_tab, ref_col, updact, delact in references:
 
34
    if (src_tab, src_col) in skip:
 
35
        continue
 
36
    query = "SELECT id FROM %s WHERE %s=%s" % (src_tab, src_col, person.id)
 
37
    cur.execute(query)
 
38
    rows = cur.fetchall()
 
39
    for row in rows:
 
40
        if src_tab.lower() == 'teamparticipation':
 
41
            tp = TeamParticipation.selectOneBy(
 
42
                personID=person.id, teamID=person.id)
 
43
            if tp.id == row[0]:
 
44
                # Every person has a teamparticipation entry for itself,
 
45
                # and we already know this. No need to output it, then.
 
46
                continue
 
47
        print ("\tColumn %s of table %s with id %s points to this "
 
48
               "person." % (src_col, src_tab, row[0]))
 
49
 
 
50
print
 
51