~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to scripts/migrate-bugzilla-initialcontacts.py

  • Committer: Colin Watson
  • Date: 2011-08-19 00:25:11 UTC
  • mfrom: (7675.1045.728 db-devel)
  • mto: This revision was merged to the branch mainline in revision 13909.
  • Revision ID: cjwatson@canonical.com-20110819002511-0x8hrqs1ckiqk53g
merge db-devel

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/python -S
2
 
#
3
 
# Copyright 2009 Canonical Ltd.  This software is licensed under the
4
 
# GNU Affero General Public License version 3 (see the file LICENSE).
5
 
 
6
 
import logging
7
 
import MySQLdb
8
 
 
9
 
import _pythonpath
10
 
 
11
 
from zope.component import getUtility
12
 
 
13
 
from canonical.lp import initZopeless
14
 
from canonical.launchpad.scripts import execute_zcml_for_scripts
15
 
from canonical.launchpad.interfaces.emailaddress import IEmailAddressSet
16
 
from lp.app.interfaces.launchpad import ILaunchpadCelebrities
17
 
from lp.app.errors import NotFoundError
18
 
from lp.registry.interfaces.person import IPersonSet
19
 
 
20
 
 
21
 
execute_zcml_for_scripts()
22
 
ztm = initZopeless()
23
 
logging.basicConfig(level=logging.INFO)
24
 
 
25
 
ubuntu = getUtility(ILaunchpadCelebrities).ubuntu
26
 
techboard = getUtility(IPersonSet).getByName('techboard')
27
 
 
28
 
def getPerson(email, realname):
29
 
    # The debzilla user acts as a placeholder for "no specific maintainer".
30
 
    # We don't create a bug contact record for it.
31
 
    if email is None or email == 'debzilla@ubuntu.com':
32
 
        return None
33
 
 
34
 
    personset = getUtility(IPersonSet)
35
 
    person = personset.getByEmail(email)
36
 
    if person:
37
 
        return person
38
 
 
39
 
    # we mark the bugzilla email as preferred email, since it has been
40
 
    # validated there.
41
 
    if email.endswith('@lists.ubuntu.com'):
42
 
        logging.info('creating team for %s (%s)', email, realname)
43
 
        person = personset.newTeam(techboard, email[:-17], realname)
44
 
        email = getUtility(IEmailAddressSet).new(email, person.id)
45
 
        person.setPreferredEmail(email)
46
 
    else:
47
 
        logging.info('creating person for %s (%s)', email, realname)
48
 
        person, email = personset.createPersonAndEmail(email,
49
 
                                                       displayname=realname)
50
 
        person.setPreferredEmail(email)
51
 
 
52
 
    return person
53
 
 
54
 
 
55
 
conn = MySQLdb.connect(db='bugs_warty')
56
 
cursor = conn.cursor()
57
 
 
58
 
# big arse query that gets all the default assignees and QA contacts:
59
 
cursor.execute(
60
 
    "SELECT components.name, owner.login_name, owner.realname, "
61
 
    "    qa.login_name, qa.realname "
62
 
    "  FROM components "
63
 
    "    JOIN products ON components.product_id = products.id "
64
 
    "    LEFT JOIN profiles AS owner ON components.initialowner = owner.userid"
65
 
    "    LEFT JOIN profiles AS qa ON components.initialqacontact = qa.userid "
66
 
    "  WHERE  products.name = 'Ubuntu'")
67
 
 
68
 
for (component, owneremail, ownername, qaemail, qaname) in cursor.fetchall():
69
 
    logging.info('Processing %s', component)
70
 
    try:
71
 
        srcpkgname, binpkgname = ubuntu.getPackageNames(component)
72
 
    except NotFoundError, e:
73
 
        logging.warning('could not find package name for "%s": %s', component,
74
 
                        str(e))
75
 
        continue
76
 
 
77
 
    srcpkg = ubuntu.getSourcePackage(srcpkgname)
78
 
 
79
 
    # default assignee => maintainer
80
 
    person = getPerson(owneremail, ownername)
81
 
    if person:
82
 
        if not srcpkg.isBugContact(person):
83
 
            srcpkg.addBugContact(person)
84
 
 
85
 
    # QA contact => maintainer
86
 
    person = getPerson(qaemail, qaname)
87
 
    if person:
88
 
        if not srcpkg.isBugContact(person):
89
 
            srcpkg.addBugContact(person)
90
 
 
91
 
ztm.commit()