Colin Watson has proposed merging ~cjwatson/launchpad:remove-getPOFilesTouchedSince into launchpad:master.
Commit message: Remove POFileSet.getPOFilesTouchedSince Requested reviews: Launchpad code reviewers (launchpad-reviewers) For more details, see: https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/447291 It hasn't been used since commit 47b797b084. -- Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:remove-getPOFilesTouchedSince into launchpad:master.
diff --git a/lib/lp/translations/interfaces/pofile.py b/lib/lp/translations/interfaces/pofile.py index 06700b1..a4f2a42 100644 --- a/lib/lp/translations/interfaces/pofile.py +++ b/lib/lp/translations/interfaces/pofile.py @@ -424,12 +424,3 @@ class IPOFileSet(Interface): :param untranslated: Look only for `POFile`s with a credits message that is not translated. """ - - def getPOFilesTouchedSince(date): - """Return IDs for PO files that might have been updated since `date`. - - :param date: A datetime object to use as the starting date. - - :return: a ResultSet over POFile IDs for directly and indirectly - (through sharing POFiles) touched POFiles since `date`. - """ diff --git a/lib/lp/translations/model/pofile.py b/lib/lp/translations/model/pofile.py index 1f76e09..ccd9158 100644 --- a/lib/lp/translations/model/pofile.py +++ b/lib/lp/translations/model/pofile.py @@ -21,7 +21,6 @@ from storm.expr import ( Desc, Exists, Join, - LeftJoin, Not, Or, Select, @@ -1664,103 +1663,6 @@ class POFileSet: result = IPrimaryStore(POFile).find((POFile, POTMsgSet), clauses) return result.order_by("POFile.id") - def getPOFilesTouchedSince(self, date): - """See `IPOFileSet`.""" - # Avoid circular imports. - from lp.registry.model.distroseries import DistroSeries - from lp.registry.model.productseries import ProductSeries - from lp.translations.model.potemplate import POTemplate - - store = IPrimaryStore(POTemplate) - - # Find a matching POTemplate and its ProductSeries - # and DistroSeries, if they are defined. - MatchingPOT = ClassAlias(POTemplate) - MatchingPOTJoin = Join( - MatchingPOT, POFile.potemplate == MatchingPOT.id - ) - MatchingProductSeries = ClassAlias(ProductSeries) - MatchingProductSeriesJoin = LeftJoin( - MatchingProductSeries, - MatchingPOT.productseriesID == MatchingProductSeries.id, - ) - MatchingDistroSeries = ClassAlias(DistroSeries) - MatchingDistroSeriesJoin = LeftJoin( - MatchingDistroSeries, - MatchingPOT.distroseriesID == MatchingDistroSeries.id, - ) - - # Find any sharing POTemplate corresponding to MatchingPOT - # and its ProductSeries and DistroSeries, if they are defined. - OtherPOT = ClassAlias(POTemplate) - OtherPOTJoin = Join(OtherPOT, And(OtherPOT.name == MatchingPOT.name)) - OtherProductSeries = ClassAlias(ProductSeries) - OtherProductSeriesJoin = LeftJoin( - OtherProductSeries, - OtherPOT.productseriesID == OtherProductSeries.id, - ) - OtherDistroSeries = ClassAlias(DistroSeries) - OtherDistroSeriesJoin = LeftJoin( - OtherDistroSeries, OtherPOT.distroseriesID == OtherDistroSeries.id - ) - - # And find a sharing POFile corresponding to a sharing POTemplate, - # i.e. OtherPOT. - OtherPOFile = ClassAlias(POFile) - OtherPOFileJoin = Join( - OtherPOFile, - And( - OtherPOFile.language_id == POFile.language_id, - OtherPOFile.potemplate_id == OtherPOT.id, - ), - ) - - source = store.using( - POFile, - MatchingPOTJoin, - MatchingProductSeriesJoin, - MatchingDistroSeriesJoin, - OtherPOTJoin, - OtherProductSeriesJoin, - OtherDistroSeriesJoin, - OtherPOFileJoin, - ) - - results = source.find( - OtherPOFile, - And( - POFile.date_changed >= date, - Or( - # OtherPOT is a sharing template with MatchingPOT - # in the same distribution and sourcepackagename. - And( - MatchingPOT.distroseriesID is not None, - OtherPOT.distroseriesID is not None, - ( - MatchingDistroSeries.distributionID - == OtherDistroSeries.distributionID - ), - ( - MatchingPOT.sourcepackagenameID - == OtherPOT.sourcepackagenameID - ), - ), - # OtherPOT is a sharing template with MatchingPOT - # in the same product. - And( - MatchingPOT.productseriesID is not None, - OtherPOT.productseriesID is not None, - ( - MatchingProductSeries.productID - == OtherProductSeries.productID - ), - ), - ), - ), - ) - results.config(distinct=True) - return results - @implementer(ITranslationFileData) class POFileToTranslationFileDataAdapter: diff --git a/lib/lp/translations/tests/test_pofile.py b/lib/lp/translations/tests/test_pofile.py index 0c8547b..1d919a1 100644 --- a/lib/lp/translations/tests/test_pofile.py +++ b/lib/lp/translations/tests/test_pofile.py @@ -1645,196 +1645,6 @@ class TestPOFileSet(TestCaseWithFactory): super().setUp() self.pofileset = getUtility(IPOFileSet) - def test_POFileSet_getPOFilesTouchedSince_none(self): - # Make sure getPOFilesTouchedSince returns nothing - # when there are no touched PO files. - now = datetime.now(timezone.utc) - pofiles = self.pofileset.getPOFilesTouchedSince(now) - self.assertContentEqual([], pofiles) - - week_ago = now - timedelta(7) - pofiles = self.pofileset.getPOFilesTouchedSince(week_ago) - self.assertContentEqual([], pofiles) - - # Even when a POFile is touched, but earlier than - # what we are looking for, nothing is returned. - pofile = self.factory.makePOFile("sr") - pofile.date_changed = week_ago - pofiles = self.pofileset.getPOFilesTouchedSince(now) - self.assertContentEqual([], pofiles) - - def test_POFileSet_getPOFilesTouchedSince_unshared(self): - # Make sure actual touched POFiles are returned by - # getPOFilesTouchedSince. - now = datetime.now(timezone.utc) - yesterday = now - timedelta(1) - - new_pofile = self.factory.makePOFile("sr") - new_pofile.date_changed = now - pofiles = self.pofileset.getPOFilesTouchedSince(yesterday) - self.assertContentEqual([new_pofile], pofiles) - - # An older file means is not returned. - week_ago = now - timedelta(7) - old_pofile = self.factory.makePOFile("sr") - old_pofile.date_changed = week_ago - pofiles = self.pofileset.getPOFilesTouchedSince(yesterday) - self.assertContentEqual([new_pofile], pofiles) - - # Unless we extend the time period we ask for. - pofiles = self.pofileset.getPOFilesTouchedSince(week_ago) - self.assertContentEqual([new_pofile, old_pofile], pofiles) - - def test_POFileSet_getPOFilesTouchedSince_shared_in_product(self): - # Make sure actual touched POFiles and POFiles that are sharing - # with them in the same product are all returned by - # getPOFilesTouchedSince. - - # We create a product with two series, and attach - # a POTemplate and Serbian POFile to each, making - # sure they share translations (potemplates have the same name). - product = self.factory.makeProduct( - translations_usage=ServiceUsage.LAUNCHPAD - ) - series1 = self.factory.makeProductSeries(product=product, name="one") - series2 = self.factory.makeProductSeries(product=product, name="two") - potemplate1 = self.factory.makePOTemplate( - name="shared", productseries=series1 - ) - pofile1 = self.factory.makePOFile("sr", potemplate=potemplate1) - potemplate2 = self.factory.makePOTemplate( - name="shared", productseries=series2 - ) - pofile2 = potemplate2.getPOFileByLang("sr") - - now = datetime.now(timezone.utc) - yesterday = now - timedelta(1) - pofiles = self.pofileset.getPOFilesTouchedSince(yesterday) - self.assertContentEqual([pofile1, pofile2], pofiles) - - # Even if one of the sharing POFiles is older, it's still returned. - week_ago = now - timedelta(7) - pofile2.date_changed = week_ago - pofiles = self.pofileset.getPOFilesTouchedSince(yesterday) - self.assertContentEqual([pofile1, pofile2], pofiles) - - # A POFile in a different language is not returned. - pofile3 = self.factory.makePOFile("de", potemplate=potemplate2) - pofile3.date_changed = week_ago - pofiles = self.pofileset.getPOFilesTouchedSince(yesterday) - self.assertContentEqual([pofile1, pofile2], pofiles) - - def test_POFileSet_getPOFilesTouchedSince_smaller_ids(self): - # Make sure that all relevant POFiles are returned, - # even the sharing ones with smaller IDs. - # This is a test for bug #414832 which caused sharing POFiles - # of the touched POFile not to be returned if they had - # IDs smaller than the touched POFile. - product = self.factory.makeProduct( - translations_usage=ServiceUsage.LAUNCHPAD - ) - series1 = self.factory.makeProductSeries(product=product, name="one") - series2 = self.factory.makeProductSeries(product=product, name="two") - potemplate1 = self.factory.makePOTemplate( - name="shared", productseries=series1 - ) - pofile1 = self.factory.makePOFile("sr", potemplate=potemplate1) - potemplate2 = self.factory.makePOTemplate( - name="shared", productseries=series2 - ) - pofile2 = potemplate2.getPOFileByLang("sr") - now = datetime.now(timezone.utc) - yesterday = now - timedelta(1) - week_ago = now - timedelta(7) - pofile1.date_changed = week_ago - - # Let's make sure the condition from the bug holds, - # since pofile2 is created implicitly with the makePOTemplate call. - self.assertTrue(pofile1.id < pofile2.id) - pofiles = self.pofileset.getPOFilesTouchedSince(yesterday) - self.assertContentEqual([pofile1, pofile2], pofiles) - - def test_POFileSet_getPOFilesTouchedSince_shared_in_distribution(self): - # Make sure actual touched POFiles and POFiles that are sharing - # with them in the same distribution/sourcepackage are all returned - # by getPOFilesTouchedSince. - - # We create a distribution with two series with the same - # sourcepackage in both, and attach a POTemplate and Serbian - # POFile to each, making sure they share translations - # (potemplates have the same name). - distro = self.factory.makeDistribution() - distro.translations_usage = ServiceUsage.LAUNCHPAD - series1 = self.factory.makeDistroSeries( - distribution=distro, name="one" - ) - sourcepackagename = self.factory.makeSourcePackageName() - potemplate1 = self.factory.makePOTemplate( - name="shared", - distroseries=series1, - sourcepackagename=sourcepackagename, - ) - pofile1 = self.factory.makePOFile("sr", potemplate=potemplate1) - - series2 = self.factory.makeDistroSeries( - distribution=distro, name="two" - ) - potemplate2 = self.factory.makePOTemplate( - name="shared", - distroseries=series2, - sourcepackagename=sourcepackagename, - ) - pofile2 = potemplate2.getPOFileByLang("sr") - - # Now the test actually starts. - now = datetime.now(timezone.utc) - yesterday = now - timedelta(1) - pofiles = self.pofileset.getPOFilesTouchedSince(yesterday) - self.assertContentEqual([pofile1, pofile2], pofiles) - - # Even if one of the sharing POFiles is older, it's still returned. - week_ago = now - timedelta(7) - pofile2.date_changed = week_ago - pofiles = self.pofileset.getPOFilesTouchedSince(yesterday) - self.assertContentEqual([pofile1, pofile2], pofiles) - - # A POFile in a different language is not returned. - pofile3 = self.factory.makePOFile("de", potemplate=potemplate2) - pofile3.date_changed = week_ago - pofiles = self.pofileset.getPOFilesTouchedSince(yesterday) - self.assertContentEqual([pofile1, pofile2], pofiles) - - def test_POFileSet_getPOFilesTouchedSince_external_pofiles(self): - # Make sure POFiles which are in different products - # are not returned even though they have the same potemplate name. - series1 = self.factory.makeProductSeries(name="one") - series1.product.translations_usage = ServiceUsage.LAUNCHPAD - series2 = self.factory.makeProductSeries(name="two") - series1.product.translations_usage = ServiceUsage.LAUNCHPAD - self.assertNotEqual(series1.product, series2.product) - - potemplate1 = self.factory.makePOTemplate( - name="shared", productseries=series1 - ) - pofile1 = self.factory.makePOFile("sr", potemplate=potemplate1) - - potemplate2 = self.factory.makePOTemplate( - name="shared", productseries=series2 - ) - pofile2 = self.factory.makePOFile("sr", potemplate=potemplate2) - - # Now the test actually starts. - now = datetime.now(timezone.utc) - yesterday = now - timedelta(1) - week_ago = now - timedelta(7) - - # Second POFile has been modified earlier than yesterday, - # and is attached to a different product, even if the template - # name is the same. It's not returned. - pofile2.date_changed = week_ago - pofiles = self.pofileset.getPOFilesTouchedSince(yesterday) - self.assertContentEqual([pofile1], pofiles) - def test_getPOFilesWithTranslationCredits(self): # Initially, we only get data from the sampledata. sampledata_pofiles = list(
_______________________________________________ Mailing list: https://launchpad.net/~launchpad-reviewers Post to : launchpad-reviewers@lists.launchpad.net Unsubscribe : https://launchpad.net/~launchpad-reviewers More help : https://help.launchpad.net/ListHelp