~launchpad-pqm/launchpad/devel

3944.1.1 by Francis J. Lacoste
Use system version python2.4 for scripts.
1
#!/usr/bin/python2.4
7161.1.14 by Gary Poster
change per review by flacoste: add in XXX for bugs, add some comments, and factor out some common code
2
# Copyright 2006-2008 Canonical Ltd.  All rights reserved.
3691.201.5 by James Henstridge
sourceforge importer driver script
3
4
import logging
5
import optparse
3691.201.38 by James Henstridge
fixes from spiv's review
6
import sys
3691.201.5 by James Henstridge
sourceforge importer driver script
7
7178.3.1 by Curtis Hovey
Remove that last of the callsites that mutate the config.
8
# pylint: disable-msg=W0403
3691.201.5 by James Henstridge
sourceforge importer driver script
9
import _pythonpath
10
11
from zope.component import getUtility
12
from canonical.config import config
13
from canonical.lp import initZopeless
14
from canonical.launchpad.interfaces import IProductSet
15
from canonical.launchpad.scripts import (
16
    execute_zcml_for_scripts, logger_options, logger)
17
from canonical.launchpad.ftests import login
7161.1.10 by Gary Poster
all ftests should be passing now. Only page tests--six of them--to go, as far as I know.
18
from canonical.launchpad.webapp.interaction import Participation
3691.201.5 by James Henstridge
sourceforge importer driver script
19
3691.201.6 by James Henstridge
fixes to get import working with siproxd test data
20
from canonical.launchpad.scripts.sftracker import Tracker, TrackerImporter
3691.201.5 by James Henstridge
sourceforge importer driver script
21
22
def main(argv):
23
    parser = optparse.OptionParser(description="This script imports bugs "
24
                                   "from Sourceforge into Launchpad.")
25
26
    parser.add_option('--product', metavar='PRODUCT', action='store',
27
                      help='The product to associate bugs with',
28
                      type='string', dest='product', default=None)
29
    parser.add_option('--dumpfile', metavar='XML', action='store',
30
                      help='The XML tracker data dump',
31
                      type='string', dest='dumpfile', default=None)
32
    parser.add_option('--dumpdir', metavar='DIR', action='store',
33
                      help='The directory with the dumped tracker data',
34
                      type='string', dest='dumpdir', default=None)
3691.201.6 by James Henstridge
fixes to get import working with siproxd test data
35
    parser.add_option('--verify-users', dest='verify_users',
36
                      help='Should created users have verified emails?',
37
                      action='store_true', default=False)
3691.201.5 by James Henstridge
sourceforge importer driver script
38
3691.201.6 by James Henstridge
fixes to get import working with siproxd test data
39
    logger_options(parser, logging.INFO)
3691.201.5 by James Henstridge
sourceforge importer driver script
40
41
    options, args = parser.parse_args(argv[1:])
42
    logger(options, 'canonical.launchpad.scripts.sftracker')
43
44
    # don't send email
7178.3.1 by Curtis Hovey
Remove that last of the callsites that mutate the config.
45
    send_email_data = """
46
        [zopeless]
47
        send_email: False
48
        """
49
    config.push('send_email_data', send_email_data)
3691.201.5 by James Henstridge
sourceforge importer driver script
50
5821.5.14 by James Henstridge
Run execute_zcml_for_scripts() before initZopeless() in many tests.
51
    execute_zcml_for_scripts()
3691.201.5 by James Henstridge
sourceforge importer driver script
52
    ztm = initZopeless()
7161.1.14 by Gary Poster
change per review by flacoste: add in XXX for bugs, add some comments, and factor out some common code
53
    # XXX gary 21-Oct-2008 bug 285808
7161.1.10 by Gary Poster
all ftests should be passing now. Only page tests--six of them--to go, as far as I know.
54
    # We should reconsider using a ftest helper for production code.  For now,
55
    # we explicitly keep the code from using a test request by using a basic
56
    # participation.
57
    login('bug-importer@launchpad.net', Participation())
3691.201.5 by James Henstridge
sourceforge importer driver script
58
59
    product = getUtility(IProductSet).getByName(options.product)
60
    tracker = Tracker(options.dumpfile, options.dumpdir)
3691.201.6 by James Henstridge
fixes to get import working with siproxd test data
61
    importer = TrackerImporter(product, options.verify_users)
3691.201.5 by James Henstridge
sourceforge importer driver script
62
63
    importer.importTracker(ztm, tracker)
7178.3.1 by Curtis Hovey
Remove that last of the callsites that mutate the config.
64
    config.pop('send_email_data')
3691.201.5 by James Henstridge
sourceforge importer driver script
65
66
if __name__ == '__main__':
67
    sys.exit(main(sys.argv))