~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
#
11626.3.17 by Curtis Hovey
Updated copyright.
3
# Copyright 2009-2010 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
11626.3.12 by Curtis Hovey
Cross fingers and toes and hope for the best--remove all glob imports of bugs from
12
from lp.registry.model.person import Person
13
from lp.registry.model.teammembership import TeamParticipation
14
3691.315.1 by kiko
Add a script to list all references to a certain Person tuple, script originally from Salgado.
15
16
person_handle = sys.argv[1]
17
txn = initZopeless()
18
try:
19
    int(person_handle)
20
except ValueError:
21
    if "@" in person_handle:
22
        person = Person.selectOne("EmailAddress.person = Person.id AND "
23
                               "emailaddress.email = %s" % person_handle)
24
    else:
25
        person = Person.selectOneBy(name=person_handle)
26
else:
27
    person = Person.selectOneBy(id=person_handle)
28
29
if person is None:
30
    print "Person %s not found" % person_handle
31
    sys.exit(1)
32
33
34
skip = []
35
cur = cursor()
36
references = list(postgresql.listReferences(cur, 'person', 'id'))
37
38
print ("Listing references for %s (ID %s, preferred email %s):\n" %
39
       (person.name, person.id,
40
        person.preferredemail and person.preferredemail.email))
41
for src_tab, src_col, ref_tab, ref_col, updact, delact in references:
42
    if (src_tab, src_col) in skip:
43
        continue
44
    query = "SELECT id FROM %s WHERE %s=%s" % (src_tab, src_col, person.id)
45
    cur.execute(query)
46
    rows = cur.fetchall()
47
    for row in rows:
48
        if src_tab.lower() == 'teamparticipation':
49
            tp = TeamParticipation.selectOneBy(
50
                personID=person.id, teamID=person.id)
51
            if tp.id == row[0]:
52
                # Every person has a teamparticipation entry for itself,
53
                # and we already know this. No need to output it, then.
54
                continue
55
        print ("\tColumn %s of table %s with id %s points to this "
56
               "person." % (src_col, src_tab, row[0]))
57
58
print