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