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 ( |
14612.2.8
by William Grant
cronscripts |
15 |
LaunchpadCronScript, |
16 |
LaunchpadScriptFailure, |
|
17 |
)
|
|
8751.1.1
by Danilo Šegan
Store migration changes so far. |
18 |
from lp.translations.scripts.language_pack import export_language_pack |
1685
by Canonical.com Patch Queue Manager
RosettaLanguagePackExports (r=Steve) |
19 |
|
3691.348.18
by kiko
Convert most other scripts; 6 remain, of which one looks like it's going to be a bit tricky... |
20 |
|
4264.2.1
by James Henstridge
add a LaunchpadCronScript subclass, and make cronscripts/*.py use it |
21 |
class RosettaLangPackExporter(LaunchpadCronScript): |
5428.1.1
by Curtis Hovey
Restructured RosettaLangPackExporter to allow lang-pack-exporter to run |
22 |
"""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 |
23 |
usage = '%prog [options] distribution series' |
4796.3.10
by Carlos Perello Marin
Finished some integration bits + tests |
24 |
|
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 |
def add_my_options(self): |
5428.1.1
by Curtis Hovey
Restructured RosettaLangPackExporter to allow lang-pack-exporter to run |
26 |
"""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... |
27 |
self.parser.add_option( |
28 |
'--output', |
|
29 |
dest='output', |
|
30 |
default=None, |
|
31 |
action='store', |
|
32 |
help='A file to send the generated tarball to, rather than the' |
|
33 |
' Libraran.'
|
|
34 |
)
|
|
35 |
self.parser.add_option( |
|
36 |
'--component', |
|
37 |
dest='component', |
|
38 |
default=None, |
|
39 |
action='store', |
|
40 |
help='Select a concrete archive component to export.' |
|
41 |
)
|
|
42 |
self.parser.add_option( |
|
43 |
'--force-utf8-encoding', |
|
44 |
dest='force_utf8', |
|
45 |
default=False, |
|
46 |
action='store_true', |
|
47 |
help='Whether the exported files should be exported using UTF-8' |
|
48 |
' encoding.'
|
|
49 |
)
|
|
50 |
||
5428.1.1
by Curtis Hovey
Restructured RosettaLangPackExporter to allow lang-pack-exporter to run |
51 |
def args(self): |
52 |
"""Return the list of command-line arguments."""
|
|
53 |
return self._args |
|
54 |
||
55 |
def _setargs(self, args): |
|
56 |
"""Set distribution_name and series_name from the args."""
|
|
57 |
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... |
58 |
raise LaunchpadScriptFailure( |
59 |
'Wrong number of arguments: should include distribution '
|
|
5428.1.1
by Curtis Hovey
Restructured RosettaLangPackExporter to allow lang-pack-exporter to run |
60 |
'and series name.') |
61 |
||
62 |
self._args = args |
|
63 |
self.distribution_name, self.series_name = self._args |
|
64 |
||
65 |
args = property(args, _setargs, doc=args.__doc__) |
|
66 |
||
67 |
@property
|
|
68 |
def lockfilename(self): |
|
69 |
"""Return lockfilename.
|
|
70 |
||
71 |
The lockfile name is unique to the script, distribution, and series.
|
|
72 |
The script can run concurrently for different distroseries.
|
|
73 |
"""
|
|
5428.1.2
by Curtis Hovey
Revisions per review. |
74 |
lockfile_name = "launchpad-%s__%s__%s.lock" % ( |
5428.1.1
by Curtis Hovey
Restructured RosettaLangPackExporter to allow lang-pack-exporter to run |
75 |
self.name, self.distribution_name, self.series_name) |
76 |
self.logger.info('Setting lockfile name to %s.' % lockfile_name) |
|
77 |
return lockfile_name |
|
78 |
||
79 |
def main(self): |
|
80 |
"""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... |
81 |
self.logger.info( |
5428.1.1
by Curtis Hovey
Restructured RosettaLangPackExporter to allow lang-pack-exporter to run |
82 |
'Exporting translations for series %s of distribution %s.', |
83 |
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... |
84 |
success = export_language_pack( |
5428.1.1
by Curtis Hovey
Restructured RosettaLangPackExporter to allow lang-pack-exporter to run |
85 |
distribution_name=self.distribution_name, |
86 |
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... |
87 |
component=self.options.component, |
88 |
force_utf8=self.options.force_utf8, |
|
89 |
output_file=self.options.output, |
|
90 |
logger=self.logger) |
|
91 |
||
92 |
if not success: |
|
93 |
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 |
94 |
else: |
95 |
self.txn.commit() |
|
96 |
||
1685
by Canonical.com Patch Queue Manager
RosettaLanguagePackExports (r=Steve) |
97 |
|
98 |
if __name__ == '__main__': |
|
6556.4.1
by Jeroen Vermeulen
Dedicated database user for language pack export. |
99 |
script = RosettaLangPackExporter( |
100 |
'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... |
101 |
script.lock_and_run() |
1685
by Canonical.com Patch Queue Manager
RosettaLanguagePackExports (r=Steve) |
102 |