~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to scripts/bugzilla-import.py

  • Committer: Danilo Segan
  • Date: 2011-04-22 14:02:29 UTC
  • mto: This revision was merged to the branch mainline in revision 12910.
  • Revision ID: danilo@canonical.com-20110422140229-zhq4d4c2k8jpglhf
Ignore hidden files when building combined JS file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python -S
 
2
#
 
3
# Copyright 2009 Canonical Ltd.  This software is licensed under the
 
4
# GNU Affero General Public License version 3 (see the file LICENSE).
 
5
 
 
6
import sys
 
7
import logging
 
8
import optparse
 
9
import MySQLdb
 
10
 
 
11
# pylint: disable-msg=W0403
 
12
import _pythonpath
 
13
 
 
14
from canonical.config import config
 
15
from canonical.lp import initZopeless
 
16
from canonical.launchpad.scripts import (
 
17
    execute_zcml_for_scripts, logger_options, logger)
 
18
from canonical.launchpad.webapp.interaction import setupInteractionByEmail
 
19
 
 
20
from canonical.launchpad.scripts import bugzilla
 
21
 
 
22
 
 
23
def make_connection(options):
 
24
    kws = {}
 
25
    if options.db_name is not None:
 
26
        kws['db'] = options.db_name
 
27
    if options.db_user is not None:
 
28
        kws['user'] = options.db_user
 
29
    if options.db_password is not None:
 
30
        kws['passwd'] = options.db_passwd
 
31
    if options.db_host is not None:
 
32
        kws['host'] = options.db_host
 
33
 
 
34
    return MySQLdb.connect(**kws)
 
35
 
 
36
def main(argv):
 
37
    parser = optparse.OptionParser(
 
38
        description=("This script imports bugs from a Bugzilla "
 
39
                     "into Launchpad."))
 
40
 
 
41
    parser.add_option('--component', metavar='COMPONENT', action='append',
 
42
                      help='Limit to this bugzilla component',
 
43
                      type='string', dest='component', default=[])
 
44
    parser.add_option('--status', metavar='STATUS,...', action='store',
 
45
                      help='Only import bugs with the given status',
 
46
                      type='string', dest='status',
 
47
                      default=None)
 
48
 
 
49
    # MySQL connection details
 
50
    parser.add_option('-d', '--dbname', metavar='DB', action='store',
 
51
                      help='The MySQL database name',
 
52
                      type='string', dest='db_name', default='bugs_warty')
 
53
    parser.add_option('-U', '--username', metavar='USER', action='store',
 
54
                      help='The MySQL user name',
 
55
                      type='string', dest='db_user', default=None)
 
56
    parser.add_option('-p', '--password', metavar='PASSWORD', action='store',
 
57
                      help='The MySQL password',
 
58
                      type='string', dest='db_password', default=None)
 
59
    parser.add_option('-H', '--host', metavar='HOST', action='store',
 
60
                      help='The MySQL database host',
 
61
                      type='string', dest='db_host', default=None)
 
62
 
 
63
    # logging options
 
64
    logger_options(parser, logging.INFO)
 
65
 
 
66
    options, args = parser.parse_args(argv[1:])
 
67
    if options.status is not None:
 
68
        options.status = options.status.split(',')
 
69
    else:
 
70
        options.status = []
 
71
 
 
72
    logger(options, 'canonical.launchpad.scripts.bugzilla')
 
73
 
 
74
    # don't send email
 
75
    send_email_data = """
 
76
        [zopeless]
 
77
        send_email: False
 
78
        """
 
79
    config.push('send_email_data', send_email_data)
 
80
 
 
81
    execute_zcml_for_scripts()
 
82
    ztm = initZopeless()
 
83
    setupInteractionByEmail('bug-importer@launchpad.net')
 
84
 
 
85
    db = make_connection(options)
 
86
    bz = bugzilla.Bugzilla(db)
 
87
 
 
88
    bz.importBugs(ztm,
 
89
                  product=['Ubuntu'],
 
90
                  component=options.component,
 
91
                  status=options.status)
 
92
 
 
93
    bz.processDuplicates(ztm)
 
94
    config.pop('send_email_data')
 
95
 
 
96
if __name__ == '__main__':
 
97
    sys.exit(main(sys.argv))