launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #05987
[Merge] lp:~benji/launchpad/bug-903532 into lp:launchpad
Benji York has proposed merging lp:~benji/launchpad/bug-903532 into lp:launchpad.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~benji/launchpad/bug-903532/+merge/86426
Bug 903532 is about a task that was thought to have been done, but half
still needed to be done. This branch does the other half.
The root issue is that when updating the statistics for a POFile, any
POFiles that share translations with the original POFile need to be
updated as well.
The new code (in pofilestatsjob.py) simply loops over all the POFiles
that share translations with the POFile associated with the job and, if
the languages match, updates their statistics as well.
The tests can be run with this command:
bin/test -c -m lp.translations.tests.test_pofilestatsjob
QA:
1) Note the statistics for the translations listed in bug 904012 (a
related bug)
2) Make a suggestion for one of those translations
3) Get webops to run cronscripts/run_jobs.py pofile_stats
4) Check to see if both the statistics for the translation you changed
were updated as well as the statistics for the shared translation
Lint: the "make lint" report is clean.
--
https://code.launchpad.net/~benji/launchpad/bug-903532/+merge/86426
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~benji/launchpad/bug-903532 into lp:launchpad.
=== modified file 'database/schema/security.cfg'
--- database/schema/security.cfg 2011-12-18 08:14:12 +0000
+++ database/schema/security.cfg 2011-12-20 16:21:13 +0000
@@ -444,6 +444,7 @@
public.pofile = SELECT, UPDATE
public.potemplate = SELECT, UPDATE
public.job = SELECT, UPDATE, DELETE
+public.packaging = SELECT
public.pofilestatsjob = SELECT, UPDATE, DELETE
public.potmsgset = SELECT
public.product = SELECT
=== modified file 'lib/lp/translations/model/pofilestatsjob.py'
--- lib/lp/translations/model/pofilestatsjob.py 2011-12-19 23:38:16 +0000
+++ lib/lp/translations/model/pofilestatsjob.py 2011-12-20 16:21:13 +0000
@@ -34,6 +34,7 @@
from lp.services.job.model.job import Job
from lp.services.job.runner import BaseRunnableJob
from lp.translations.interfaces.pofilestatsjob import IPOFileStatsJobSource
+from lp.translations.interfaces.potemplate import IPOTemplateSet
from lp.translations.model.pofile import POFile
@@ -72,8 +73,24 @@
"""See `IRunnableJob`."""
logger = logging.getLogger()
logger.info('Updating statistics for %s' % self.pofile.title)
+ # First update the statistics for the POFile that was directly
+ # modified.
self.pofile.updateStatistics()
+ # Next we have to find any POFiles that share translations with the
+ # above POFile so we can update their statistics too. To do that we
+ # first have to find the set of shared templates.
+ subset = getUtility(IPOTemplateSet).getSharingSubset(
+ product=self.pofile.potemplate.product)
+ shared_templates = subset.getSharingPOTemplates(
+ self.pofile.potemplate.name)
+ # Now we have to find any POFiles that translate the shared templates
+ # into the same language as the POFile this job is about.
+ for template in shared_templates:
+ for pofile in template.pofiles:
+ if pofile.language == self.pofile.language:
+ pofile.updateStatistics()
+
@staticmethod
def iterReady():
"""See `IJobSource`."""
=== modified file 'lib/lp/translations/tests/test_pofilestatsjob.py'
--- lib/lp/translations/tests/test_pofilestatsjob.py 2011-12-19 23:38:16 +0000
+++ lib/lp/translations/tests/test_pofilestatsjob.py 2011-12-20 16:21:13 +0000
@@ -93,3 +93,44 @@
# is added.
pofilestatsjob.schedule(pofile.id)
self.assertIs(len(list(POFileStatsJob.iterReady())), 2)
+
+ def test_run_with_shared_template(self):
+ # Create a product with two series and sharing POTemplates
+ # in different series ('devel' and 'stable').
+ product = self.factory.makeProduct(
+ translations_usage=ServiceUsage.LAUNCHPAD)
+ devel = self.factory.makeProductSeries(
+ name='devel', product=product)
+ stable = self.factory.makeProductSeries(
+ name='stable', product=product)
+
+ # POTemplate is a 'sharing' one if it has the same name ('messages').
+ template1 = self.factory.makePOTemplate(devel, name='messages')
+ template2 = self.factory.makePOTemplate(stable, name='messages')
+
+ # Create a single POTMsgSet and add it to only one of the POTemplates.
+ self.potmsgset = self.factory.makePOTMsgSet(template1)
+
+ self.factory.makeLanguage('en-tt')
+ pofile1 = self.factory.makePOFile('en-tt', template1)
+ pofile2 = self.factory.makePOFile('en-tt', template2)
+
+ self.factory.makeSuggestion(pofile1)
+ self.factory.makeSuggestion(pofile2)
+
+ # The statistics start at 0.
+ self.assertEqual(pofile1.getStatistics(), (0, 0, 0, 0))
+ self.assertEqual(pofile2.getStatistics(), (0, 0, 0, 0))
+ job = pofilestatsjob.schedule(pofile1.id)
+ # Just scheduling the job doesn't update the statistics.
+ self.assertEqual(pofile1.getStatistics(), (0, 0, 0, 0))
+ self.assertEqual(pofile2.getStatistics(), (0, 0, 0, 0))
+ with dbuser(config.pofile_stats.dbuser):
+ job.run()
+ # Now that the job ran, the statistics for the POFile have been
+ # updated.
+ self.assertEqual(pofile1.getStatistics(), (0, 0, 0, 1))
+ # The statistics for the other POFile is also updated as a result of
+ # running the job for the other POFile because they share
+ # translations.
+ self.assertEqual(pofile2.getStatistics(), (0, 0, 0, 1))