~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
11882.2.2 by Jonathan Lange
Clear up a heck of a lot of imports from canonical.launchpad.interfaces.
13
from lp.registry.interfaces.product import IProductSet
11666.3.1 by Curtis Hovey
Merged apocalypse-0 into this branch to fix translations and codehosting.
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):
12043.8.2 by Peter Clifton
scripts/bug-import.py: Reformat self.parser.add_option() lines
25
        self.parser.add_option(
26
            '-p', '--product', metavar='PRODUCT', action='store',
27
            help='Which product to export', type='string', dest='product',
28
            default=None)
29
        self.parser.add_option(
30
            '--cache', metavar='FILE', action='store',
31
            help='Cache for bug ID mapping', type='string',
32
            dest='cache_filename', 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.
12043.8.2 by Peter Clifton
scripts/bug-import.py: Reformat self.parser.add_option() lines
37
        self.parser.add_option(
38
            '--dont-verify-users', dest='verify_users',
39
            help="Don't verify newly created users", action='store_false',
40
            default=True)
3691.440.16 by James Henstridge
convert bug-import.py over to new scripts infrastructure
41
42
    def main(self):
43
        if self.options.product is None:
44
            self.parser.error('No product specified')
45
        if len(self.args) != 1:
46
            self.parser.error('Please specify a bug XML file to import')
47
        bugs_filename = self.args[0]
7178.3.1 by Curtis Hovey
Remove that last of the callsites that mutate the config.
48
3691.440.16 by James Henstridge
convert bug-import.py over to new scripts infrastructure
49
        # don't send email
7178.3.1 by Curtis Hovey
Remove that last of the callsites that mutate the config.
50
        send_email_data = """
51
            [zopeless]
52
            send_email: False
53
            """
54
        config.push('send_email_data', send_email_data)
3691.440.16 by James Henstridge
convert bug-import.py over to new scripts infrastructure
55
        self.login('bug-importer@launchpad.net')
7178.3.1 by Curtis Hovey
Remove that last of the callsites that mutate the config.
56
3691.440.16 by James Henstridge
convert bug-import.py over to new scripts infrastructure
57
        product = getUtility(IProductSet).getByName(self.options.product)
58
        if product is None:
59
            self.parser.error('Product %s does not exist'
60
                              % self.options.product)
61
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().
62
        importer = BugImporter(
63
            product, bugs_filename, self.options.cache_filename,
12043.8.3 by Peter Clifton
bug-import: Remove the --allow-empty-comments option, check attachments instead
64
            verify_users=self.options.verify_users, logger=self.logger)
3691.440.16 by James Henstridge
convert bug-import.py over to new scripts infrastructure
65
        importer.importBugs(self.txn)
7178.3.1 by Curtis Hovey
Remove that last of the callsites that mutate the config.
66
        config.pop('send_email_data')
3691.440.16 by James Henstridge
convert bug-import.py over to new scripts infrastructure
67
3691.440.4 by James Henstridge
driver script
68
69
if __name__ == '__main__':
3691.440.16 by James Henstridge
convert bug-import.py over to new scripts infrastructure
70
    script = BugImportScript('canonical.launchpad.scripts.bugimport')
71
    script.run()