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 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 |
|
11882.2.2
by Jonathan Lange
Clear up a heck of a lot of imports from canonical.launchpad.interfaces. |
15 |
from canonical.launchpad.interfaces.emailaddress import IEmailAddressSet |
13130.1.22
by Curtis Hovey
Fixed db imports. |
16 |
from lp.app.interfaces.launchpad import ILaunchpadCelebrities |
11270.1.3
by Tim Penhey
Changed NotFoundError imports - gee there were a lot of them. |
17 |
from lp.app.errors import NotFoundError |
11882.2.2
by Jonathan Lange
Clear up a heck of a lot of imports from canonical.launchpad.interfaces. |
18 |
from lp.registry.interfaces.person import IPersonSet |
10409.5.68
by Curtis Hovey
Removed the globs imports from scripts. |
19 |
|
2949.1.1
by James Henstridge
Add migrate-bugzilla-contacts.py script, converted to work with |
20 |
|
5821.5.14
by James Henstridge
Run execute_zcml_for_scripts() before initZopeless() in many tests. |
21 |
execute_zcml_for_scripts() |
2949.1.1
by James Henstridge
Add migrate-bugzilla-contacts.py script, converted to work with |
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) |
|
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) |
45 |
person.setPreferredEmail(email) |
2949.1.1
by James Henstridge
Add migrate-bugzilla-contacts.py script, converted to work with |
46 |
else: |
47 |
logging.info('creating person for %s (%s)', email, realname) |
|
48 |
person, email = personset.createPersonAndEmail(email, |
|
49 |
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) |
50 |
person.setPreferredEmail(email) |
2949.1.1
by James Henstridge
Add migrate-bugzilla-contacts.py script, converted to work with |
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() |