~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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/python
# Copyright 2004-2005 Canonical Ltd.  All rights reserved.

"""Script to export a tarball of translations for a distro release."""

__metaclass__ = type

import _pythonpath

import optparse
import sys

from canonical.lp import initZopeless
from canonical.launchpad.scripts import (execute_zcml_for_scripts, logger,
    logger_options)
from canonical.launchpad.scripts.language_pack import export_language_pack

def parse_options(args):
    """Parse options for exporting distribution release translations.

    Returns a 3-tuple containing an options object, a distribution name and a
    release name.
    """

    parser = optparse.OptionParser(
        usage='%prog [options] distribution release')
    parser.add_option(
        '--email',
        dest='email_addresses',
        default=[],
        action='append',
        help='An email address to send a notification to.'
        )
    parser.add_option(
        '--output',
        dest='output',
        default=None,
        action='store',
        help='A file to send the generated tarball to, rather than the'
             ' Libraran.'
        )
    parser.add_option(
        '--update',
        dest='update',
        default=False,
        action='store_true'
        )

    # Add the verbose/quiet options.
    logger_options(parser)

    parser.add_option(
        '--component',
        dest='component',
        default=None,
        action='store'
        )

    options, args = parser.parse_args(args)

    if len(args) != 2:
        parser.error('Wrong number of arguments')

    return options, args[0], args[1]

def main(argv):
    initZopeless()
    execute_zcml_for_scripts()

    options, distribution_name, release_name = parse_options(argv[1:])

    logger_object = logger(options, 'rosetta-language-pack-export')
    logger_object.info(
            'Exporting translations for release %s of distribution %s',
            distribution_name, release_name
            )

    success = export_language_pack(
        distribution_name=distribution_name,
        release_name=release_name,
        component=options.component,
        update=options.update,
        output_file=options.output,
        email_addresses=options.email_addresses,
        logger=logger_object)

    if success:
        return 0
    else:
        return 1

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