~launchpad-pqm/launchpad/devel

10637.3.1 by Guilherme Salgado
Use the default python version instead of a hard-coded version
1
#!/usr/bin/python -S
8687.15.7 by Karl Fogel
Add the copyright header block to more files.
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
4935.3.7 by Curtis Hovey
Added bad name suppression to cronscripts.
6
# pylint: disable-msg=C0103,W0403
1685 by Canonical.com Patch Queue Manager
RosettaLanguagePackExports (r=Steve)
7
4796.3.8 by Carlos Perello Marin
Added a form to see the language packs available for a distro series and store them in the LanguagePack table
8
"""Script to export a tarball of translations for a distro series."""
1685 by Canonical.com Patch Queue Manager
RosettaLanguagePackExports (r=Steve)
9
10
__metaclass__ = type
11
2125 by Canonical.com Patch Queue Manager
[r=bjornt] Cronscript refactorings
12
import _pythonpath
13
8356.1.1 by Leonard Richardson
Partial move.
14
from lp.services.scripts.base import (
4796.3.10 by Carlos Perello Marin
Finished some integration bits + tests
15
    LaunchpadCronScript, LaunchpadScriptFailure)
8751.1.1 by Danilo Šegan
Store migration changes so far.
16
from lp.translations.scripts.language_pack import export_language_pack
1685 by Canonical.com Patch Queue Manager
RosettaLanguagePackExports (r=Steve)
17
3691.348.18 by kiko
Convert most other scripts; 6 remain, of which one looks like it's going to be a bit tricky...
18
4264.2.1 by James Henstridge
add a LaunchpadCronScript subclass, and make cronscripts/*.py use it
19
class RosettaLangPackExporter(LaunchpadCronScript):
5428.1.1 by Curtis Hovey
Restructured RosettaLangPackExporter to allow lang-pack-exporter to run
20
    """Export language packs for a distribution series."""
4796.3.8 by Carlos Perello Marin
Added a form to see the language packs available for a distro series and store them in the LanguagePack table
21
    usage = '%prog [options] distribution series'
4796.3.10 by Carlos Perello Marin
Finished some integration bits + tests
22
3691.348.18 by kiko
Convert most other scripts; 6 remain, of which one looks like it's going to be a bit tricky...
23
    def add_my_options(self):
5428.1.1 by Curtis Hovey
Restructured RosettaLangPackExporter to allow lang-pack-exporter to run
24
        """See `LaunchpadScript`."""
3691.348.18 by kiko
Convert most other scripts; 6 remain, of which one looks like it's going to be a bit tricky...
25
        self.parser.add_option(
26
            '--output',
27
            dest='output',
28
            default=None,
29
            action='store',
30
            help='A file to send the generated tarball to, rather than the'
31
                 ' Libraran.'
32
            )
33
        self.parser.add_option(
34
            '--component',
35
            dest='component',
36
            default=None,
37
            action='store',
38
            help='Select a concrete archive component to export.'
39
            )
40
        self.parser.add_option(
41
            '--force-utf8-encoding',
42
            dest='force_utf8',
43
            default=False,
44
            action='store_true',
45
            help='Whether the exported files should be exported using UTF-8'
46
                 ' encoding.'
47
            )
48
5428.1.1 by Curtis Hovey
Restructured RosettaLangPackExporter to allow lang-pack-exporter to run
49
    def args(self):
50
        """Return the list of command-line arguments."""
51
        return self._args
52
53
    def _setargs(self, args):
54
        """Set distribution_name and series_name from the args."""
55
        if len(args) != 2:
3691.348.18 by kiko
Convert most other scripts; 6 remain, of which one looks like it's going to be a bit tricky...
56
            raise LaunchpadScriptFailure(
57
                'Wrong number of arguments: should include distribution '
5428.1.1 by Curtis Hovey
Restructured RosettaLangPackExporter to allow lang-pack-exporter to run
58
                'and series name.')
59
60
        self._args = args
61
        self.distribution_name, self.series_name = self._args
62
63
    args = property(args, _setargs, doc=args.__doc__)
64
65
    @property
66
    def lockfilename(self):
67
        """Return lockfilename.
68
69
        The lockfile name is unique to the script, distribution, and series.
70
        The script can run concurrently for different distroseries.
71
        """
5428.1.2 by Curtis Hovey
Revisions per review.
72
        lockfile_name = "launchpad-%s__%s__%s.lock" % (
5428.1.1 by Curtis Hovey
Restructured RosettaLangPackExporter to allow lang-pack-exporter to run
73
            self.name, self.distribution_name, self.series_name)
74
        self.logger.info('Setting lockfile name to %s.' % lockfile_name)
75
        return lockfile_name
76
77
    def main(self):
78
        """See `LaunchpadScript`."""
3691.348.18 by kiko
Convert most other scripts; 6 remain, of which one looks like it's going to be a bit tricky...
79
        self.logger.info(
5428.1.1 by Curtis Hovey
Restructured RosettaLangPackExporter to allow lang-pack-exporter to run
80
            'Exporting translations for series %s of distribution %s.',
81
            self.series_name, self.distribution_name)
3691.348.18 by kiko
Convert most other scripts; 6 remain, of which one looks like it's going to be a bit tricky...
82
        success = export_language_pack(
5428.1.1 by Curtis Hovey
Restructured RosettaLangPackExporter to allow lang-pack-exporter to run
83
            distribution_name=self.distribution_name,
84
            series_name=self.series_name,
3691.348.18 by kiko
Convert most other scripts; 6 remain, of which one looks like it's going to be a bit tricky...
85
            component=self.options.component,
86
            force_utf8=self.options.force_utf8,
87
            output_file=self.options.output,
88
            logger=self.logger)
89
90
        if not success:
91
            raise LaunchpadScriptFailure('Language pack generation failed')
4796.3.8 by Carlos Perello Marin
Added a form to see the language packs available for a distro series and store them in the LanguagePack table
92
        else:
93
            self.txn.commit()
94
1685 by Canonical.com Patch Queue Manager
RosettaLanguagePackExports (r=Steve)
95
96
if __name__ == '__main__':
6556.4.1 by Jeroen Vermeulen
Dedicated database user for language pack export.
97
    script = RosettaLangPackExporter(
98
        'language-pack-exporter', dbuser='langpack')
3691.348.18 by kiko
Convert most other scripts; 6 remain, of which one looks like it's going to be a bit tricky...
99
    script.lock_and_run()
1685 by Canonical.com Patch Queue Manager
RosettaLanguagePackExports (r=Steve)
100