~launchpad-pqm/launchpad/devel

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).
3691.440.4 by James Henstridge
driver script
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
9641.1.7 by Gary Poster
fix scripts to work
9
import logging
10
3691.440.4 by James Henstridge
driver script
11
from zope.component import getUtility
12
from canonical.config import config
13
from canonical.launchpad.interfaces import IProductSet
14
8657.3.5 by Graham Binns
Reinstated bug import tests.
15
from lp.bugs.scripts.bugimport import BugImporter
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
3691.440.4 by James Henstridge
driver script
17
3691.440.16 by James Henstridge
convert bug-import.py over to new scripts infrastructure
18
19
class BugImportScript(LaunchpadScript):
20
3691.440.17 by James Henstridge
fix description in bug-import.py help output
21
    description = "Import bugs into Launchpad from XML."
3691.440.16 by James Henstridge
convert bug-import.py over to new scripts infrastructure
22
    loglevel = logging.INFO
23
24
    def add_my_options(self):
25
        self.parser.add_option('-p', '--product', metavar='PRODUCT',
26
                               action='store',
27
                               help='Which product to export',
28
                               type='string', dest='product', default=None)
29
        self.parser.add_option('--cache', metavar='FILE', action='store',
30
                               help='Cache for bug ID mapping',
31
                               type='string', dest='cache_filename',
32
                               default='bug-map.pickle')
4664.1.1 by Curtis Hovey
Normalized comments for bug 3732.
33
        # XXX: jamesh 2007-04-11 bugs=86352
3691.440.21 by James Henstridge
add some new coments in response to Bjorn's review
34
        # Not verifying users created by a bug import can result in
35
        # problems with mail notification, so should not be used for
36
        # imports.
3691.440.16 by James Henstridge
convert bug-import.py over to new scripts infrastructure
37
        self.parser.add_option('--dont-verify-users', dest='verify_users',
38
                               help="Don't verify newly created users",
39
                               action='store_false', default=True)
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 = """
50
            [zopeless]
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,
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()