← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~cjwatson/launchpad/translations-copy-archive into lp:launchpad

 

Colin Watson has proposed merging lp:~cjwatson/launchpad/translations-copy-archive into lp:launchpad.

Commit message:
Add an -A/--archive option to copy-distroseries-translations.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/translations-copy-archive/+merge/265420

Add an -A/--archive option to copy-distroseries-translations.

This will let us check publications in a PPA rather than in the primary archive, which is needed by ubuntu-rtm/15.04 / ~ci-train-ppa-service/ubuntu/stable-phone-overlay.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~cjwatson/launchpad/translations-copy-archive into lp:launchpad.
=== modified file 'lib/lp/translations/scripts/copy_distroseries_translations.py'
--- lib/lp/translations/scripts/copy_distroseries_translations.py	2014-08-20 06:02:40 +0000
+++ lib/lp/translations/scripts/copy_distroseries_translations.py	2015-07-21 17:05:20 +0000
@@ -1,4 +1,4 @@
-# Copyright 2009-2012 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).
 
 """Copy `DistroSeries` translations from its parent series."""
@@ -78,7 +78,8 @@
 
 
 def copy_distroseries_translations(source, target, txn, logger,
-                                   published_sources_only=False):
+                                   published_sources_only=False,
+                                   archive=None):
     """Copy translations into a new `DistroSeries`.
 
     Wraps around `copy_active_translations`, but also ensures that the
@@ -109,9 +110,11 @@
             " translation state.")
 
         if published_sources_only:
+            if archive is None:
+                archive = target.main_archive
             spns = bulk.load(
                 SourcePackageName,
-                target.main_archive.getPublishedSources(
+                archive.getPublishedSources(
                         distroseries=target, status=active_publishing_status)
                     .config(distinct=True)
                     .order_by(

=== modified file 'lib/lp/translations/scripts/tests/test_copy_distroseries_translations.py'
--- lib/lp/translations/scripts/tests/test_copy_distroseries_translations.py	2014-08-20 06:02:40 +0000
+++ lib/lp/translations/scripts/tests/test_copy_distroseries_translations.py	2015-07-21 17:05:20 +0000
@@ -1,4 +1,4 @@
-# Copyright 2009 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).
 
 """Test distroseries translations copying."""
@@ -11,7 +11,10 @@
 from zope.component import getUtility
 
 from lp.registry.interfaces.distribution import IDistributionSet
-from lp.soyuz.enums import PackagePublishingStatus
+from lp.soyuz.enums import (
+    ArchivePurpose,
+    PackagePublishingStatus,
+    )
 from lp.testing import TestCaseWithFactory
 from lp.testing.faketransaction import FakeTransaction
 from lp.testing.layers import LaunchpadZopelessLayer
@@ -87,3 +90,45 @@
         copy_distroseries_translations(
             dapper, edgy, self.txn, logging, published_sources_only=True)
         self.assertContentEqual([spns[0], spns[2]], get_template_spns(edgy))
+
+    def test_published_packages_only_different_archive(self):
+        # If an archive parameter is passed,
+        # copy_distroseries_translations's published_sources_only flag
+        # checks source package publications in that archive rather than in
+        # the target's main archive.
+        distro = self.factory.makeDistribution(name='notbuntu')
+        dapper = self.factory.makeDistroSeries(
+            distribution=distro, name='dapper')
+        spns = [self.factory.makeSourcePackageName() for i in range(3)]
+        for spn in spns:
+            self.factory.makePOTemplate(
+                distroseries=dapper, sourcepackagename=spn)
+        ppa = self.factory.makeArchive(
+            distribution=distro, purpose=ArchivePurpose.PPA)
+
+        def get_template_spns(series):
+            return [
+                pot.sourcepackagename for pot in
+                getUtility(IPOTemplateSet).getSubset(distroseries=series)]
+
+        # Create a fresh series with two sources published in the PPA, and
+        # one in the target's main archive.
+        edgy = self.factory.makeDistroSeries(
+            distribution=distro, name='edgy')
+        self.factory.makeSourcePackagePublishingHistory(
+            archive=ppa, distroseries=edgy, sourcepackagename=spns[0],
+            status=PackagePublishingStatus.PUBLISHED)
+        self.factory.makeSourcePackagePublishingHistory(
+            archive=edgy.main_archive, distroseries=edgy,
+            sourcepackagename=spns[1],
+            status=PackagePublishingStatus.PUBLISHED)
+        self.factory.makeSourcePackagePublishingHistory(
+            archive=ppa, distroseries=edgy, sourcepackagename=spns[2],
+            status=PackagePublishingStatus.PENDING)
+
+        self.assertContentEqual(spns, get_template_spns(dapper))
+        self.assertContentEqual([], get_template_spns(edgy))
+        copy_distroseries_translations(
+            dapper, edgy, self.txn, logging, published_sources_only=True,
+            archive=ppa)
+        self.assertContentEqual([spns[0], spns[2]], get_template_spns(edgy))

=== modified file 'scripts/copy-distroseries-translations.py'
--- scripts/copy-distroseries-translations.py	2014-08-20 06:41:00 +0000
+++ scripts/copy-distroseries-translations.py	2015-07-21 17:05:20 +0000
@@ -1,6 +1,6 @@
 #!/usr/bin/python -S
 #
-# 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).
 
 """Furnish distroseries with lacking translations that its parent does have.
@@ -18,6 +18,7 @@
 
 from lp.registry.interfaces.distribution import IDistributionSet
 from lp.services.scripts.base import LaunchpadCronScript
+from lp.soyuz.interfaces.archive import IArchiveSet
 from lp.translations.scripts.copy_distroseries_translations import (
     copy_distroseries_translations,
     )
@@ -49,6 +50,11 @@
             help=(
                 "Copy only templates for sources that are published in the "
                 "target series."))
+        self.parser.add_option('-A', '--archive', dest='archive',
+            help=(
+                "With --published-sources-only, check publication in this "
+                "archive (if omitted, the target's main archive will be "
+                "checked)."))
         self.parser.add_option('-f', '--force', dest='force',
             action="store_true", default=False,
             help="Don't check if target's UI and imports are blocked; "
@@ -71,6 +77,11 @@
             self.parser.error(
                 "No source series specified and target has no previous "
                 "series.")
+        if self.options.archive is not None:
+            archive = getUtility(IArchiveSet).getByReference(
+                self.options.archive)
+        else:
+            archive = None
 
         # Both translation UI and imports for this series should be blocked
         # while the copy is in progress, to reduce the chances of deadlocks or
@@ -92,7 +103,8 @@
         # Actual work is done here.
         copy_distroseries_translations(
             source, target, self.txn, self.logger,
-            published_sources_only=self.options.published_sources_only)
+            published_sources_only=self.options.published_sources_only,
+            archive=archive)
 
         # We would like to update the DistroRelase statistics, but it takes
         # too long so this should be done after.


Follow ups