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).
|
|
2701.1.13
by James Henstridge
treat comments,etc as UTF-8. fix up option parsing in import script |
5 |
|
6 |
import sys |
|
2701.1.5
by James Henstridge
add some basic logging to the bugzilla module |
7 |
import logging |
2701.1.13
by James Henstridge
treat comments,etc as UTF-8. fix up option parsing in import script |
8 |
import optparse |
2701.1.5
by James Henstridge
add some basic logging to the bugzilla module |
9 |
import MySQLdb |
10 |
||
7178.3.1
by Curtis Hovey
Remove that last of the callsites that mutate the config. |
11 |
# pylint: disable-msg=W0403
|
2701.1.7
by James Henstridge
extract actual mysql stuff into a separate class so it can be replaced |
12 |
import _pythonpath |
13 |
||
2701.1.41
by James Henstridge
Run script as bugzilla-importer user |
14 |
from canonical.config import config |
2701.1.5
by James Henstridge
add some basic logging to the bugzilla module |
15 |
from canonical.lp import initZopeless |
2701.1.13
by James Henstridge
treat comments,etc as UTF-8. fix up option parsing in import script |
16 |
from canonical.launchpad.scripts import ( |
17 |
execute_zcml_for_scripts, logger_options, logger) |
|
10721.2.7
by Francis J. Lacoste
Remove use of login and login_person from production code. |
18 |
from canonical.launchpad.webapp.interaction import setupInteractionByEmail |
2701.1.5
by James Henstridge
add some basic logging to the bugzilla module |
19 |
|
20 |
from canonical.launchpad.scripts import bugzilla |
|
21 |
||
2701.1.13
by James Henstridge
treat comments,etc as UTF-8. fix up option parsing in import script |
22 |
|
23 |
def make_connection(options): |
|
24 |
kws = {} |
|
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 |
|
33 |
||
34 |
return MySQLdb.connect(**kws) |
|
7161.1.10
by Gary Poster
all ftests should be passing now. Only page tests--six of them--to go, as far as I know. |
35 |
|
2701.1.13
by James Henstridge
treat comments,etc as UTF-8. fix up option parsing in import script |
36 |
def main(argv): |
37 |
parser = optparse.OptionParser( |
|
7178.3.1
by Curtis Hovey
Remove that last of the callsites that mutate the config. |
38 |
description=("This script imports bugs from a Bugzilla " |
39 |
"into Launchpad.")) |
|
2701.1.13
by James Henstridge
treat comments,etc as UTF-8. fix up option parsing in import script |
40 |
|
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', |
|
2701.1.32
by James Henstridge
By default, import bugs with all statuses |
47 |
default=None) |
2701.1.13
by James Henstridge
treat comments,etc as UTF-8. fix up option parsing in import script |
48 |
|
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) |
|
62 |
||
63 |
# logging options
|
|
64 |
logger_options(parser, logging.INFO) |
|
7178.3.1
by Curtis Hovey
Remove that last of the callsites that mutate the config. |
65 |
|
2701.1.13
by James Henstridge
treat comments,etc as UTF-8. fix up option parsing in import script |
66 |
options, args = parser.parse_args(argv[1:]) |
2701.1.32
by James Henstridge
By default, import bugs with all statuses |
67 |
if options.status is not None: |
68 |
options.status = options.status.split(',') |
|
69 |
else: |
|
70 |
options.status = [] |
|
2701.1.13
by James Henstridge
treat comments,etc as UTF-8. fix up option parsing in import script |
71 |
|
72 |
logger(options, 'canonical.launchpad.scripts.bugzilla') |
|
73 |
||
2701.1.41
by James Henstridge
Run script as bugzilla-importer user |
74 |
# don't send email
|
7178.3.1
by Curtis Hovey
Remove that last of the callsites that mutate the config. |
75 |
send_email_data = """ |
76 |
[zopeless]
|
|
77 |
send_email: False
|
|
78 |
"""
|
|
79 |
config.push('send_email_data', send_email_data) |
|
80 |
||
5821.5.14
by James Henstridge
Run execute_zcml_for_scripts() before initZopeless() in many tests. |
81 |
execute_zcml_for_scripts() |
2701.1.13
by James Henstridge
treat comments,etc as UTF-8. fix up option parsing in import script |
82 |
ztm = initZopeless() |
10721.2.7
by Francis J. Lacoste
Remove use of login and login_person from production code. |
83 |
setupInteractionByEmail('bug-importer@launchpad.net') |
2701.1.13
by James Henstridge
treat comments,etc as UTF-8. fix up option parsing in import script |
84 |
|
85 |
db = make_connection(options) |
|
86 |
bz = bugzilla.Bugzilla(db) |
|
87 |
||
2701.1.51
by James Henstridge
Revert method name changes in rev 2747 in light of decision at meeting. |
88 |
bz.importBugs(ztm, |
89 |
product=['Ubuntu'], |
|
90 |
component=options.component, |
|
91 |
status=options.status) |
|
2701.1.13
by James Henstridge
treat comments,etc as UTF-8. fix up option parsing in import script |
92 |
|
2701.1.51
by James Henstridge
Revert method name changes in rev 2747 in light of decision at meeting. |
93 |
bz.processDuplicates(ztm) |
7178.3.1
by Curtis Hovey
Remove that last of the callsites that mutate the config. |
94 |
config.pop('send_email_data') |
2701.1.31
by James Henstridge
Add code to process the bugzilla duplicates table, and import the data into |
95 |
|
2701.1.13
by James Henstridge
treat comments,etc as UTF-8. fix up option parsing in import script |
96 |
if __name__ == '__main__': |
97 |
sys.exit(main(sys.argv)) |