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