Merge ~cjwatson/launchpad:remove-getPOFilesTouchedSince into launchpad:master

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: 367a79023112c249dd2ec003b4bb1f3dd81e5064
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/launchpad:remove-getPOFilesTouchedSince
Merge into: launchpad:master
Diff against target: 334 lines (+0/-297)
3 files modified
lib/lp/translations/interfaces/pofile.py (+0/-9)
lib/lp/translations/model/pofile.py (+0/-98)
lib/lp/translations/tests/test_pofile.py (+0/-190)
Reviewer Review Type Date Requested Status
Simone Pelosi Approve
Review via email: mp+447291@code.launchpad.net

Commit message

Remove POFileSet.getPOFilesTouchedSince

Description of the change

It hasn't been used since commit 47b797b084.

To post a comment you must log in.
Revision history for this message
Simone Pelosi (pelpsi) wrote :

LGTM!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/lp/translations/interfaces/pofile.py b/lib/lp/translations/interfaces/pofile.py
2index 06700b1..a4f2a42 100644
3--- a/lib/lp/translations/interfaces/pofile.py
4+++ b/lib/lp/translations/interfaces/pofile.py
5@@ -424,12 +424,3 @@ class IPOFileSet(Interface):
6 :param untranslated: Look only for `POFile`s with a credits
7 message that is not translated.
8 """
9-
10- def getPOFilesTouchedSince(date):
11- """Return IDs for PO files that might have been updated since `date`.
12-
13- :param date: A datetime object to use as the starting date.
14-
15- :return: a ResultSet over POFile IDs for directly and indirectly
16- (through sharing POFiles) touched POFiles since `date`.
17- """
18diff --git a/lib/lp/translations/model/pofile.py b/lib/lp/translations/model/pofile.py
19index 1f76e09..ccd9158 100644
20--- a/lib/lp/translations/model/pofile.py
21+++ b/lib/lp/translations/model/pofile.py
22@@ -21,7 +21,6 @@ from storm.expr import (
23 Desc,
24 Exists,
25 Join,
26- LeftJoin,
27 Not,
28 Or,
29 Select,
30@@ -1664,103 +1663,6 @@ class POFileSet:
31 result = IPrimaryStore(POFile).find((POFile, POTMsgSet), clauses)
32 return result.order_by("POFile.id")
33
34- def getPOFilesTouchedSince(self, date):
35- """See `IPOFileSet`."""
36- # Avoid circular imports.
37- from lp.registry.model.distroseries import DistroSeries
38- from lp.registry.model.productseries import ProductSeries
39- from lp.translations.model.potemplate import POTemplate
40-
41- store = IPrimaryStore(POTemplate)
42-
43- # Find a matching POTemplate and its ProductSeries
44- # and DistroSeries, if they are defined.
45- MatchingPOT = ClassAlias(POTemplate)
46- MatchingPOTJoin = Join(
47- MatchingPOT, POFile.potemplate == MatchingPOT.id
48- )
49- MatchingProductSeries = ClassAlias(ProductSeries)
50- MatchingProductSeriesJoin = LeftJoin(
51- MatchingProductSeries,
52- MatchingPOT.productseriesID == MatchingProductSeries.id,
53- )
54- MatchingDistroSeries = ClassAlias(DistroSeries)
55- MatchingDistroSeriesJoin = LeftJoin(
56- MatchingDistroSeries,
57- MatchingPOT.distroseriesID == MatchingDistroSeries.id,
58- )
59-
60- # Find any sharing POTemplate corresponding to MatchingPOT
61- # and its ProductSeries and DistroSeries, if they are defined.
62- OtherPOT = ClassAlias(POTemplate)
63- OtherPOTJoin = Join(OtherPOT, And(OtherPOT.name == MatchingPOT.name))
64- OtherProductSeries = ClassAlias(ProductSeries)
65- OtherProductSeriesJoin = LeftJoin(
66- OtherProductSeries,
67- OtherPOT.productseriesID == OtherProductSeries.id,
68- )
69- OtherDistroSeries = ClassAlias(DistroSeries)
70- OtherDistroSeriesJoin = LeftJoin(
71- OtherDistroSeries, OtherPOT.distroseriesID == OtherDistroSeries.id
72- )
73-
74- # And find a sharing POFile corresponding to a sharing POTemplate,
75- # i.e. OtherPOT.
76- OtherPOFile = ClassAlias(POFile)
77- OtherPOFileJoin = Join(
78- OtherPOFile,
79- And(
80- OtherPOFile.language_id == POFile.language_id,
81- OtherPOFile.potemplate_id == OtherPOT.id,
82- ),
83- )
84-
85- source = store.using(
86- POFile,
87- MatchingPOTJoin,
88- MatchingProductSeriesJoin,
89- MatchingDistroSeriesJoin,
90- OtherPOTJoin,
91- OtherProductSeriesJoin,
92- OtherDistroSeriesJoin,
93- OtherPOFileJoin,
94- )
95-
96- results = source.find(
97- OtherPOFile,
98- And(
99- POFile.date_changed >= date,
100- Or(
101- # OtherPOT is a sharing template with MatchingPOT
102- # in the same distribution and sourcepackagename.
103- And(
104- MatchingPOT.distroseriesID is not None,
105- OtherPOT.distroseriesID is not None,
106- (
107- MatchingDistroSeries.distributionID
108- == OtherDistroSeries.distributionID
109- ),
110- (
111- MatchingPOT.sourcepackagenameID
112- == OtherPOT.sourcepackagenameID
113- ),
114- ),
115- # OtherPOT is a sharing template with MatchingPOT
116- # in the same product.
117- And(
118- MatchingPOT.productseriesID is not None,
119- OtherPOT.productseriesID is not None,
120- (
121- MatchingProductSeries.productID
122- == OtherProductSeries.productID
123- ),
124- ),
125- ),
126- ),
127- )
128- results.config(distinct=True)
129- return results
130-
131
132 @implementer(ITranslationFileData)
133 class POFileToTranslationFileDataAdapter:
134diff --git a/lib/lp/translations/tests/test_pofile.py b/lib/lp/translations/tests/test_pofile.py
135index 0c8547b..1d919a1 100644
136--- a/lib/lp/translations/tests/test_pofile.py
137+++ b/lib/lp/translations/tests/test_pofile.py
138@@ -1645,196 +1645,6 @@ class TestPOFileSet(TestCaseWithFactory):
139 super().setUp()
140 self.pofileset = getUtility(IPOFileSet)
141
142- def test_POFileSet_getPOFilesTouchedSince_none(self):
143- # Make sure getPOFilesTouchedSince returns nothing
144- # when there are no touched PO files.
145- now = datetime.now(timezone.utc)
146- pofiles = self.pofileset.getPOFilesTouchedSince(now)
147- self.assertContentEqual([], pofiles)
148-
149- week_ago = now - timedelta(7)
150- pofiles = self.pofileset.getPOFilesTouchedSince(week_ago)
151- self.assertContentEqual([], pofiles)
152-
153- # Even when a POFile is touched, but earlier than
154- # what we are looking for, nothing is returned.
155- pofile = self.factory.makePOFile("sr")
156- pofile.date_changed = week_ago
157- pofiles = self.pofileset.getPOFilesTouchedSince(now)
158- self.assertContentEqual([], pofiles)
159-
160- def test_POFileSet_getPOFilesTouchedSince_unshared(self):
161- # Make sure actual touched POFiles are returned by
162- # getPOFilesTouchedSince.
163- now = datetime.now(timezone.utc)
164- yesterday = now - timedelta(1)
165-
166- new_pofile = self.factory.makePOFile("sr")
167- new_pofile.date_changed = now
168- pofiles = self.pofileset.getPOFilesTouchedSince(yesterday)
169- self.assertContentEqual([new_pofile], pofiles)
170-
171- # An older file means is not returned.
172- week_ago = now - timedelta(7)
173- old_pofile = self.factory.makePOFile("sr")
174- old_pofile.date_changed = week_ago
175- pofiles = self.pofileset.getPOFilesTouchedSince(yesterday)
176- self.assertContentEqual([new_pofile], pofiles)
177-
178- # Unless we extend the time period we ask for.
179- pofiles = self.pofileset.getPOFilesTouchedSince(week_ago)
180- self.assertContentEqual([new_pofile, old_pofile], pofiles)
181-
182- def test_POFileSet_getPOFilesTouchedSince_shared_in_product(self):
183- # Make sure actual touched POFiles and POFiles that are sharing
184- # with them in the same product are all returned by
185- # getPOFilesTouchedSince.
186-
187- # We create a product with two series, and attach
188- # a POTemplate and Serbian POFile to each, making
189- # sure they share translations (potemplates have the same name).
190- product = self.factory.makeProduct(
191- translations_usage=ServiceUsage.LAUNCHPAD
192- )
193- series1 = self.factory.makeProductSeries(product=product, name="one")
194- series2 = self.factory.makeProductSeries(product=product, name="two")
195- potemplate1 = self.factory.makePOTemplate(
196- name="shared", productseries=series1
197- )
198- pofile1 = self.factory.makePOFile("sr", potemplate=potemplate1)
199- potemplate2 = self.factory.makePOTemplate(
200- name="shared", productseries=series2
201- )
202- pofile2 = potemplate2.getPOFileByLang("sr")
203-
204- now = datetime.now(timezone.utc)
205- yesterday = now - timedelta(1)
206- pofiles = self.pofileset.getPOFilesTouchedSince(yesterday)
207- self.assertContentEqual([pofile1, pofile2], pofiles)
208-
209- # Even if one of the sharing POFiles is older, it's still returned.
210- week_ago = now - timedelta(7)
211- pofile2.date_changed = week_ago
212- pofiles = self.pofileset.getPOFilesTouchedSince(yesterday)
213- self.assertContentEqual([pofile1, pofile2], pofiles)
214-
215- # A POFile in a different language is not returned.
216- pofile3 = self.factory.makePOFile("de", potemplate=potemplate2)
217- pofile3.date_changed = week_ago
218- pofiles = self.pofileset.getPOFilesTouchedSince(yesterday)
219- self.assertContentEqual([pofile1, pofile2], pofiles)
220-
221- def test_POFileSet_getPOFilesTouchedSince_smaller_ids(self):
222- # Make sure that all relevant POFiles are returned,
223- # even the sharing ones with smaller IDs.
224- # This is a test for bug #414832 which caused sharing POFiles
225- # of the touched POFile not to be returned if they had
226- # IDs smaller than the touched POFile.
227- product = self.factory.makeProduct(
228- translations_usage=ServiceUsage.LAUNCHPAD
229- )
230- series1 = self.factory.makeProductSeries(product=product, name="one")
231- series2 = self.factory.makeProductSeries(product=product, name="two")
232- potemplate1 = self.factory.makePOTemplate(
233- name="shared", productseries=series1
234- )
235- pofile1 = self.factory.makePOFile("sr", potemplate=potemplate1)
236- potemplate2 = self.factory.makePOTemplate(
237- name="shared", productseries=series2
238- )
239- pofile2 = potemplate2.getPOFileByLang("sr")
240- now = datetime.now(timezone.utc)
241- yesterday = now - timedelta(1)
242- week_ago = now - timedelta(7)
243- pofile1.date_changed = week_ago
244-
245- # Let's make sure the condition from the bug holds,
246- # since pofile2 is created implicitly with the makePOTemplate call.
247- self.assertTrue(pofile1.id < pofile2.id)
248- pofiles = self.pofileset.getPOFilesTouchedSince(yesterday)
249- self.assertContentEqual([pofile1, pofile2], pofiles)
250-
251- def test_POFileSet_getPOFilesTouchedSince_shared_in_distribution(self):
252- # Make sure actual touched POFiles and POFiles that are sharing
253- # with them in the same distribution/sourcepackage are all returned
254- # by getPOFilesTouchedSince.
255-
256- # We create a distribution with two series with the same
257- # sourcepackage in both, and attach a POTemplate and Serbian
258- # POFile to each, making sure they share translations
259- # (potemplates have the same name).
260- distro = self.factory.makeDistribution()
261- distro.translations_usage = ServiceUsage.LAUNCHPAD
262- series1 = self.factory.makeDistroSeries(
263- distribution=distro, name="one"
264- )
265- sourcepackagename = self.factory.makeSourcePackageName()
266- potemplate1 = self.factory.makePOTemplate(
267- name="shared",
268- distroseries=series1,
269- sourcepackagename=sourcepackagename,
270- )
271- pofile1 = self.factory.makePOFile("sr", potemplate=potemplate1)
272-
273- series2 = self.factory.makeDistroSeries(
274- distribution=distro, name="two"
275- )
276- potemplate2 = self.factory.makePOTemplate(
277- name="shared",
278- distroseries=series2,
279- sourcepackagename=sourcepackagename,
280- )
281- pofile2 = potemplate2.getPOFileByLang("sr")
282-
283- # Now the test actually starts.
284- now = datetime.now(timezone.utc)
285- yesterday = now - timedelta(1)
286- pofiles = self.pofileset.getPOFilesTouchedSince(yesterday)
287- self.assertContentEqual([pofile1, pofile2], pofiles)
288-
289- # Even if one of the sharing POFiles is older, it's still returned.
290- week_ago = now - timedelta(7)
291- pofile2.date_changed = week_ago
292- pofiles = self.pofileset.getPOFilesTouchedSince(yesterday)
293- self.assertContentEqual([pofile1, pofile2], pofiles)
294-
295- # A POFile in a different language is not returned.
296- pofile3 = self.factory.makePOFile("de", potemplate=potemplate2)
297- pofile3.date_changed = week_ago
298- pofiles = self.pofileset.getPOFilesTouchedSince(yesterday)
299- self.assertContentEqual([pofile1, pofile2], pofiles)
300-
301- def test_POFileSet_getPOFilesTouchedSince_external_pofiles(self):
302- # Make sure POFiles which are in different products
303- # are not returned even though they have the same potemplate name.
304- series1 = self.factory.makeProductSeries(name="one")
305- series1.product.translations_usage = ServiceUsage.LAUNCHPAD
306- series2 = self.factory.makeProductSeries(name="two")
307- series1.product.translations_usage = ServiceUsage.LAUNCHPAD
308- self.assertNotEqual(series1.product, series2.product)
309-
310- potemplate1 = self.factory.makePOTemplate(
311- name="shared", productseries=series1
312- )
313- pofile1 = self.factory.makePOFile("sr", potemplate=potemplate1)
314-
315- potemplate2 = self.factory.makePOTemplate(
316- name="shared", productseries=series2
317- )
318- pofile2 = self.factory.makePOFile("sr", potemplate=potemplate2)
319-
320- # Now the test actually starts.
321- now = datetime.now(timezone.utc)
322- yesterday = now - timedelta(1)
323- week_ago = now - timedelta(7)
324-
325- # Second POFile has been modified earlier than yesterday,
326- # and is attached to a different product, even if the template
327- # name is the same. It's not returned.
328- pofile2.date_changed = week_ago
329- pofiles = self.pofileset.getPOFilesTouchedSince(yesterday)
330- self.assertContentEqual([pofile1], pofiles)
331-
332 def test_getPOFilesWithTranslationCredits(self):
333 # Initially, we only get data from the sampledata.
334 sampledata_pofiles = list(

Subscribers

People subscribed via source and target branches

to status/vote changes: