~launchpad-pqm/launchpad/devel

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/python2.4
# Copyright 2006-2008 Canonical Ltd.  All rights reserved.

import logging
import optparse
import sys

# pylint: disable-msg=W0403
import _pythonpath

from zope.component import getUtility
from canonical.config import config
from canonical.lp import initZopeless
from canonical.launchpad.interfaces import IProductSet
from canonical.launchpad.scripts import (
    execute_zcml_for_scripts, logger_options, logger)
from canonical.launchpad.ftests import login
from canonical.launchpad.webapp.interaction import Participation

from canonical.launchpad.scripts.sftracker import Tracker, TrackerImporter

def main(argv):
    parser = optparse.OptionParser(description="This script imports bugs "
                                   "from Sourceforge into Launchpad.")

    parser.add_option('--product', metavar='PRODUCT', action='store',
                      help='The product to associate bugs with',
                      type='string', dest='product', default=None)
    parser.add_option('--dumpfile', metavar='XML', action='store',
                      help='The XML tracker data dump',
                      type='string', dest='dumpfile', default=None)
    parser.add_option('--dumpdir', metavar='DIR', action='store',
                      help='The directory with the dumped tracker data',
                      type='string', dest='dumpdir', default=None)
    parser.add_option('--verify-users', dest='verify_users',
                      help='Should created users have verified emails?',
                      action='store_true', default=False)

    logger_options(parser, logging.INFO)

    options, args = parser.parse_args(argv[1:])
    logger(options, 'canonical.launchpad.scripts.sftracker')

    # don't send email
    send_email_data = """
        [zopeless]
        send_email: False
        """
    config.push('send_email_data', send_email_data)

    execute_zcml_for_scripts()
    ztm = initZopeless()
    # XXX gary 21-Oct-2008 bug 285808
    # We should reconsider using a ftest helper for production code.  For now,
    # we explicitly keep the code from using a test request by using a basic
    # participation.
    login('bug-importer@launchpad.net', Participation())

    product = getUtility(IProductSet).getByName(options.product)
    tracker = Tracker(options.dumpfile, options.dumpdir)
    importer = TrackerImporter(product, options.verify_users)

    importer.importTracker(ztm, tracker)
    config.pop('send_email_data')

if __name__ == '__main__':
    sys.exit(main(sys.argv))