3
# Copyright 2009 Canonical Ltd. This software is licensed under the
4
# GNU Affero General Public License version 3 (see the file LICENSE).
11
# pylint: disable-msg=W0403
14
from canonical.config import config
15
from canonical.lp import initZopeless
16
from canonical.launchpad.scripts import (
17
execute_zcml_for_scripts, logger_options, logger)
18
from canonical.launchpad.webapp.interaction import setupInteractionByEmail
20
from canonical.launchpad.scripts import bugzilla
23
def make_connection(options):
25
if options.db_name is not None:
26
kws['db'] = options.db_name
27
if options.db_user is not None:
28
kws['user'] = options.db_user
29
if options.db_password is not None:
30
kws['passwd'] = options.db_passwd
31
if options.db_host is not None:
32
kws['host'] = options.db_host
34
return MySQLdb.connect(**kws)
37
parser = optparse.OptionParser(
38
description=("This script imports bugs from a Bugzilla "
41
parser.add_option('--component', metavar='COMPONENT', action='append',
42
help='Limit to this bugzilla component',
43
type='string', dest='component', default=[])
44
parser.add_option('--status', metavar='STATUS,...', action='store',
45
help='Only import bugs with the given status',
46
type='string', dest='status',
49
# MySQL connection details
50
parser.add_option('-d', '--dbname', metavar='DB', action='store',
51
help='The MySQL database name',
52
type='string', dest='db_name', default='bugs_warty')
53
parser.add_option('-U', '--username', metavar='USER', action='store',
54
help='The MySQL user name',
55
type='string', dest='db_user', default=None)
56
parser.add_option('-p', '--password', metavar='PASSWORD', action='store',
57
help='The MySQL password',
58
type='string', dest='db_password', default=None)
59
parser.add_option('-H', '--host', metavar='HOST', action='store',
60
help='The MySQL database host',
61
type='string', dest='db_host', default=None)
64
logger_options(parser, logging.INFO)
66
options, args = parser.parse_args(argv[1:])
67
if options.status is not None:
68
options.status = options.status.split(',')
72
logger(options, 'canonical.launchpad.scripts.bugzilla')
79
config.push('send_email_data', send_email_data)
81
execute_zcml_for_scripts()
83
setupInteractionByEmail('bug-importer@launchpad.net')
85
db = make_connection(options)
86
bz = bugzilla.Bugzilla(db)
90
component=options.component,
91
status=options.status)
93
bz.processDuplicates(ztm)
94
config.pop('send_email_data')
96
if __name__ == '__main__':
97
sys.exit(main(sys.argv))