← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~stevenk/launchpad/delete-ddebs into lp:launchpad

 

Steve Kowalik has proposed merging lp:~stevenk/launchpad/delete-ddebs into lp:launchpad.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)
Related bugs:
  Bug #604429 in Launchpad itself: "Deletion of a DEB must delete the corresponding DDEB too"
  https://bugs.launchpad.net/launchpad/+bug/604429

For more details, see:
https://code.launchpad.net/~stevenk/launchpad/delete-ddebs/+merge/162265

Deleting binary publications will now also find any related debug publications that exactly match them and also delete them.
-- 
https://code.launchpad.net/~stevenk/launchpad/delete-ddebs/+merge/162265
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~stevenk/launchpad/delete-ddebs into lp:launchpad.
=== modified file 'lib/lp/services/database/stormexpr.py'
--- lib/lp/services/database/stormexpr.py	2013-05-01 17:12:51 +0000
+++ lib/lp/services/database/stormexpr.py	2013-05-02 22:37:32 +0000
@@ -15,6 +15,7 @@
     'fti_search',
     'Greatest',
     'get_where_for_reference',
+    'IsDistinctFrom',
     'NullCount',
     'rank_by_fti',
     'TryAdvisoryLock',
@@ -205,6 +206,12 @@
     oper = "&&"
 
 
+class IsDistinctFrom(CompoundOper):
+    """True iff the left side is distinct from the right side."""
+    __slots__ = ()
+    oper = " IS DISTINCT FROM "
+
+
 def get_where_for_reference(reference, other):
     """Generate a column comparison expression for a reference property.
 

=== modified file 'lib/lp/soyuz/model/publishing.py'
--- lib/lp/soyuz/model/publishing.py	2013-05-01 04:08:37 +0000
+++ lib/lp/soyuz/model/publishing.py	2013-05-02 22:37:32 +0000
@@ -17,7 +17,10 @@
 
 from collections import defaultdict
 from datetime import datetime
-import operator
+from operator import (
+    attrgetter,
+    itemgetter,
+    )
 import os
 import re
 import sys
@@ -31,10 +34,13 @@
 from storm.expr import (
     And,
     Desc,
+    Join,
     LeftJoin,
+    Not,
     Or,
     Sum,
     )
+from storm.info import ClassAlias
 from storm.store import Store
 from storm.zope import IResultSet
 from storm.zope.interfaces import ISQLObjectResultSet
@@ -61,6 +67,7 @@
     IStore,
     )
 from lp.services.database.sqlbase import SQLBase
+from lp.services.database.stormexpr import IsDistinctFrom
 from lp.services.librarian.browser import ProxiedLibraryFileAlias
 from lp.services.librarian.model import (
     LibraryFileAlias,
@@ -543,7 +550,7 @@
         publishing_set = getUtility(IPublishingSet)
         result_set = publishing_set.getUnpublishedBuildsForSources(
             self, build_states)
-        return DecoratedResultSet(result_set, operator.itemgetter(1))
+        return DecoratedResultSet(result_set, itemgetter(1))
 
     def getFileByName(self, name):
         """See `ISourcePackagePublishingHistory`."""
@@ -667,7 +674,7 @@
 
         # XXX cprov 20080710: UNIONs cannot be ordered appropriately.
         # See IPublishing.getFilesForSources().
-        return sorted(libraryfiles, key=operator.attrgetter('filename'))
+        return sorted(libraryfiles, key=attrgetter('filename'))
 
     @property
     def meta_sourcepackage(self):
@@ -2016,6 +2023,37 @@
 
         affected_pubs = IMasterStore(publication_class).find(
             publication_class, publication_class.id.is_in(ids))
+        # Find any related debug packages.
+        if publication_class == BinaryPackagePublishingHistory:
+            bpph = ClassAlias(publication_class)
+            debug_bpph = BinaryPackagePublishingHistory
+            origin = [
+                bpph,
+                Join(
+                    BinaryPackageRelease,
+                    bpph.binarypackagereleaseID == BinaryPackageRelease.id),
+                Join(
+                    debug_bpph,
+                    debug_bpph.binarypackagereleaseID ==
+                        BinaryPackageRelease.debug_packageID)]
+            debugs = IMasterStore(publication_class).using(*origin).find(
+                (debug_bpph.id,),
+                bpph.id.is_in(ids), bpph.archiveID == debug_bpph.archiveID,
+                bpph.pocket == debug_bpph.pocket,
+                bpph.componentID == debug_bpph.componentID,
+                bpph.sectionID == debug_bpph.sectionID,
+                bpph.priority == debug_bpph.priority,
+                Not(IsDistinctFrom(
+                    bpph.phased_update_percentage,
+                    debug_bpph.phased_update_percentage)))
+            debug_ids = [pub[0] for pub in debugs]
+            IMasterStore(publication_class).find(
+                BinaryPackagePublishingHistory,
+                BinaryPackagePublishingHistory.id.is_in(debug_ids)).set(
+                    status=PackagePublishingStatus.DELETED,
+                    datesuperseded=UTC_NOW,
+                    removed_byID=removed_by_id,
+                    removal_comment=removal_comment)
         affected_pubs.set(
             status=PackagePublishingStatus.DELETED,
             datesuperseded=UTC_NOW,
@@ -2098,7 +2136,7 @@
     for context, package_names in context_sourcepackagenames.items():
         clause = And(
             SourcePackagePublishingHistory.sourcepackagenameID.is_in(
-                map(operator.attrgetter('id'), package_names)),
+                map(attrgetter('id'), package_names)),
             SourcePackagePublishingHistory.archiveID.is_in(
                 archive_ids_func(context)),
             package_clause_func(context),

=== modified file 'lib/lp/soyuz/tests/test_publishing.py'
--- lib/lp/soyuz/tests/test_publishing.py	2013-05-01 18:39:38 +0000
+++ lib/lp/soyuz/tests/test_publishing.py	2013-05-02 22:37:32 +0000
@@ -37,7 +37,6 @@
     BinaryPackageFormat,
     PackageUploadStatus,
     )
-from lp.soyuz.interfaces.archive import IArchiveSet
 from lp.soyuz.interfaces.archivearch import IArchiveArchSet
 from lp.soyuz.interfaces.binarypackagename import IBinaryPackageNameSet
 from lp.soyuz.interfaces.component import IComponentSet
@@ -1223,6 +1222,38 @@
             self.assertRaisesWithContent(
                 DeletionError, message, pub.api_requestDeletion, self.person)
 
+    def test_requestDeletion_marks_debug_as_deleted(self):
+        matching_bpph = self.factory.makeBinaryPackagePublishingHistory(
+            pocket=PackagePublishingPocket.RELEASE)
+        matching_bpr = removeSecurityProxy(matching_bpph.binarypackagerelease)
+        debug_matching_bpph = self.factory.makeBinaryPackagePublishingHistory(
+            pocket=PackagePublishingPocket.RELEASE,
+            binpackageformat=BinaryPackageFormat.DDEB,
+            archive=matching_bpph.archive,
+            section_name=matching_bpph.section)
+        debug_match_bpr = debug_matching_bpph.binarypackagerelease
+        non_match_bpph = self.factory.makeBinaryPackagePublishingHistory(
+            pocket=PackagePublishingPocket.RELEASE)
+        non_match_bpr = removeSecurityProxy(
+            non_match_bpph.binarypackagerelease)
+        debug_non_match_bpph = self.factory.makeBinaryPackagePublishingHistory(
+            pocket=PackagePublishingPocket.RELEASE,
+            binpackageformat=BinaryPackageFormat.DDEB)
+        debug_non_match_bpr = debug_non_match_bpph.binarypackagerelease
+        matching_bpr.debug_package = debug_match_bpr
+        non_match_bpr.debug_package = debug_non_match_bpr
+        getUtility(IPublishingSet).requestDeletion(
+            [matching_bpph, non_match_bpph], self.person)
+        self.assertEqual(matching_bpph.status, PackagePublishingStatus.DELETED)
+        self.assertEqual(
+            debug_matching_bpph.status, PackagePublishingStatus.DELETED)
+        self.assertEqual(
+            non_match_bpph.status, PackagePublishingStatus.DELETED)
+        #for pub in (matching_bpph, debug_matching_bpph, non_match_bpph):
+        #    self.assertEqual(pub.status, PackagePublishingStatus.DELETED)
+        self.assertEqual(
+            debug_non_match_bpph.status, PackagePublishingStatus.PENDING)
+
 
 class TestSourceDomination(TestNativePublishingBase):
     """Test SourcePackagePublishingHistory.supersede() operates correctly."""

=== modified file 'lib/lp/testing/factory.py'
--- lib/lp/testing/factory.py	2013-05-02 00:40:14 +0000
+++ lib/lp/testing/factory.py	2013-05-02 22:37:32 +0000
@@ -3744,6 +3744,7 @@
                                            datecreated=None,
                                            pocket=None, archive=None,
                                            source_package_release=None,
+                                           binpackageformat=None,
                                            sourcepackagename=None):
         """Make a `BinaryPackagePublishingHistory`."""
         if distroarchseries is None:
@@ -3761,13 +3762,14 @@
                 purpose=ArchivePurpose.PRIMARY)
 
         if pocket is None:
-            pocket = self.getAnyPocket()
-
+            pocket = self.getAnyPocket() 
         if status is None:
             status = PackagePublishingStatus.PENDING
 
         if priority is None:
             priority = PackagePublishingPriority.OPTIONAL
+        if binpackageformat is None:
+            binpackageformat = BinaryPackageFormat.DEB
 
         if binarypackagerelease is None:
             # Create a new BinaryPackageBuild and BinaryPackageRelease
@@ -3779,9 +3781,8 @@
             binarypackagerelease = self.makeBinaryPackageRelease(
                 binarypackagename=binarypackagename,
                 build=binarypackagebuild,
-                component=component,
-                section_name=section_name,
-                priority=priority)
+                component=component, binpackageformat=binpackageformat,
+                section_name=section_name, priority=priority)
 
         if datecreated is None:
             datecreated = self.getUniqueDate()
@@ -3869,7 +3870,10 @@
             binpackageformat = BinaryPackageFormat.DEB
         if component is None:
             component = build.source_package_release.component
-        section = build.source_package_release.section
+        if section_name is None:
+            section = build.source_package_release.section
+        else:
+            section = section_name
         if priority is None:
             priority = PackagePublishingPriority.OPTIONAL
         if summary is None: