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