3691.440.15
by James Henstridge
explicitly use python 2.4 in scripts/bug-import.py |
1 |
#!/usr/bin/python2.4
|
3691.440.4
by James Henstridge
driver script |
2 |
# Copyright 2006 Canonical Ltd. All rights reserved.
|
3 |
||
4 |
import logging |
|
5 |
||
7178.3.1
by Curtis Hovey
Remove that last of the callsites that mutate the config. |
6 |
# pylint: disable-msg=W0403
|
3691.440.4
by James Henstridge
driver script |
7 |
import _pythonpath |
8 |
||
9 |
from zope.component import getUtility |
|
10 |
from canonical.config import config |
|
11 |
from canonical.launchpad.interfaces import IProductSet |
|
12 |
||
3691.440.16
by James Henstridge
convert bug-import.py over to new scripts infrastructure |
13 |
from canonical.launchpad.scripts.base import LaunchpadScript |
3691.440.4
by James Henstridge
driver script |
14 |
from canonical.launchpad.scripts.bugimport import BugImporter |
15 |
||
3691.440.16
by James Henstridge
convert bug-import.py over to new scripts infrastructure |
16 |
|
17 |
class BugImportScript(LaunchpadScript): |
|
18 |
||
3691.440.17
by James Henstridge
fix description in bug-import.py help output |
19 |
description = "Import bugs into Launchpad from XML." |
3691.440.16
by James Henstridge
convert bug-import.py over to new scripts infrastructure |
20 |
loglevel = logging.INFO |
21 |
||
22 |
def add_my_options(self): |
|
23 |
self.parser.add_option('-p', '--product', metavar='PRODUCT', |
|
24 |
action='store', |
|
25 |
help='Which product to export', |
|
26 |
type='string', dest='product', default=None) |
|
27 |
self.parser.add_option('--cache', metavar='FILE', action='store', |
|
28 |
help='Cache for bug ID mapping', |
|
29 |
type='string', dest='cache_filename', |
|
30 |
default='bug-map.pickle') |
|
4664.1.1
by Curtis Hovey
Normalized comments for bug 3732. |
31 |
# XXX: jamesh 2007-04-11 bugs=86352
|
3691.440.21
by James Henstridge
add some new coments in response to Bjorn's review |
32 |
# Not verifying users created by a bug import can result in
|
33 |
# problems with mail notification, so should not be used for
|
|
34 |
# imports.
|
|
3691.440.16
by James Henstridge
convert bug-import.py over to new scripts infrastructure |
35 |
self.parser.add_option('--dont-verify-users', dest='verify_users', |
36 |
help="Don't verify newly created users", |
|
37 |
action='store_false', default=True) |
|
38 |
||
39 |
def main(self): |
|
40 |
if self.options.product is None: |
|
41 |
self.parser.error('No product specified') |
|
42 |
if len(self.args) != 1: |
|
43 |
self.parser.error('Please specify a bug XML file to import') |
|
44 |
bugs_filename = self.args[0] |
|
7178.3.1
by Curtis Hovey
Remove that last of the callsites that mutate the config. |
45 |
|
3691.440.16
by James Henstridge
convert bug-import.py over to new scripts infrastructure |
46 |
# don't send email
|
7178.3.1
by Curtis Hovey
Remove that last of the callsites that mutate the config. |
47 |
send_email_data = """ |
48 |
[zopeless]
|
|
49 |
send_email: False
|
|
50 |
"""
|
|
51 |
config.push('send_email_data', send_email_data) |
|
3691.440.16
by James Henstridge
convert bug-import.py over to new scripts infrastructure |
52 |
self.login('bug-importer@launchpad.net') |
7178.3.1
by Curtis Hovey
Remove that last of the callsites that mutate the config. |
53 |
|
3691.440.16
by James Henstridge
convert bug-import.py over to new scripts infrastructure |
54 |
product = getUtility(IProductSet).getByName(self.options.product) |
55 |
if product is None: |
|
56 |
self.parser.error('Product %s does not exist' |
|
57 |
% self.options.product) |
|
58 |
||
59 |
importer = BugImporter(product, bugs_filename, |
|
60 |
self.options.cache_filename, |
|
61 |
verify_users=self.options.verify_users) |
|
62 |
importer.importBugs(self.txn) |
|
7178.3.1
by Curtis Hovey
Remove that last of the callsites that mutate the config. |
63 |
config.pop('send_email_data') |
3691.440.16
by James Henstridge
convert bug-import.py over to new scripts infrastructure |
64 |
|
3691.440.4
by James Henstridge
driver script |
65 |
|
66 |
if __name__ == '__main__': |
|
3691.440.16
by James Henstridge
convert bug-import.py over to new scripts infrastructure |
67 |
script = BugImportScript('canonical.launchpad.scripts.bugimport') |
68 |
script.run() |