10637.3.1
by Guilherme Salgado
Use the default python version instead of a hard-coded version |
1 |
#!/usr/bin/python -S
|
8687.15.22
by Karl Fogel
Add the copyright header block to the remaining .py 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 |
||
5619.1.5
by Jeroen Vermeulen
Improvements based on review. |
6 |
# pylint: disable-msg=W0403
|
3617.3.12
by Carlos Perello Marin
added a script to do the translation migration |
7 |
|
3691.8.105
by Carlos Perello Marin
Applied review comments for postmerge review of r4272 + bug fix for bug #122363 |
8 |
"""Furnish distroseries with lacking translations that its parent does have.
|
4128.3.21
by Jeroen Vermeulen
Processed final notes from reviewer. Several things still to do; see bug 116196, bug 116197, 116200. |
9 |
|
3691.8.105
by Carlos Perello Marin
Applied review comments for postmerge review of r4272 + bug fix for bug #122363 |
10 |
This can be used either to update a distroseries' translations, or to
|
11 |
provide a new distroseries in a series with its initial translation data.
|
|
4128.3.21
by Jeroen Vermeulen
Processed final notes from reviewer. Several things still to do; see bug 116196, bug 116197, 116200. |
12 |
Only current translations are copied.
|
13 |
"""
|
|
14 |
||
3691.70.9
by Stuart Bishop
Add missing "import _pythonpath" from script |
15 |
import _pythonpath |
8751.1.2
by Danilo Šegan
Update configure.zcml and interface calls. |
16 |
|
3691.8.105
by Carlos Perello Marin
Applied review comments for postmerge review of r4272 + bug fix for bug #122363 |
17 |
import sys |
14612.2.7
by William Grant
scripts |
18 |
|
3617.3.12
by Carlos Perello Marin
added a script to do the translation migration |
19 |
from zope.component import getUtility |
14612.2.7
by William Grant
scripts |
20 |
|
14605.1.1
by Curtis Hovey
Moved canonical.config to lp.services. |
21 |
from lp.services.config import config |
8356.1.1
by Leonard Richardson
Partial move. |
22 |
from lp.services.scripts.base import LaunchpadCronScript |
8751.1.2
by Danilo Šegan
Update configure.zcml and interface calls. |
23 |
from lp.translations.scripts.copy_distroseries_translations import ( |
14612.2.7
by William Grant
scripts |
24 |
copy_distroseries_translations, |
25 |
)
|
|
5619.1.1
by Jeroen Vermeulen
Sketch for making copy-missing-translations-from-parent.py runnable as a cron job. |
26 |
|
27 |
||
28 |
class TranslationsCopier(LaunchpadCronScript): |
|
29 |
"""Copy latest distroseries translations from parent series.
|
|
30 |
||
31 |
Core job is to invoke `distroseries.copyMissingTranslationsFromParent()`.
|
|
3617.3.12
by Carlos Perello Marin
added a script to do the translation migration |
32 |
"""
|
4271.1.1
by Jeroen Vermeulen
Fixes bug #116197: protect copy-missing-translations-from-parent from concurrent runs by making it a LaunchpadScript. https://bugs.launchpad.net/rosetta/+bug/116197 |
33 |
|
34 |
def add_my_options(self): |
|
35 |
self.parser.add_option('-d', '--distribution', dest='distro', |
|
36 |
default='ubuntu', |
|
37 |
help='Name of distribution to copy translations in.') |
|
3691.8.108
by Carlos Perello Marin
Applied more reviewer comments |
38 |
self.parser.add_option('-s', '--series', dest='series', |
3691.8.105
by Carlos Perello Marin
Applied review comments for postmerge review of r4272 + bug fix for bug #122363 |
39 |
help='Name of distroseries whose translations should be updated') |
5619.1.1
by Jeroen Vermeulen
Sketch for making copy-missing-translations-from-parent.py runnable as a cron job. |
40 |
self.parser.add_option('-f', '--force', dest='force', |
5619.1.3
by Jeroen Vermeulen
Fixed bug in option spec. |
41 |
action="store_true", default=False, |
5619.1.1
by Jeroen Vermeulen
Sketch for making copy-missing-translations-from-parent.py runnable as a cron job. |
42 |
help="Don't check if target's UI and imports are blocked; " |
43 |
"actively block them.") |
|
44 |
||
45 |
def _getTargetSeries(self): |
|
46 |
"""Retrieve target `DistroSeries`."""
|
|
8751.1.7
by Danilo Šegan
Move translations test out of sourcepackagerelease.txt. |
47 |
from lp.registry.interfaces.distribution import IDistributionSet |
5619.1.1
by Jeroen Vermeulen
Sketch for making copy-missing-translations-from-parent.py runnable as a cron job. |
48 |
distro = self.options.distro |
49 |
series = self.options.series |
|
50 |
return getUtility(IDistributionSet)[distro][series] |
|
4271.1.1
by Jeroen Vermeulen
Fixes bug #116197: protect copy-missing-translations-from-parent from concurrent runs by making it a LaunchpadScript. https://bugs.launchpad.net/rosetta/+bug/116197 |
51 |
|
52 |
def main(self): |
|
8751.1.7
by Danilo Šegan
Move translations test out of sourcepackagerelease.txt. |
53 |
from lp.registry.interfaces.distribution import IDistributionSet |
4271.1.1
by Jeroen Vermeulen
Fixes bug #116197: protect copy-missing-translations-from-parent from concurrent runs by making it a LaunchpadScript. https://bugs.launchpad.net/rosetta/+bug/116197 |
54 |
distribution = getUtility(IDistributionSet)[self.options.distro] |
5619.1.1
by Jeroen Vermeulen
Sketch for making copy-missing-translations-from-parent.py runnable as a cron job. |
55 |
series = self._getTargetSeries() |
56 |
||
5619.1.5
by Jeroen Vermeulen
Improvements based on review. |
57 |
# Both translation UI and imports for this series should be blocked
|
58 |
# while the copy is in progress, to reduce the chances of deadlocks or
|
|
59 |
# other conflicts.
|
|
5840.4.1
by Jeroen Vermeulen
Extracted handling of flags, and added test. |
60 |
blocked = ( |
61 |
series.hide_all_translations and series.defer_translation_imports) |
|
62 |
if not blocked and not self.options.force: |
|
63 |
self.txn.abort() |
|
64 |
self.logger.error( |
|
65 |
'Before this process starts, set the '
|
|
66 |
'hide_all_translations and defer_translation_imports '
|
|
67 |
'flags for distribution %s, series %s; or use the ' |
|
68 |
'--force option to make it happen automatically.' % ( |
|
69 |
self.options.distro, self.options.series)) |
|
70 |
sys.exit(1) |
|
4271.1.1
by Jeroen Vermeulen
Fixes bug #116197: protect copy-missing-translations-from-parent from concurrent runs by making it a LaunchpadScript. https://bugs.launchpad.net/rosetta/+bug/116197 |
71 |
|
72 |
self.logger.info('Starting...') |
|
5619.1.1
by Jeroen Vermeulen
Sketch for making copy-missing-translations-from-parent.py runnable as a cron job. |
73 |
|
5840.4.1
by Jeroen Vermeulen
Extracted handling of flags, and added test. |
74 |
# Actual work is done here.
|
7675.193.6
by Henning Eggers
Reviewer comments. |
75 |
copy_distroseries_translations(series, self.txn, self.logger) |
4271.1.1
by Jeroen Vermeulen
Fixes bug #116197: protect copy-missing-translations-from-parent from concurrent runs by making it a LaunchpadScript. https://bugs.launchpad.net/rosetta/+bug/116197 |
76 |
|
77 |
# We would like to update the DistroRelase statistics, but it takes
|
|
78 |
# too long so this should be done after.
|
|
79 |
#
|
|
80 |
# Finally, we changed many things related with cached statistics, so
|
|
81 |
# we may want to update those.
|
|
5121.2.7
by Stuart Bishop
More required code changes |
82 |
# self.logger.info('Updating DistroSeries statistics...')
|
3691.8.105
by Carlos Perello Marin
Applied review comments for postmerge review of r4272 + bug fix for bug #122363 |
83 |
# series.updateStatistics(self.txn)
|
5619.1.1
by Jeroen Vermeulen
Sketch for making copy-missing-translations-from-parent.py runnable as a cron job. |
84 |
|
85 |
self.txn.commit() |
|
5840.4.1
by Jeroen Vermeulen
Extracted handling of flags, and added test. |
86 |
self.logger.info('Done.') |
4271.1.1
by Jeroen Vermeulen
Fixes bug #116197: protect copy-missing-translations-from-parent from concurrent runs by making it a LaunchpadScript. https://bugs.launchpad.net/rosetta/+bug/116197 |
87 |
|
88 |
@property
|
|
89 |
def lockfilename(self): |
|
3691.8.105
by Carlos Perello Marin
Applied review comments for postmerge review of r4272 + bug fix for bug #122363 |
90 |
"""Return lock file name for this script on this distroseries.
|
4271.1.1
by Jeroen Vermeulen
Fixes bug #116197: protect copy-missing-translations-from-parent from concurrent runs by making it a LaunchpadScript. https://bugs.launchpad.net/rosetta/+bug/116197 |
91 |
|
3691.8.105
by Carlos Perello Marin
Applied review comments for postmerge review of r4272 + bug fix for bug #122363 |
92 |
No global lock is needed, only one for the distroseries we operate
|
4271.1.1
by Jeroen Vermeulen
Fixes bug #116197: protect copy-missing-translations-from-parent from concurrent runs by making it a LaunchpadScript. https://bugs.launchpad.net/rosetta/+bug/116197 |
93 |
on. This does mean that our options must have been parsed before this
|
5619.1.1
by Jeroen Vermeulen
Sketch for making copy-missing-translations-from-parent.py runnable as a cron job. |
94 |
property is ever accessed. Luckily that is what the `LaunchpadScript`
|
95 |
code does!
|
|
4271.1.1
by Jeroen Vermeulen
Fixes bug #116197: protect copy-missing-translations-from-parent from concurrent runs by making it a LaunchpadScript. https://bugs.launchpad.net/rosetta/+bug/116197 |
96 |
"""
|
97 |
return "launchpad-%s-%s-%s.lock" % (self.name, self.options.distro, |
|
3691.8.105
by Carlos Perello Marin
Applied review comments for postmerge review of r4272 + bug fix for bug #122363 |
98 |
self.options.series) |
4271.1.1
by Jeroen Vermeulen
Fixes bug #116197: protect copy-missing-translations-from-parent from concurrent runs by making it a LaunchpadScript. https://bugs.launchpad.net/rosetta/+bug/116197 |
99 |
|
3617.3.12
by Carlos Perello Marin
added a script to do the translation migration |
100 |
|
101 |
if __name__ == '__main__': |
|
4271.1.1
by Jeroen Vermeulen
Fixes bug #116197: protect copy-missing-translations-from-parent from concurrent runs by making it a LaunchpadScript. https://bugs.launchpad.net/rosetta/+bug/116197 |
102 |
|
4482.2.1
by Jeroen Vermeulen
Adding "language" column to POMsgSet in preparation for various optimizations |
103 |
script = TranslationsCopier( |
10828.5.1
by Danilo Segan
Provide a separate DB user for translations distroseries copy. |
104 |
'copy-missing-translations', dbuser='translations_distroseries_copy') |
4271.1.1
by Jeroen Vermeulen
Fixes bug #116197: protect copy-missing-translations-from-parent from concurrent runs by making it a LaunchpadScript. https://bugs.launchpad.net/rosetta/+bug/116197 |
105 |
|
106 |
script.lock_and_run() |
|
3617.3.12
by Carlos Perello Marin
added a script to do the translation migration |
107 |