Merge lp:~benji/launchpad/bug-903532 into lp:launchpad

Proposed by Benji York
Status: Merged
Approved by: Benji York
Approved revision: no longer in the source branch.
Merged at revision: 14639
Proposed branch: lp:~benji/launchpad/bug-903532
Merge into: lp:launchpad
Diff against target: 161 lines (+117/-1)
3 files modified
database/schema/security.cfg (+1/-0)
lib/lp/translations/model/pofilestatsjob.py (+18/-0)
lib/lp/translations/tests/test_pofilestatsjob.py (+98/-1)
To merge this branch: bzr merge lp:~benji/launchpad/bug-903532
Reviewer Review Type Date Requested Status
Benji York (community) Approve
Review via email: mp+86820@code.launchpad.net

Commit message

[r=benji] make POFile statistics update jobs also update the stats for related POFiles

Description of the change

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.

To post a comment you must log in.
Revision history for this message
Benji York (benji) wrote :

This MP is for a bug-fix version of the branch that failed QA. The fix
wasn't involved (see discussion on [1]_ for full details) so I'm just
self-reviewing the changes.

.. [1] https://code.launchpad.net/~benji/launchpad/bug-903532/+merge/86426

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'database/schema/security.cfg'
--- database/schema/security.cfg 2012-01-03 01:40:09 +0000
+++ database/schema/security.cfg 2012-01-04 16:22:26 +0000
@@ -441,6 +441,7 @@
441[pofilestats]441[pofilestats]
442groups=script442groups=script
443public.language = SELECT443public.language = SELECT
444public.packaging = SELECT
444public.pofile = SELECT, UPDATE445public.pofile = SELECT, UPDATE
445public.potemplate = SELECT, UPDATE446public.potemplate = SELECT, UPDATE
446public.job = SELECT, UPDATE, DELETE447public.job = SELECT, UPDATE, DELETE
447448
=== modified file 'lib/lp/translations/model/pofilestatsjob.py'
--- lib/lp/translations/model/pofilestatsjob.py 2012-01-01 02:58:52 +0000
+++ lib/lp/translations/model/pofilestatsjob.py 2012-01-04 16:22:26 +0000
@@ -34,6 +34,7 @@
34 MAIN_STORE,34 MAIN_STORE,
35 )35 )
36from lp.translations.interfaces.pofilestatsjob import IPOFileStatsJobSource36from lp.translations.interfaces.pofilestatsjob import IPOFileStatsJobSource
37from lp.translations.interfaces.potemplate import IPOTemplateSet
37from lp.translations.model.pofile import POFile38from lp.translations.model.pofile import POFile
3839
3940
@@ -74,6 +75,23 @@
74 logger.info('Updating statistics for %s' % self.pofile.title)75 logger.info('Updating statistics for %s' % self.pofile.title)
75 self.pofile.updateStatistics()76 self.pofile.updateStatistics()
7677
78 # Next we have to find any POFiles that share translations with the
79 # above POFile so we can update their statistics too. To do that we
80 # first have to find the set of shared templates.
81 subset = getUtility(IPOTemplateSet).getSharingSubset(
82 product=self.pofile.potemplate.product,
83 distribution=self.pofile.potemplate.distribution,
84 sourcepackagename=self.pofile.potemplate.sourcepackagename)
85 shared_templates = subset.getSharingPOTemplates(
86 self.pofile.potemplate.name)
87 # Now we have to find any POFiles that translate the shared templates
88 # into the same language as the POFile this job is about.
89 for template in shared_templates:
90 pofile = template.getPOFileByLang(self.pofile.language.code)
91 if pofile is None:
92 continue
93 pofile.updateStatistics()
94
77 @staticmethod95 @staticmethod
78 def iterReady():96 def iterReady():
79 """See `IJobSource`."""97 """See `IJobSource`."""
8098
=== modified file 'lib/lp/translations/tests/test_pofilestatsjob.py'
--- lib/lp/translations/tests/test_pofilestatsjob.py 2012-01-01 02:58:52 +0000
+++ lib/lp/translations/tests/test_pofilestatsjob.py 2012-01-04 16:22:26 +0000
@@ -51,7 +51,7 @@
51 # Now that the job ran, the statistics have been updated.51 # Now that the job ran, the statistics have been updated.
52 self.assertEqual(pofile.potemplate.messageCount(), 1)52 self.assertEqual(pofile.potemplate.messageCount(), 1)
5353
54 def test_with_product(self):54 def test_run_with_product(self):
55 product = self.factory.makeProduct(55 product = self.factory.makeProduct(
56 translations_usage=ServiceUsage.LAUNCHPAD)56 translations_usage=ServiceUsage.LAUNCHPAD)
57 productseries = self.factory.makeProductSeries(product=product)57 productseries = self.factory.makeProductSeries(product=product)
@@ -93,3 +93,100 @@
93 # is added.93 # is added.
94 pofilestatsjob.schedule(pofile.id)94 pofilestatsjob.schedule(pofile.id)
95 self.assertIs(len(list(POFileStatsJob.iterReady())), 2)95 self.assertIs(len(list(POFileStatsJob.iterReady())), 2)
96
97 def assertJobUpdatesStats(self, pofile1, pofile2):
98 # Create a single POTMsgSet and add it to only one of the POTemplates.
99 self.factory.makeSuggestion(pofile1)
100 self.factory.makeSuggestion(pofile2)
101 # The statistics start at 0.
102 self.assertEqual(pofile1.getStatistics(), (0, 0, 0, 0))
103 self.assertEqual(pofile2.getStatistics(), (0, 0, 0, 0))
104 job = pofilestatsjob.schedule(pofile1.id)
105 # Just scheduling the job doesn't update the statistics.
106 self.assertEqual(pofile1.getStatistics(), (0, 0, 0, 0))
107 self.assertEqual(pofile2.getStatistics(), (0, 0, 0, 0))
108 with dbuser(config.pofile_stats.dbuser):
109 job.run()
110 # Now that the job ran, the statistics for the POFile have been
111 # updated.
112 self.assertEqual(pofile1.getStatistics(), (0, 0, 0, 1))
113 # The statistics for the other POFile is also updated as a result of
114 # running the job for the other POFile because they share
115 # translations.
116 self.assertEqual(pofile2.getStatistics(), (0, 0, 0, 1))
117
118 def test_run_with_project_shared_template(self):
119 # Create a product with two series and sharing POTemplates
120 # in different series ('devel' and 'stable').
121 product = self.factory.makeProduct(
122 translations_usage=ServiceUsage.LAUNCHPAD)
123 devel = self.factory.makeProductSeries(
124 name='devel', product=product)
125 stable = self.factory.makeProductSeries(
126 name='stable', product=product)
127
128 # POTemplate is a 'sharing' one if it has the same name ('messages').
129 template1 = self.factory.makePOTemplate(devel, name='messages')
130 template2 = self.factory.makePOTemplate(stable, name='messages')
131
132 self.factory.makeLanguage('en-tt')
133 pofile1 = self.factory.makePOFile('en-tt', template1)
134 pofile2 = self.factory.makePOFile('en-tt', template2)
135
136 self.assertJobUpdatesStats(pofile1, pofile2)
137
138 def test_run_with_product_and_distro_translation_sharing(self):
139 language = self.factory.makeLanguage('en-tt')
140 distroseries = self.factory.makeUbuntuDistroSeries()
141 distroseries.distribution.translation_focus = distroseries
142 sourcepackagename = self.factory.makeSourcePackageName()
143 sourcepackage = self.factory.makeSourcePackage(
144 distroseries=distroseries,
145 sourcepackagename=sourcepackagename)
146 productseries = self.factory.makeProductSeries()
147 sourcepackage.setPackaging(
148 productseries, self.factory.makePerson())
149
150 # Create template ready for sharing on the Ubuntu side.
151 template1 = self.factory.makePOTemplate(
152 distroseries=distroseries,
153 sourcepackagename=sourcepackagename,
154 name='messages')
155 pofile1 = self.factory.makePOFile(
156 language=language, potemplate=template1)
157
158 # Create template ready for sharing on the upstream side.
159 template2 = self.factory.makePOTemplate(
160 productseries=productseries, name='messages')
161 pofile2 = template2.getPOFileByLang(language.code)
162
163 self.assertJobUpdatesStats(pofile1, pofile2)
164
165 def test_run_with_distro_translation_sharing(self):
166 language = self.factory.makeLanguage('en-tt')
167 distroseries1 = self.factory.makeUbuntuDistroSeries()
168 distroseries1.distribution.translation_focus = distroseries1
169 sourcepackagename = self.factory.makeSourcePackageName()
170 self.factory.makeSourcePackage(
171 distroseries=distroseries1,
172 sourcepackagename=sourcepackagename)
173 distroseries2 = self.factory.makeUbuntuDistroSeries()
174 distroseries2.distribution.translation_focus = distroseries2
175 self.factory.makeSourcePackage(
176 distroseries=distroseries2,
177 sourcepackagename=sourcepackagename)
178
179 template1 = self.factory.makePOTemplate(
180 distroseries=distroseries1,
181 sourcepackagename=sourcepackagename,
182 name='messages')
183 pofile1 = self.factory.makePOFile(
184 language=language, potemplate=template1)
185
186 template2 = self.factory.makePOTemplate(
187 distroseries=distroseries2,
188 sourcepackagename=sourcepackagename,
189 name='messages')
190 pofile2 = template2.getPOFileByLang(language.code)
191
192 self.assertJobUpdatesStats(pofile1, pofile2)