~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
#!/usr/bin/python -S
#
# Copyright 2009 Canonical Ltd.  This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
# pylint: disable-msg=W0403

import _pythonpath

import sys
import optparse

from zope.component import getUtility
from canonical.lp import initZopeless
from canonical.launchpad.interfaces import IProductSet
from canonical.launchpad.scripts import execute_zcml_for_scripts

from lp.bugs.scripts.bugexport import export_bugtasks

def main(argv):
    parser = optparse.OptionParser(
        description="Export bugs for a Launchpad product as XML")
    parser.add_option('-o', '--output', metavar='FILE', action='store',
                      help='Export bugs to this file',
                      type='string', dest='output', default=None)
    parser.add_option('-p', '--product', metavar='PRODUCT', action='store',
                      help='Which product to export',
                      type='string', dest='product', default=None)
    parser.add_option('--include-private', action='store_true',
                      help='Include private bugs in dump',
                      dest='include_private', default=False)

    options, args = parser.parse_args(argv[1:])

    if options.product is None:
        parser.error('No product specified')
    output = sys.stdout
    if options.output is not None:
        output = open(options.output, 'wb')

    execute_zcml_for_scripts()
    ztm = initZopeless()

    product = getUtility(IProductSet).getByName(options.product)
    if product is None:
        parser.error('Product %s does not exist' % options.product)

    export_bugtasks(ztm, product, output,
                    include_private=options.include_private)

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