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 |
|
14273.1.9
by Gavin Panella
Add --testing option to bug-import.py so we don't have to create a project by hand. |
6 |
import _pythonpath |
7 |
||
14027.3.2
by Jeroen Vermeulen
Merge devel, resolve conflicts. |
8 |
import logging |
9 |
||
14273.1.9
by Gavin Panella
Add --testing option to bug-import.py so we don't have to create a project by hand. |
10 |
import transaction |
3691.440.4
by James Henstridge
driver script |
11 |
from zope.component import getUtility |
14027.3.2
by Jeroen Vermeulen
Merge devel, resolve conflicts. |
12 |
|
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 |
14612.2.7
by William Grant
scripts |
15 |
from lp.services.config import config |
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/. |
16 |
from lp.services.scripts.base import LaunchpadScript |
14273.1.9
by Gavin Panella
Add --testing option to bug-import.py so we don't have to create a project by hand. |
17 |
from lp.testing.factory import LaunchpadObjectFactory |
3691.440.4
by James Henstridge
driver script |
18 |
|
3691.440.16
by James Henstridge
convert bug-import.py over to new scripts infrastructure |
19 |
|
20 |
class BugImportScript(LaunchpadScript): |
|
21 |
||
3691.440.17
by James Henstridge
fix description in bug-import.py help output |
22 |
description = "Import bugs into Launchpad from XML." |
3691.440.16
by James Henstridge
convert bug-import.py over to new scripts infrastructure |
23 |
loglevel = logging.INFO |
24 |
||
25 |
def add_my_options(self): |
|
12043.8.2
by Peter Clifton
scripts/bug-import.py: Reformat self.parser.add_option() lines |
26 |
self.parser.add_option( |
27 |
'-p', '--product', metavar='PRODUCT', action='store', |
|
28 |
help='Which product to export', type='string', dest='product', |
|
29 |
default=None) |
|
30 |
self.parser.add_option( |
|
31 |
'--cache', metavar='FILE', action='store', |
|
32 |
help='Cache for bug ID mapping', type='string', |
|
33 |
dest='cache_filename', default='bug-map.pickle') |
|
4664.1.1
by Curtis Hovey
Normalized comments for bug 3732. |
34 |
# XXX: jamesh 2007-04-11 bugs=86352
|
3691.440.21
by James Henstridge
add some new coments in response to Bjorn's review |
35 |
# Not verifying users created by a bug import can result in
|
36 |
# problems with mail notification, so should not be used for
|
|
37 |
# imports.
|
|
12043.8.2
by Peter Clifton
scripts/bug-import.py: Reformat self.parser.add_option() lines |
38 |
self.parser.add_option( |
39 |
'--dont-verify-users', dest='verify_users', |
|
40 |
help="Don't verify newly created users", action='store_false', |
|
41 |
default=True) |
|
14273.1.9
by Gavin Panella
Add --testing option to bug-import.py so we don't have to create a project by hand. |
42 |
self.parser.add_option( |
43 |
'--testing', dest="testing", action="store_true", help=( |
|
14273.1.13
by Gavin Panella
Update help text for --testing option. |
44 |
"Testing mode; if --product=name is omitted, create a "
|
45 |
"product with Launchpad's test object factory. Do *not* "
|
|
46 |
"use in production!"), |
|
14273.1.9
by Gavin Panella
Add --testing option to bug-import.py so we don't have to create a project by hand. |
47 |
default=False) |
48 |
||
49 |
def create_test_product(self): |
|
50 |
"""Create a test product with `LaunchpadObjectFactory`.
|
|
51 |
||
52 |
Returns the new object's name.
|
|
53 |
"""
|
|
14273.1.12
by Gavin Panella
Simplify test product creation. |
54 |
factory = LaunchpadObjectFactory() |
55 |
product = factory.makeProduct(official_malone=True) |
|
56 |
transaction.commit() |
|
57 |
return product.name |
|
3691.440.16
by James Henstridge
convert bug-import.py over to new scripts infrastructure |
58 |
|
59 |
def main(self): |
|
60 |
if self.options.product is None: |
|
14273.1.9
by Gavin Panella
Add --testing option to bug-import.py so we don't have to create a project by hand. |
61 |
if self.options.testing: |
62 |
self.options.product = self.create_test_product() |
|
14273.1.12
by Gavin Panella
Simplify test product creation. |
63 |
self.logger.info("Product %s created", self.options.product) |
14273.1.9
by Gavin Panella
Add --testing option to bug-import.py so we don't have to create a project by hand. |
64 |
else: |
65 |
self.parser.error('No product specified') |
|
3691.440.16
by James Henstridge
convert bug-import.py over to new scripts infrastructure |
66 |
if len(self.args) != 1: |
67 |
self.parser.error('Please specify a bug XML file to import') |
|
68 |
bugs_filename = self.args[0] |
|
7178.3.1
by Curtis Hovey
Remove that last of the callsites that mutate the config. |
69 |
|
3691.440.16
by James Henstridge
convert bug-import.py over to new scripts infrastructure |
70 |
# don't send email
|
7178.3.1
by Curtis Hovey
Remove that last of the callsites that mutate the config. |
71 |
send_email_data = """ |
14022.2.7
by William Grant
Fix two zopeless config overlays in scripts. |
72 |
[immediate_mail]
|
7178.3.1
by Curtis Hovey
Remove that last of the callsites that mutate the config. |
73 |
send_email: False
|
74 |
"""
|
|
75 |
config.push('send_email_data', send_email_data) |
|
3691.440.16
by James Henstridge
convert bug-import.py over to new scripts infrastructure |
76 |
self.login('bug-importer@launchpad.net') |
7178.3.1
by Curtis Hovey
Remove that last of the callsites that mutate the config. |
77 |
|
3691.440.16
by James Henstridge
convert bug-import.py over to new scripts infrastructure |
78 |
product = getUtility(IProductSet).getByName(self.options.product) |
79 |
if product is None: |
|
80 |
self.parser.error('Product %s does not exist' |
|
81 |
% self.options.product) |
|
82 |
||
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(). |
83 |
importer = BugImporter( |
84 |
product, bugs_filename, self.options.cache_filename, |
|
12043.8.3
by Peter Clifton
bug-import: Remove the --allow-empty-comments option, check attachments instead |
85 |
verify_users=self.options.verify_users, logger=self.logger) |
3691.440.16
by James Henstridge
convert bug-import.py over to new scripts infrastructure |
86 |
importer.importBugs(self.txn) |
7178.3.1
by Curtis Hovey
Remove that last of the callsites that mutate the config. |
87 |
config.pop('send_email_data') |
3691.440.16
by James Henstridge
convert bug-import.py over to new scripts infrastructure |
88 |
|
3691.440.4
by James Henstridge
driver script |
89 |
|
90 |
if __name__ == '__main__': |
|
14565.2.15
by Curtis Hovey
Moved canonical.launchpad.scripts __init__ to lp.services.scripts. |
91 |
script = BugImportScript('lp.services.scripts.bugimport') |
3691.440.16
by James Henstridge
convert bug-import.py over to new scripts infrastructure |
92 |
script.run() |