332
332
self.status = PackagePublishingStatus.SUPERSEDED
333
333
self.datesuperseded = UTC_NOW
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(
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)
348
340
def requestObsolescence(self):
349
341
"""See `IArchivePublisher`."""
894
886
diff.diff_content, self.archive).http_url
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(
896
self.sourcepackagerelease.sourcepackagename, self.pocket)
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
1762
1767
return result_set
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 (
1772
# Avoid circular imports.
1773
from lp.soyuz.model.distroarchseries import DistroArchSeries
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]
1960
def setMultipleDeleted(self, publication_class, ids, removed_by,
1961
removal_comment=None):
1962
"""Mark multiple publication records as deleted."""
1967
permitted_classes = [
1968
BinaryPackagePublishingHistory,
1969
SourcePackagePublishingHistory,
1971
assert publication_class in permitted_classes, "Deleting wrong type."
1973
affected_pubs = IMasterStore(publication_class).find(
1974
publication_class, publication_class.id.is_in(ids))
1976
status=PackagePublishingStatus.DELETED,
1977
datesuperseded=UTC_NOW,
1978
removed_byID=removed_by.id,
1979
removal_comment=removal_comment)
1958
1981
def requestDeletion(self, sources, removed_by, removal_comment=None):
1959
1982
"""See `IPublishingSet`."""
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
1965
# Apparently the caller anticipates that we return the sequence of
1966
# instances "deleted" adhering to the original type of the 'sources'
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
1972
assert isinstance(sources, list), (
1973
"The 'sources' parameter must be a list.")
1983
sources = list(sources)
1975
1984
if len(sources) == 0:
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 = '''
1982
datesuperseded = %s,
1984
removal_comment = %s
1986
''' % sqlvalues(PackagePublishingStatus.DELETED, UTC_NOW,
1987
removed_by, removal_comment)
1989
store = getUtility(IStoreSelector).get(MAIN_STORE, DEFAULT_FLAVOR)
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)
1999
# Prepare the list of associated *binary* packages publishing
2001
binary_packages = []
2002
for source in sources:
2003
binary_packages.extend(source.getPublishedBinaries())
2005
if len(binary_packages) == 0:
2008
# Now run the query that marks the binary packages as deleted
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)
2017
return sources + binary_packages
1987
spph_ids = [spph.id for spph in sources]
1988
self.setMultipleDeleted(
1989
SourcePackagePublishingHistory, spph_ids, removed_by,
1990
removal_comment=removal_comment)
1992
getUtility(IDistroSeriesDifferenceJobSource).createForSPPHs(sources)
1994
# Mark binary publications deleted.
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)
2019
2004
def getNearestAncestor(
2020
2005
self, package_name, archive, distroseries, pocket=None,