~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/soyuz/model/publishing.py

  • Committer: Graham Binns
  • Date: 2011-09-07 15:59:13 UTC
  • mto: This revision was merged to the branch mainline in revision 13914.
  • Revision ID: graham@canonical.com-20110907155913-p97tx2e34ysbcgp3
Added an XXX.

Show diffs side-by-side

added added

removed removed

Lines of Context:
332
332
        self.status = PackagePublishingStatus.SUPERSEDED
333
333
        self.datesuperseded = UTC_NOW
334
334
 
335
 
    def requestDeletion(self, removed_by, removal_comment=None):
336
 
        """See `IPublishing`."""
337
 
        self.status = PackagePublishingStatus.DELETED
338
 
        self.datesuperseded = UTC_NOW
339
 
        self.removed_by = removed_by
340
 
        self.removal_comment = removal_comment
341
 
        if ISourcePackagePublishingHistory.providedBy(self):
342
 
            if self.archive == self.distroseries.main_archive:
343
 
                dsd_job_source = getUtility(IDistroSeriesDifferenceJobSource)
344
 
                dsd_job_source.createForPackagePublication(
345
 
                    self.distroseries,
346
 
                    self.sourcepackagerelease.sourcepackagename, self.pocket)
 
335
    def setDeleted(self, removed_by, removal_comment=None):
 
336
        """Set to DELETED status."""
 
337
        getUtility(IPublishingSet).setMultipleDeleted(
 
338
            self.__class__, [self.id], removed_by, removal_comment)
347
339
 
348
340
    def requestObsolescence(self):
349
341
        """See `IArchivePublisher`."""
746
738
 
747
739
    def supersede(self, dominant=None, logger=None):
748
740
        """See `ISourcePackagePublishingHistory`."""
749
 
        assert self.status in [PUBLISHED, PENDING], (
 
741
        assert self.status in active_publishing_status, (
750
742
            "Should not dominate unpublished source %s" %
751
743
            self.sourcepackagerelease.title)
752
744
 
894
886
                    diff.diff_content, self.archive).http_url
895
887
        return None
896
888
 
 
889
    def requestDeletion(self, removed_by, removal_comment=None):
 
890
        """See `IPublishing`."""
 
891
        self.setDeleted(removed_by, removal_comment)
 
892
        if self.archive.is_main:
 
893
            dsd_job_source = getUtility(IDistroSeriesDifferenceJobSource)
 
894
            dsd_job_source.createForPackagePublication(
 
895
                self.distroseries,
 
896
                self.sourcepackagerelease.sourcepackagename, self.pocket)
 
897
 
897
898
    def api_requestDeletion(self, removed_by, removal_comment=None):
898
899
        """See `IPublishingEdit`."""
899
900
        # Special deletion method for the api that makes sure binaries
1117
1118
        # tolerate SUPERSEDED architecture-independent binaries, because
1118
1119
        # they are dominated automatically once the first publication is
1119
1120
        # processed.
1120
 
        if self.status not in [PUBLISHED, PENDING]:
 
1121
        if self.status not in active_publishing_status:
1121
1122
            assert not self.binarypackagerelease.architecturespecific, (
1122
1123
                "Should not dominate unpublished architecture specific "
1123
1124
                "binary %s (%s)" % (
1296
1297
        # different here (yet).
1297
1298
        self.requestDeletion(removed_by, removal_comment)
1298
1299
 
 
1300
    def requestDeletion(self, removed_by, removal_comment=None):
 
1301
        """See `IPublishing`."""
 
1302
        self.setDeleted(removed_by, removal_comment)
 
1303
 
1299
1304
 
1300
1305
def expand_binary_requests(distroseries, binaries):
1301
1306
    """Architecture-expand a dict of binary publication requests.
1761
1766
 
1762
1767
        return result_set
1763
1768
 
1764
 
    def getBinaryPublicationsForSources(
1765
 
        self, one_or_more_source_publications):
 
1769
    def getBinaryPublicationsForSources(self,
 
1770
                                        one_or_more_source_publications):
1766
1771
        """See `IPublishingSet`."""
1767
 
        # Import Buildand DistroArchSeries locally to avoid circular imports,
1768
 
        # since Build uses SourcePackagePublishingHistory and DistroArchSeries
1769
 
        # uses BinaryPackagePublishingHistory.
1770
 
        from lp.soyuz.model.distroarchseries import (
1771
 
            DistroArchSeries)
 
1772
        # Avoid circular imports.
 
1773
        from lp.soyuz.model.distroarchseries import DistroArchSeries
1772
1774
 
1773
1775
        source_publication_ids = self._extractIDs(
1774
1776
            one_or_more_source_publications)
1955
1957
        return self.getBuildStatusSummariesForSourceIdsAndArchive([source_id],
1956
1958
            source_publication.archive)[source_id]
1957
1959
 
 
1960
    def setMultipleDeleted(self, publication_class, ids, removed_by,
 
1961
                           removal_comment=None):
 
1962
        """Mark multiple publication records as deleted."""
 
1963
        ids = list(ids)
 
1964
        if len(ids) == 0:
 
1965
            return
 
1966
 
 
1967
        permitted_classes = [
 
1968
            BinaryPackagePublishingHistory,
 
1969
            SourcePackagePublishingHistory,
 
1970
            ]
 
1971
        assert publication_class in permitted_classes, "Deleting wrong type."
 
1972
 
 
1973
        affected_pubs = IMasterStore(publication_class).find(
 
1974
            publication_class, publication_class.id.is_in(ids))
 
1975
        affected_pubs.set(
 
1976
            status=PackagePublishingStatus.DELETED,
 
1977
            datesuperseded=UTC_NOW,
 
1978
            removed_byID=removed_by.id,
 
1979
            removal_comment=removal_comment)
 
1980
 
1958
1981
    def requestDeletion(self, sources, removed_by, removal_comment=None):
1959
1982
        """See `IPublishingSet`."""
1960
 
 
1961
 
        # The 'sources' parameter could actually be any kind of sequence
1962
 
        # (e.g. even a ResultSet) and the method would still work correctly.
1963
 
        # This is problematic when it comes to the type of the return value
1964
 
        # however.
1965
 
        # Apparently the caller anticipates that we return the sequence of
1966
 
        # instances "deleted" adhering to the original type of the 'sources'
1967
 
        # parameter.
1968
 
        # Since this is too messy we prescribe that the type of 'sources'
1969
 
        # must be a list and we return the instances manipulated as a list.
1970
 
        # This may not be an ideal solution but this way we at least achieve
1971
 
        # consistency.
1972
 
        assert isinstance(sources, list), (
1973
 
            "The 'sources' parameter must be a list.")
1974
 
 
 
1983
        sources = list(sources)
1975
1984
        if len(sources) == 0:
1976
 
            return []
1977
 
 
1978
 
        # The following piece of query "boiler plate" will be used for
1979
 
        # both the source and the binary package publishing history table.
1980
 
        query_boilerplate = '''
1981
 
            SET status = %s,
1982
 
                datesuperseded = %s,
1983
 
                removed_by = %s,
1984
 
                removal_comment = %s
1985
 
            WHERE id IN
1986
 
            ''' % sqlvalues(PackagePublishingStatus.DELETED, UTC_NOW,
1987
 
                            removed_by, removal_comment)
1988
 
 
1989
 
        store = getUtility(IStoreSelector).get(MAIN_STORE, DEFAULT_FLAVOR)
1990
 
 
1991
 
        # First update the source package publishing history table.
1992
 
        source_ids = [source.id for source in sources]
1993
 
        if len(source_ids) > 0:
1994
 
            query = 'UPDATE SourcePackagePublishingHistory '
1995
 
            query += query_boilerplate
1996
 
            query += ' %s' % sqlvalues(source_ids)
1997
 
            store.execute(query)
1998
 
 
1999
 
        # Prepare the list of associated *binary* packages publishing
2000
 
        # history records.
2001
 
        binary_packages = []
2002
 
        for source in sources:
2003
 
            binary_packages.extend(source.getPublishedBinaries())
2004
 
 
2005
 
        if len(binary_packages) == 0:
2006
 
            return sources
2007
 
 
2008
 
        # Now run the query that marks the binary packages as deleted
2009
 
        # as well.
2010
 
        if len(binary_packages) > 0:
2011
 
            query = 'UPDATE BinaryPackagePublishingHistory '
2012
 
            query += query_boilerplate
2013
 
            query += ' %s' % sqlvalues(
2014
 
                [binary.id for binary in binary_packages])
2015
 
            store.execute(query)
2016
 
 
2017
 
        return sources + binary_packages
 
1985
            return
 
1986
 
 
1987
        spph_ids = [spph.id for spph in sources]
 
1988
        self.setMultipleDeleted(
 
1989
            SourcePackagePublishingHistory, spph_ids, removed_by,
 
1990
            removal_comment=removal_comment)
 
1991
 
 
1992
        getUtility(IDistroSeriesDifferenceJobSource).createForSPPHs(sources)
 
1993
 
 
1994
        # Mark binary publications deleted.
 
1995
        bpph_ids = [
 
1996
            bpph.id
 
1997
            for source, bpph, bin, bin_name, arch
 
1998
                in self.getBinaryPublicationsForSources(sources)]
 
1999
        if len(bpph_ids) > 0:
 
2000
            self.setMultipleDeleted(
 
2001
                BinaryPackagePublishingHistory, bpph_ids, removed_by,
 
2002
                removal_comment=removal_comment)
2018
2003
 
2019
2004
    def getNearestAncestor(
2020
2005
        self, package_name, archive, distroseries, pocket=None,