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 |
#
|
14027.3.2
by Jeroen Vermeulen
Merge devel, resolve conflicts. |
3 |
# Copyright 2009-2011 Canonical Ltd. This software is licensed under the
|
8687.15.22
by Karl Fogel
Add the copyright header block to the remaining .py files. |
4 |
# GNU Affero General Public License version 3 (see the file LICENSE).
|
3691.440.4
by James Henstridge
driver script |
5 |
|
14027.3.2
by Jeroen Vermeulen
Merge devel, resolve conflicts. |
6 |
import logging |
7 |
||
7178.3.1
by Curtis Hovey
Remove that last of the callsites that mutate the config. |
8 |
# pylint: disable-msg=W0403
|
3691.440.4
by James Henstridge
driver script |
9 |
import _pythonpath |
10 |
from zope.component import getUtility |
|
14027.3.2
by Jeroen Vermeulen
Merge devel, resolve conflicts. |
11 |
|
3691.440.4
by James Henstridge
driver script |
12 |
from canonical.config import config |
14027.3.2
by Jeroen Vermeulen
Merge devel, resolve conflicts. |
13 |
from lp.bugs.scripts.bugimport import BugImporter |
11882.2.2
by Jonathan Lange
Clear up a heck of a lot of imports from canonical.launchpad.interfaces. |
14 |
from lp.registry.interfaces.product import IProductSet |
8356.1.9
by Leonard Richardson
Renamed the base script module in scripts/, which module_rename.py didn't touch because it wasn't under lib/. |
15 |
from lp.services.scripts.base import LaunchpadScript |
3691.440.4
by James Henstridge
driver script |
16 |
|
3691.440.16
by James Henstridge
convert bug-import.py over to new scripts infrastructure |
17 |
|
18 |
class BugImportScript(LaunchpadScript): |
|
19 |
||
3691.440.17
by James Henstridge
fix description in bug-import.py help output |
20 |
description = "Import bugs into Launchpad from XML." |
3691.440.16
by James Henstridge
convert bug-import.py over to new scripts infrastructure |
21 |
loglevel = logging.INFO |
22 |
||
23 |
def add_my_options(self): |
|
12043.8.2
by Peter Clifton
scripts/bug-import.py: Reformat self.parser.add_option() lines |
24 |
self.parser.add_option( |
25 |
'-p', '--product', metavar='PRODUCT', action='store', |
|
26 |
help='Which product to export', type='string', dest='product', |
|
27 |
default=None) |
|
28 |
self.parser.add_option( |
|
29 |
'--cache', metavar='FILE', action='store', |
|
30 |
help='Cache for bug ID mapping', type='string', |
|
31 |
dest='cache_filename', default='bug-map.pickle') |
|
4664.1.1
by Curtis Hovey
Normalized comments for bug 3732. |
32 |
# XXX: jamesh 2007-04-11 bugs=86352
|
3691.440.21
by James Henstridge
add some new coments in response to Bjorn's review |
33 |
# Not verifying users created by a bug import can result in
|
34 |
# problems with mail notification, so should not be used for
|
|
35 |
# imports.
|
|
12043.8.2
by Peter Clifton
scripts/bug-import.py: Reformat self.parser.add_option() lines |
36 |
self.parser.add_option( |
37 |
'--dont-verify-users', dest='verify_users', |
|
38 |
help="Don't verify newly created users", action='store_false', |
|
39 |
default=True) |
|
3691.440.16
by James Henstridge
convert bug-import.py over to new scripts infrastructure |
40 |
|
41 |
def main(self): |
|
42 |
if self.options.product is None: |
|
43 |
self.parser.error('No product specified') |
|
44 |
if len(self.args) != 1: |
|
45 |
self.parser.error('Please specify a bug XML file to import') |
|
46 |
bugs_filename = self.args[0] |
|
7178.3.1
by Curtis Hovey
Remove that last of the callsites that mutate the config. |
47 |
|
3691.440.16
by James Henstridge
convert bug-import.py over to new scripts infrastructure |
48 |
# don't send email
|
7178.3.1
by Curtis Hovey
Remove that last of the callsites that mutate the config. |
49 |
send_email_data = """ |
14022.2.7
by William Grant
Fix two zopeless config overlays in scripts. |
50 |
[immediate_mail]
|
7178.3.1
by Curtis Hovey
Remove that last of the callsites that mutate the config. |
51 |
send_email: False
|
52 |
"""
|
|
53 |
config.push('send_email_data', send_email_data) |
|
3691.440.16
by James Henstridge
convert bug-import.py over to new scripts infrastructure |
54 |
self.login('bug-importer@launchpad.net') |
7178.3.1
by Curtis Hovey
Remove that last of the callsites that mutate the config. |
55 |
|
3691.440.16
by James Henstridge
convert bug-import.py over to new scripts infrastructure |
56 |
product = getUtility(IProductSet).getByName(self.options.product) |
57 |
if product is None: |
|
58 |
self.parser.error('Product %s does not exist' |
|
59 |
% self.options.product) |
|
60 |
||
8657.3.6
by Graham Binns
BugImporter now accepts a logger in its constructor so that it can be passed the logger by the script that uses it rather than relying on getting a logger using getlogger(). |
61 |
importer = BugImporter( |
62 |
product, bugs_filename, self.options.cache_filename, |
|
12043.8.3
by Peter Clifton
bug-import: Remove the --allow-empty-comments option, check attachments instead |
63 |
verify_users=self.options.verify_users, logger=self.logger) |
3691.440.16
by James Henstridge
convert bug-import.py over to new scripts infrastructure |
64 |
importer.importBugs(self.txn) |
7178.3.1
by Curtis Hovey
Remove that last of the callsites that mutate the config. |
65 |
config.pop('send_email_data') |
3691.440.16
by James Henstridge
convert bug-import.py over to new scripts infrastructure |
66 |
|
3691.440.4
by James Henstridge
driver script |
67 |
|
68 |
if __name__ == '__main__': |
|
3691.440.16
by James Henstridge
convert bug-import.py over to new scripts infrastructure |
69 |
script = BugImportScript('canonical.launchpad.scripts.bugimport') |
70 |
script.run() |