~launchpad-pqm/launchpad/devel

10637.3.1 by Guilherme Salgado
Use the default python version instead of a hard-coded version
1
#!/usr/bin/python -S
8452.3.3 by Karl Fogel
* utilities/: Add copyright header block to source files that were
2
#
8687.15.2 by Karl Fogel
In files modified by r8688, change "<YEARS>" to "2009", as per
3
# Copyright 2009 Canonical Ltd.  This software is licensed under the
8687.15.3 by Karl Fogel
Shorten the copyright header block to two lines.
4
# GNU Affero General Public License version 3 (see the file LICENSE).
8452.3.3 by Karl Fogel
* utilities/: Add copyright header block to source files that were
5
10303.1.1 by Gary Poster
use newest version of zc.buildout
6
import _pythonpath
7
3691.315.1 by kiko
Add a script to list all references to a certain Person tuple, script originally from Salgado.
8
import sys
9
from canonical.lp import initZopeless
10
from canonical.database import postgresql
11
from canonical.database.sqlbase import cursor
12
from canonical.launchpad.database import Person, TeamParticipation
13
14
person_handle = sys.argv[1]
15
txn = initZopeless()
16
try:
17
    int(person_handle)
18
except ValueError:
19
    if "@" in person_handle:
20
        person = Person.selectOne("EmailAddress.person = Person.id AND "
21
                               "emailaddress.email = %s" % person_handle)
22
    else:
23
        person = Person.selectOneBy(name=person_handle)
24
else:
25
    person = Person.selectOneBy(id=person_handle)
26
27
if person is None:
28
    print "Person %s not found" % person_handle
29
    sys.exit(1)
30
31
32
skip = []
33
cur = cursor()
34
references = list(postgresql.listReferences(cur, 'person', 'id'))
35
36
print ("Listing references for %s (ID %s, preferred email %s):\n" %
37
       (person.name, person.id,
38
        person.preferredemail and person.preferredemail.email))
39
for src_tab, src_col, ref_tab, ref_col, updact, delact in references:
40
    if (src_tab, src_col) in skip:
41
        continue
42
    query = "SELECT id FROM %s WHERE %s=%s" % (src_tab, src_col, person.id)
43
    cur.execute(query)
44
    rows = cur.fetchall()
45
    for row in rows:
46
        if src_tab.lower() == 'teamparticipation':
47
            tp = TeamParticipation.selectOneBy(
48
                personID=person.id, teamID=person.id)
49
            if tp.id == row[0]:
50
                # Every person has a teamparticipation entry for itself,
51
                # and we already know this. No need to output it, then.
52
                continue
53
        print ("\tColumn %s of table %s with id %s points to this "
54
               "person." % (src_col, src_tab, row[0]))
55
56
print
57