← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~cjwatson/launchpad/phone-overlay-translations into lp:launchpad

 

Colin Watson has proposed merging lp:~cjwatson/launchpad/phone-overlay-translations into lp:launchpad.

Commit message:
Redirect translation uploads to ~ci-train-ppa-service/ubuntu/stable-phone-overlay vivid to ubuntu-rtm 15.04.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)
Related bugs:
  Bug #1463723 in Launchpad itself: "Launchpad should be able to handle translations for packages in a PPA"
  https://bugs.launchpad.net/launchpad/+bug/1463723

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/phone-overlay-translations/+merge/263819

Redirect translation uploads to ~ci-train-ppa-service/ubuntu/stable-phone-overlay vivid to ubuntu-rtm 15.04, as previously discussed and requested by the landing team.

This shouldn't be landed until the 15.04 series actually exists in ubuntu-rtm, of course, but we might as well agree on the approach and code in advance of that.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~cjwatson/launchpad/phone-overlay-translations into lp:launchpad.
=== modified file 'lib/lp/archivepublisher/rosetta_translations.py'
--- lib/lp/archivepublisher/rosetta_translations.py	2013-10-24 04:49:59 +0000
+++ lib/lp/archivepublisher/rosetta_translations.py	2015-07-04 00:45:49 +0000
@@ -1,4 +1,4 @@
-# Copyright 2009-2013 Canonical Ltd.  This software is licensed under the
+# Copyright 2009-2015 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 """The processing of Rosetta translations tarballs.
@@ -19,6 +19,7 @@
 from lp.app.interfaces.launchpad import ILaunchpadCelebrities
 from lp.archivepublisher.customupload import CustomUpload
 from lp.archivepublisher.debversion import Version
+from lp.registry.interfaces.distribution import IDistributionSet
 from lp.registry.interfaces.pocket import PackagePublishingPocket
 from lp.soyuz.interfaces.archive import MAIN_ARCHIVE_PURPOSES
 from lp.soyuz.interfaces.packagetranslationsuploadjob import (
@@ -26,6 +27,14 @@
     )
 
 
+# Translations uploaded to certain specialised PPAs are redirected to
+# specialised distroseries instead.
+REDIRECTED_PPAS = {
+    "~ci-train-ppa-service/ubuntu/stable-phone-overlay":
+        {"vivid": ("ubuntu-rtm", "15.04")},
+    }
+
+
 class RosettaTranslationsUpload(CustomUpload):
     """Rosetta Translations tarball upload.
 
@@ -45,17 +54,29 @@
         else:
             self.package_name = packageupload.package_name
 
-        # Ignore translations not with main distribution purposes.
-        if packageupload.archive.purpose not in MAIN_ARCHIVE_PURPOSES:
+        # Ignore translations not with main distribution purposes and not in
+        # redirected PPAs.
+        distroseries = None
+        if packageupload.archive.purpose in MAIN_ARCHIVE_PURPOSES:
+            distroseries = packageupload.distroseries
+        elif packageupload.archive.reference in REDIRECTED_PPAS:
+            redirect = REDIRECTED_PPAS[packageupload.archive.reference]
+            if packageupload.distroseries.name in redirect:
+                distro_name, distroseries_name = redirect[
+                    packageupload.distroseries.name]
+                distro = getUtility(IDistributionSet).getByName(distro_name)
+                distroseries = distro[distroseries_name]
+
+        if distroseries is None:
             if self.logger is not None:
                 self.logger.debug(
                     "Skipping translations since its purpose is not "
-                    "in MAIN_ARCHIVE_PURPOSES.")
+                    "in MAIN_ARCHIVE_PURPOSES and the archive is not "
+                    "whitelisted.")
             return
 
         # If the distroseries is 11.10 (oneiric) or later, the valid names
         # check is not required.  (See bug 788685.)
-        distroseries = packageupload.distroseries
         do_names_check = Version(distroseries.version) < Version('11.10')
 
         latest_publication = self._findSourcePublication(packageupload)

=== modified file 'lib/lp/archivepublisher/tests/test_rosetta_translations.py'
--- lib/lp/archivepublisher/tests/test_rosetta_translations.py	2014-07-08 09:53:50 +0000
+++ lib/lp/archivepublisher/tests/test_rosetta_translations.py	2015-07-04 00:45:49 +0000
@@ -1,4 +1,4 @@
-# Copyright 2013 Canonical Ltd.  This software is licensed under the
+# Copyright 2013-2015 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 """Test rosetta-translations custom uploads.
@@ -7,15 +7,19 @@
 high-level tests of rosetta-translations upload and queue manipulation.
 """
 
+from storm.expr import Desc
 import transaction
+from zope.component import getUtility
 from zope.security.proxy import removeSecurityProxy
-from zope.component import getUtility
 
+from lp.app.errors import NotFoundError
 from lp.archivepublisher.rosetta_translations import (
     process_rosetta_translations,
     RosettaTranslationsUpload,
     )
+from lp.registry.interfaces.distribution import IDistributionSet
 from lp.registry.interfaces.pocket import PackagePublishingPocket
+from lp.services.database.interfaces import IStore
 from lp.services.tarfile_helpers import LaunchpadWriteTarFile
 from lp.soyuz.enums import (
     ArchivePurpose,
@@ -29,7 +33,11 @@
 from lp.soyuz.model.packagetranslationsuploadjob import (
     PackageTranslationsUploadJob,
     )
-from lp.testing import TestCaseWithFactory, person_logged_in
+from lp.soyuz.model.queue import PackageUpload
+from lp.testing import (
+    person_logged_in,
+    TestCaseWithFactory,
+    )
 from lp.testing.layers import LaunchpadZopelessLayer
 
 
@@ -138,14 +146,43 @@
 
         job.run()
 
-        from storm.expr import Desc
-        from lp.soyuz.model.queue import PackageUpload
-        from lp.services.database.interfaces import IStore
         upload = IStore(PackageUpload).find(PackageUpload).order_by(
             Desc(PackageUpload.id)).first()
 
         return spr, upload, libraryfilealias
 
+    def ensureDistroSeries(self, distribution_name, distroseries_name):
+        distribution = getUtility(IDistributionSet).getByName(
+            distribution_name)
+        if distribution is None:
+            distribution = self.factory.makeDistribution(
+                name=distribution_name)
+        try:
+            distroseries = distribution[distroseries_name]
+        except NotFoundError:
+            distroseries = self.factory.makeDistroSeries(
+                distribution=distribution, name=distroseries_name)
+        return distroseries
+
+    def makeJobElementsForPPA(self, owner_name, distribution_name,
+                              distroseries_name, archive_name):
+        owner = self.factory.makePerson(name=owner_name)
+        distroseries = self.ensureDistroSeries(
+            distribution_name, distroseries_name)
+        archive = self.factory.makeArchive(
+            owner=owner, distribution=distroseries.distribution,
+            name=archive_name, purpose=ArchivePurpose.PPA)
+        sourcepackage_version = "3.8.2-1ubuntu1"
+        filename = "foo_%s_i386_translations.tar.gz" % sourcepackage_version
+        spph = self.makeAndPublishSourcePackage(
+            sourcepackagename="foo", distroseries=distroseries,
+            archive=archive)
+        packageupload = removeSecurityProxy(self.factory.makePackageUpload(
+            distroseries=distroseries, archive=archive))
+        packageupload.addSource(spph.sourcepackagerelease)
+        libraryfilealias = self.makeTranslationsLFA(filename=filename)
+        return spph.sourcepackagerelease, packageupload, libraryfilealias
+
     def test_parsePath(self):
         filename = "foobar_3.8.2-1ubuntu1_i386_translations.tar.gz"
         parsed_path = RosettaTranslationsUpload.parsePath(filename)
@@ -236,3 +273,40 @@
         self.assertEqual(spr.upload_distroseries, jobs[0].distroseries)
         self.assertEqual(libraryfilealias, jobs[0].libraryfilealias)
         self.assertEqual(spr.sourcepackagename, jobs[0].sourcepackagename)
+
+    def test_correct_job_is_created_from_redirected_ppa(self):
+        spr, packageupload, libraryfilealias = self.makeJobElementsForPPA(
+            owner_name="ci-train-ppa-service", distribution_name="ubuntu",
+            distroseries_name="vivid", archive_name="stable-phone-overlay")
+        self.ensureDistroSeries("ubuntu-rtm", "15.04")
+        transaction.commit()
+        process_rosetta_translations(packageupload, libraryfilealias)
+
+        jobs = list(PackageTranslationsUploadJob.iterReady())
+        self.assertEqual(1, len(jobs))
+
+        self.assertEqual("ubuntu-rtm 15.04", str(jobs[0].distroseries))
+        self.assertEqual(libraryfilealias, jobs[0].libraryfilealias)
+        self.assertEqual(spr.sourcepackagename, jobs[0].sourcepackagename)
+
+    def test_unredirected_series_in_redirected_ppa_is_skipped(self):
+        spr, packageupload, libraryfilealias = self.makeJobElementsForPPA(
+            owner_name="ci-train-ppa-service", distribution_name="ubuntu",
+            distroseries_name="wily", archive_name="stable-phone-overlay")
+        self.ensureDistroSeries("ubuntu-rtm", "15.04")
+        transaction.commit()
+        process_rosetta_translations(packageupload, libraryfilealias)
+
+        jobs = list(PackageTranslationsUploadJob.iterReady())
+        self.assertEqual(0, len(jobs))
+
+    def test_unredirected_ppa_is_skipped(self):
+        spr, packageupload, libraryfilealias = self.makeJobElementsForPPA(
+            owner_name="ci-train-ppa-service", distribution_name="ubuntu",
+            distroseries_name="vivid", archive_name="landing-001")
+        self.ensureDistroSeries("ubuntu-rtm", "15.04")
+        transaction.commit()
+        process_rosetta_translations(packageupload, libraryfilealias)
+
+        jobs = list(PackageTranslationsUploadJob.iterReady())
+        self.assertEqual(0, len(jobs))


Follow ups