← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~stevenk/launchpad/copies-use-overrides into lp:launchpad

 

Steve Kowalik has proposed merging lp:~stevenk/launchpad/copies-use-overrides into lp:launchpad.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~stevenk/launchpad/copies-use-overrides/+merge/61195

Building on the work that was landed via https://code.launchpad.net/~stevenk/launchpad/generic-overrides/+merge/60730, this branch adds support for generic overrides to the package copier.
-- 
https://code.launchpad.net/~stevenk/launchpad/copies-use-overrides/+merge/61195
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~stevenk/launchpad/copies-use-overrides into lp:launchpad.
=== modified file 'lib/lp/soyuz/adapters/overrides.py'
--- lib/lp/soyuz/adapters/overrides.py	2011-05-13 08:27:42 +0000
+++ lib/lp/soyuz/adapters/overrides.py	2011-05-17 04:13:31 +0000
@@ -19,6 +19,7 @@
     Or,
     SQL,
     )
+from zope.component import getUtility
 
 from canonical.launchpad.components.decoratedresultset import (
     DecoratedResultSet,
@@ -26,6 +27,7 @@
 from canonical.launchpad.interfaces.lpstorm import IStore
 from lp.registry.model.sourcepackagename import SourcePackageName
 from lp.services.database import bulk
+from lp.soyuz.interfaces.component import IComponentSet
 from lp.soyuz.interfaces.publishing import active_publishing_status
 from lp.soyuz.model.binarypackagename import BinaryPackageName
 from lp.soyuz.model.binarypackagerelease import BinaryPackageRelease
@@ -137,12 +139,14 @@
     
     def calculateSourceOverrides(self, archive, distroseries, pocket,
                                  sources):
-        default_component = archive.default_component or 'universe'
+        default_component = archive.default_component or getUtility(
+            IComponentSet)['universe']
         return [(source, default_component, None) for source in sources]
 
     def calculateBinaryOverrides(self, archive, distroseries, pocket,
                                  binaries):
-        default_component = archive.default_component or 'universe'
+        default_component = archive.default_component or getUtility(
+            IComponentSet)['universe']
         return [
             (binary, das, default_component, None, None)
             for binary, das in calculate_target_das(distroseries, binaries)]

=== modified file 'lib/lp/soyuz/adapters/tests/test_overrides.py'
--- lib/lp/soyuz/adapters/tests/test_overrides.py	2011-05-13 06:26:46 +0000
+++ lib/lp/soyuz/adapters/tests/test_overrides.py	2011-05-17 04:13:31 +0000
@@ -4,6 +4,7 @@
 """Test generic override policy classes."""
 
 from testtools.matchers import Equals
+from zope.component import getUtility
 
 from canonical.database.sqlbase import flush_database_caches
 from canonical.testing.layers import LaunchpadZopelessLayer
@@ -14,6 +15,7 @@
     UnknownOverridePolicy,
     )
 from lp.soyuz.enums import PackagePublishingStatus
+from lp.soyuz.interfaces.component import IComponentSet
 from lp.testing import (
     StormStatementRecorder,
     TestCaseWithFactory,
@@ -149,7 +151,8 @@
         overrides = policy.calculateSourceOverrides(
             spph.distroseries.main_archive, spph.distroseries, spph.pocket,
             (spph.sourcepackagerelease.sourcepackagename,))
-        expected = [(spph.sourcepackagerelease.sourcepackagename, 'universe',
+        universe = getUtility(IComponentSet)['universe']
+        expected = [(spph.sourcepackagerelease.sourcepackagename, universe,
             None)]
         self.assertEqual(expected, overrides)
 
@@ -163,15 +166,17 @@
         overrides = policy.calculateBinaryOverrides(
             distroseries.main_archive, distroseries, bpph.pocket,
             ((bpph.binarypackagerelease.binarypackagename, None),))
+        universe = getUtility(IComponentSet)['universe']
         expected = [(bpph.binarypackagerelease.binarypackagename,
-            bpph.distroarchseries, 'universe', None, None)]
+            bpph.distroarchseries, universe, None, None)]
         self.assertEqual(expected, overrides)
 
     def test_ubuntu_override_policy_sources(self):
         # The Ubuntu policy incorporates both the existing and the unknown
         # policy.
+        universe = getUtility(IComponentSet)['universe']
         spns = [self.factory.makeSourcePackageName()]
-        expected = [(spns[0], 'universe', None)]
+        expected = [(spns[0], universe, None)]
         distroseries = self.factory.makeDistroSeries()
         pocket = self.factory.getAnyPocket()
         for i in xrange(8):
@@ -183,7 +188,7 @@
                 spph.sourcepackagerelease.sourcepackagename, spph.component,
                 spph.section))
         spns.append(self.factory.makeSourcePackageName())
-        expected.append((spns[-1], 'universe', None))
+        expected.append((spns[-1], universe, None))
         policy = UbuntuOverridePolicy()
         overrides = policy.calculateSourceOverrides(
             distroseries.main_archive, distroseries, pocket, spns)
@@ -193,6 +198,7 @@
     def test_ubuntu_override_policy_binaries(self):
         # The Ubuntu policy incorporates both the existing and the unknown
         # policy.
+        universe = getUtility(IComponentSet)['universe']
         distroseries = self.factory.makeDistroSeries()
         pocket = self.factory.getAnyPocket()
         bpn = self.factory.makeBinaryPackageName()
@@ -214,7 +220,7 @@
             distroarchseries = self.factory.makeDistroArchSeries(
                 distroseries=distroseries)
             bpns.append((bpn, distroarchseries.architecturetag))
-            expected.append((bpn, distroarchseries, 'universe', None, None))
+            expected.append((bpn, distroarchseries, universe, None, None))
         distroseries.nominatedarchindep = distroarchseries
         policy = UbuntuOverridePolicy()
         overrides = policy.calculateBinaryOverrides(

=== modified file 'lib/lp/soyuz/interfaces/publishing.py'
--- lib/lp/soyuz/interfaces/publishing.py	2011-05-16 08:35:17 +0000
+++ lib/lp/soyuz/interfaces/publishing.py	2011-05-17 04:13:31 +0000
@@ -589,7 +589,7 @@
         `IBinaryPackagePublishingHistory`.
         """
 
-    def copyTo(distroseries, pocket, archive):
+    def copyTo(distroseries, pocket, archive, policy=None):
         """Copy this publication to another location.
 
         :return: a `ISourcePackagePublishingHistory` record representing the
@@ -867,7 +867,7 @@
 class IPublishingSet(Interface):
     """Auxiliary methods for dealing with sets of publications."""
 
-    def copyBinariesTo(binaries, distroseries, pocket, archive):
+    def copyBinariesTo(binaries, distroseries, pocket, archive, policy=None):
         """Copy multiple binaries to a given destination.
 
         Processing multiple binaries in a batch allows certain
@@ -879,6 +879,7 @@
         :param distroseries: The target distroseries.
         :param pocket: The target pocket.
         :param archive: The target archive.
+        :param policy: The Override policy to apply to the copy.
 
         :return: A result set of the created binary package
             publishing histories.

=== modified file 'lib/lp/soyuz/model/publishing.py'
--- lib/lp/soyuz/model/publishing.py	2011-05-16 08:35:17 +0000
+++ lib/lp/soyuz/model/publishing.py	2011-05-17 04:13:31 +0000
@@ -800,14 +800,24 @@
             section=new_section,
             archive=current.archive)
 
-    def copyTo(self, distroseries, pocket, archive):
+    def copyTo(self, distroseries, pocket, archive, policy=None):
         """See `ISourcePackagePublishingHistory`."""
+        component = self.component
+        section = self.section
+        if policy is not None:
+            overrides = policy.calculateSourceOverrides(
+                archive, distroseries, pocket,
+                (self.sourcepackagerelease.sourcepackagename,))
+            for spn, ov_component, ov_section in overrides:
+                component = ov_component
+                if ov_section is not None:
+                    section = ov_section
         return getUtility(IPublishingSet).newSourcePublication(
             archive,
             self.sourcepackagerelease,
             distroseries,
-            self.component,
-            self.section,
+            component,
+            section,
             pocket)
 
     def getStatusSummaryForBuilds(self):
@@ -1326,13 +1336,36 @@
 
     implements(IPublishingSet)
 
-    def copyBinariesTo(self, binaries, distroseries, pocket, archive):
+    def copyBinariesTo(self, binaries, distroseries, pocket, archive,
+                       policy=None):
         """See `IPublishingSet`."""
-        return self.publishBinaries(
-            archive, distroseries, pocket,
-            dict(
+        if policy is not None:
+            bpn_bpph = {}
+            for bpph in binaries:
+                key = '%s-%s' % (
+                    bpph.binarypackagerelease.binarypackagename.name,
+                    bpph.distroarchseries.architecturetag)
+                bpn_bpph[key] = bpph
+            with_archtags = [(
+                bpph.binarypackagerelease.binarypackagename,
+                bpph.distroarchseries.architecturetag)
+                for bpph in binaries]
+            with_overrides = {}
+            overrides = policy.calculateBinaryOverrides(
+                archive, distroseries, pocket, with_archtags)
+            for bpn, das, component, section, priority in overrides:
+                key = '%s-%s' % (bpn.name, das.architecturetag)
+                bpph = bpn_bpph[key]
+                new_section = section or bpph.section
+                new_priority = priority or bpph.priority
+                calculated = (component, new_section, new_priority)
+                with_overrides[bpph.binarypackagerelease] = calculated
+        else:
+            with_overrides = dict(
                 (bpph.binarypackagerelease, (bpph.component, bpph.section,
-                 bpph.priority)) for bpph in binaries))
+                 bpph.priority)) for bpph in binaries)
+        return self.publishBinaries(
+            archive, distroseries, pocket, with_overrides)
 
     def publishBinaries(self, archive, distroseries, pocket,
                         binaries):

=== modified file 'lib/lp/soyuz/scripts/packagecopier.py'
--- lib/lp/soyuz/scripts/packagecopier.py	2011-05-13 00:47:34 +0000
+++ lib/lp/soyuz/scripts/packagecopier.py	2011-05-17 04:13:31 +0000
@@ -603,16 +603,21 @@
         `BinaryPackagePublishingHistory` corresponding to the copied
         publications.
     """
+    # Round and round we go -- circular imports.
+    from lp.soyuz.adapters.overrides import UbuntuOverridePolicy
     copies = []
 
     # Copy source if it's not yet copied.
+    policy = None
+    if archive.purpose == ArchivePurpose.PRIMARY:
+        policy = UbuntuOverridePolicy()
     source_in_destination = archive.getPublishedSources(
         name=source.sourcepackagerelease.name, exact_match=True,
         version=source.sourcepackagerelease.version,
         status=active_publishing_status,
         distroseries=series, pocket=pocket)
     if source_in_destination.is_empty():
-        source_copy = source.copyTo(series, pocket, archive)
+        source_copy = source.copyTo(series, pocket, archive, policy=policy)
         close_bugs_for_sourcepublication(source_copy)
         copies.append(source_copy)
     else:
@@ -628,7 +633,7 @@
     # irrelevant arch-indep publications) and IBPPH.copy is prepared
     # to expand arch-indep publications.
     binary_copies = getUtility(IPublishingSet).copyBinariesTo(
-        source.getBuiltBinaries(), series, pocket, archive)
+        source.getBuiltBinaries(), series, pocket, archive, policy=policy)
 
     copies.extend(binary_copies)
 

=== modified file 'lib/lp/soyuz/scripts/tests/test_copypackage.py'
--- lib/lp/soyuz/scripts/tests/test_copypackage.py	2011-05-09 18:53:00 +0000
+++ lib/lp/soyuz/scripts/tests/test_copypackage.py	2011-05-17 04:13:31 +0000
@@ -1150,11 +1150,12 @@
             [copy.displayname for copy in copies])
 
     def doCopy(self, source, archive, series, pocket, include_binaries):
-        return _do_direct_copy(source, archive, series, pocket, True)
+        return _do_direct_copy(source, archive, series, pocket,
+            include_binaries)
 
     def testCanCopyArchIndependentBinariesBuiltInAnUnsupportedArch(self):
         # _do_direct_copy() uses the binary candidate build architecture,
-        # instead of the publish one, in other to check if it's
+        # instead of the published one, in order to check if it's
         # suitable for the destination. It avoids skipping the single
         # arch-indep publication returned by SPPH.getBuiltBinaries()
         # if it happens to be published in an unsupportted architecture
@@ -1244,6 +1245,83 @@
         # The copy succeeds, and no i386 publication is created.
         self.assertCopied(copies, nobby, ('hppa',))
 
+    def test_new_publication_overrides(self):
+        # When we copy publications, if the destination primary archive has
+        # no prior publications of the source/binaries, we set the component
+        # to the default.
+        archive = self.factory.makeArchive(
+            distribution=self.test_publisher.ubuntutest, virtualized=False)
+        source = self.test_publisher.getPubSource(
+            archive=archive, architecturehintlist='all')
+        source.component = getUtility(IComponentSet)['multiverse']
+        [bin_i386, bin_hppa] = self.test_publisher.getPubBinaries(
+            pub_source=source)
+
+        nobby = self.createNobby(('i386', 'hppa'))
+        target_archive = self.factory.makeArchive(
+            distribution=self.test_publisher.ubuntutest, virtualized=False,
+            purpose=ArchivePurpose.PRIMARY)
+        # The package copier will want the changes files associated with the
+        # upload.
+        transaction.commit()
+
+        [copied_source, copied_bin_i386, copied_bin_hppa] = self.doCopy(
+            source, target_archive, nobby, source.pocket, True)
+        universe = getUtility(IComponentSet)['universe']
+        self.assertEquals(universe, copied_source.component)
+
+    def test_existing_publication_overrides(self):
+        # When source/binaries are copied to a destination primary archive,
+        # if that archive has existing publications, we respect their
+        # component and section when copying.
+        nobby = self.createNobby(('i386', 'hppa'))
+        archive = self.factory.makeArchive(
+            distribution=self.test_publisher.ubuntutest, virtualized=False)
+        target_archive = self.factory.makeArchive(
+            distribution=self.test_publisher.ubuntutest, virtualized=False,
+            purpose=ArchivePurpose.PRIMARY)
+        existing_source = self.test_publisher.getPubSource(
+            archive=target_archive, version='1.0-1', distroseries=nobby,
+            architecturehintlist='all')
+        multiverse = getUtility(IComponentSet)['multiverse']
+        existing_source.component = multiverse
+        [ebin_i386, ebin_hppa] = self.test_publisher.getPubBinaries(
+            pub_source=existing_source)
+        section = self.factory.makeSection()
+        ebin_i386.section = section
+        ebin_hppa.section = section
+
+        source = self.test_publisher.getPubSource(
+            archive=archive, version='1.0-2', architecturehintlist='all')
+        [bin_i386, bin_hppa] = self.test_publisher.getPubBinaries(
+            pub_source=source)
+        # The package copier will want the changes files associated with the
+        # upload.
+        transaction.commit()
+
+        [copied_source, copied_bin_i386, copied_bin_hppa] = self.doCopy(
+            source, target_archive, nobby, source.pocket, True)
+        self.assertEquals(multiverse, copied_source.component)
+        self.assertEquals(section, copied_bin_i386.section)
+        self.assertEquals(section, copied_bin_hppa.section)
+
+    def test_existing_publication_no_overrides(self):
+        # When we copy source/binaries into a PPA, we don't respect their
+        # component and section.
+        archive = self.factory.makeArchive(
+            distribution=self.test_publisher.ubuntutest, virtualized=False)
+        source = self.test_publisher.getPubSource(
+            archive=archive, version='1.0-2', architecturehintlist='all')
+        [bin_i386, bin_hppa] = self.test_publisher.getPubBinaries(
+            pub_source=source)
+        target_archive = self.factory.makeArchive(
+            distribution=self.test_publisher.ubuntutest, virtualized=True)
+        nobby = self.createNobby(('i386', 'hppa'))
+        copies = self.doCopy(
+            source, target_archive, nobby, source.pocket, True)
+        main = getUtility(IComponentSet)['main']
+        self.assertEquals(main, copies[0].component)
+
 
 class TestDoDelayedCopy(TestCaseWithFactory, BaseDoCopyTests):
 


Follow ups