← Back to team overview

launchpad-reviewers team mailing list archive

[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)
Related bugs:
  Bug #903532 in Launchpad itself: "Translations statistics not being updated"
  https://bugs.launchpad.net/launchpad/+bug/903532

For more details, see:
https://code.launchpad.net/~benji/launchpad/bug-903532/+merge/86820

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/86820
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~benji/launchpad/bug-903532 into lp:launchpad.
=== modified file 'lib/lp/translations/model/pofilestatsjob.py'
--- lib/lp/translations/model/pofilestatsjob.py	2011-12-21 19:55:17 +0000
+++ lib/lp/translations/model/pofilestatsjob.py	2011-12-23 17:40:35 +0000
@@ -74,6 +74,26 @@
         logger.info('Updating statistics for %s' % self.pofile.title)
         self.pofile.updateStatistics()
 
+<<<<<<< TREE
+=======
+        # 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,
+            distribution=self.pofile.potemplate.distribution,
+            sourcepackagename=self.pofile.potemplate.sourcepackagename)
+        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:
+            pofile = template.getPOFileByLang(self.pofile.language.code)
+            if pofile is None:
+                continue
+            pofile.updateStatistics()
+
+>>>>>>> MERGE-SOURCE
     @staticmethod
     def iterReady():
         """See `IJobSource`."""

=== modified file 'lib/lp/translations/tests/test_pofilestatsjob.py'
--- lib/lp/translations/tests/test_pofilestatsjob.py	2011-12-21 19:55:17 +0000
+++ lib/lp/translations/tests/test_pofilestatsjob.py	2011-12-23 17:40:35 +0000
@@ -93,3 +93,103 @@
         # is added.
         pofilestatsjob.schedule(pofile.id)
         self.assertIs(len(list(POFileStatsJob.iterReady())), 2)
+<<<<<<< TREE
+=======
+
+    def assertJobUpdatesStats(self, pofile1, pofile2):
+        # Create a single POTMsgSet and add it to only one of the POTemplates.
+        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))
+
+    def test_run_with_project_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')
+
+        self.factory.makeLanguage('en-tt')
+        pofile1 = self.factory.makePOFile('en-tt', template1)
+        pofile2 = self.factory.makePOFile('en-tt', template2)
+
+        self.assertJobUpdatesStats(pofile1, pofile2)
+
+    def test_run_with_product_and_distro_translation_sharing(self):
+        language = self.factory.makeLanguage('en-tt')
+        distroseries = self.factory.makeUbuntuDistroSeries()
+        distroseries.distribution.translation_focus = distroseries
+        sourcepackagename = self.factory.makeSourcePackageName()
+        sourcepackage = self.factory.makeSourcePackage(
+            distroseries=distroseries,
+            sourcepackagename=sourcepackagename)
+        productseries = self.factory.makeProductSeries()
+        sourcepackage.setPackaging(
+            productseries, self.factory.makePerson())
+
+        # Create template ready for sharing on the Ubuntu side.
+        template1 = self.factory.makePOTemplate(
+            distroseries=distroseries,
+            sourcepackagename=sourcepackagename,
+            name='messages')
+        pofile1 = self.factory.makePOFile(
+            language=language, potemplate=template1)
+
+        # Create template ready for sharing on the upstream side.
+        template2 = self.factory.makePOTemplate(
+            productseries=productseries, name='messages')
+        pofile2 = template2.getPOFileByLang(language.code)
+
+        self.assertJobUpdatesStats(pofile1, pofile2)
+
+    def test_run_with_distro_translation_sharing(self):
+        language = self.factory.makeLanguage('en-tt')
+        distroseries1 = self.factory.makeUbuntuDistroSeries()
+        distroseries1.distribution.translation_focus = distroseries1
+        sourcepackagename = self.factory.makeSourcePackageName()
+        self.factory.makeSourcePackage(
+            distroseries=distroseries1,
+            sourcepackagename=sourcepackagename)
+        distroseries2 = self.factory.makeUbuntuDistroSeries()
+        distroseries2.distribution.translation_focus = distroseries2
+        self.factory.makeSourcePackage(
+            distroseries=distroseries2,
+            sourcepackagename=sourcepackagename)
+
+        template1 = self.factory.makePOTemplate(
+            distroseries=distroseries1,
+            sourcepackagename=sourcepackagename,
+            name='messages')
+        pofile1 = self.factory.makePOFile(
+            language=language, potemplate=template1)
+
+        template2 = self.factory.makePOTemplate(
+            distroseries=distroseries2,
+            sourcepackagename=sourcepackagename,
+            name='messages')
+        pofile2 = template2.getPOFileByLang(language.code)
+
+        self.assertJobUpdatesStats(pofile1, pofile2)
+>>>>>>> MERGE-SOURCE