322
327
fields = self.buildIndexStanzaFields()
323
328
return fields.makeOutput()
325
def setSuperseded(self):
326
"""Set to SUPERSEDED status."""
331
"""See `IPublishing`."""
327
332
self.status = PackagePublishingStatus.SUPERSEDED
328
333
self.datesuperseded = UTC_NOW
330
def setDeleted(self, removed_by, removal_comment=None):
331
"""Set to DELETED status."""
332
getUtility(IPublishingSet).setMultipleDeleted(
333
self.__class__, [self.id], removed_by, removal_comment)
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
348
def requestObsolescence(self):
336
349
"""See `IArchivePublisher`."""
420
433
"""A source package release publishing record."""
421
434
implements(ISourcePackagePublishingHistory)
423
sourcepackagename = ForeignKey(
424
foreignKey='SourcePackageName', dbName='sourcepackagename')
425
sourcepackagerelease = ForeignKey(
426
foreignKey='SourcePackageRelease', dbName='sourcepackagerelease')
427
distroseries = ForeignKey(
428
foreignKey='DistroSeries', dbName='distroseries')
436
sourcepackagerelease = ForeignKey(foreignKey='SourcePackageRelease',
437
dbName='sourcepackagerelease')
438
distroseries = ForeignKey(foreignKey='DistroSeries',
439
dbName='distroseries')
429
440
component = ForeignKey(foreignKey='Component', dbName='component')
430
441
section = ForeignKey(foreignKey='Section', dbName='section')
431
442
status = EnumCol(schema=PackagePublishingStatus)
889
894
diff.diff_content, self.archive).http_url
892
def requestDeletion(self, removed_by, removal_comment=None):
893
"""See `IPublishing`."""
894
self.setDeleted(removed_by, removal_comment)
895
if self.archive.is_main:
896
dsd_job_source = getUtility(IDistroSeriesDifferenceJobSource)
897
dsd_job_source.createForPackagePublication(
899
self.sourcepackagerelease.sourcepackagename, self.pocket)
901
897
def api_requestDeletion(self, removed_by, removal_comment=None):
902
898
"""See `IPublishingEdit`."""
903
899
# Special deletion method for the api that makes sure binaries
912
908
implements(IBinaryPackagePublishingHistory)
914
binarypackagename = ForeignKey(
915
foreignKey='BinaryPackageName', dbName='binarypackagename')
916
binarypackagerelease = ForeignKey(
917
foreignKey='BinaryPackageRelease', dbName='binarypackagerelease')
918
distroarchseries = ForeignKey(
919
foreignKey='DistroArchSeries', dbName='distroarchseries')
910
binarypackagerelease = ForeignKey(foreignKey='BinaryPackageRelease',
911
dbName='binarypackagerelease')
912
distroarchseries = ForeignKey(foreignKey='DistroArchSeries',
913
dbName='distroarchseries')
920
914
component = ForeignKey(foreignKey='Component', dbName='component')
921
915
section = ForeignKey(foreignKey='Section', dbName='section')
922
916
priority = EnumCol(dbName='priority', schema=PackagePublishingPriority)
1441
1428
insert_head = """
1442
1429
INSERT INTO BinaryPackagePublishingHistory
1443
1430
(archive, distroarchseries, pocket, binarypackagerelease,
1444
binarypackagename, component, section, priority, status,
1431
component, section, priority, status, datecreated)
1448
1434
insert_pubs = ", ".join(
1449
1435
"(%s)" % ", ".join(sqlvalues(
1450
1436
get_archive(archive, bpr).id, das.id, pocket, bpr.id,
1451
bpr.binarypackagename,
1452
1437
get_component(archive, das.distroseries, component).id,
1453
1438
section.id, priority, PackagePublishingStatus.PENDING,
1491
1475
def newSourcePublication(self, archive, sourcepackagerelease,
1492
1476
distroseries, component, section, pocket,
1493
ancestor=None, create_dsd_job=True,
1477
ancestor=None, create_dsd_job=True):
1495
1478
"""See `IPublishingSet`."""
1496
1479
# Avoid circular import.
1497
1480
from lp.registry.model.distributionsourcepackage import (
1498
1481
DistributionSourcePackage)
1501
creator = sourcepackagerelease.creator
1503
1483
pub = SourcePackagePublishingHistory(
1504
1484
distroseries=distroseries,
1506
1486
archive=archive,
1507
sourcepackagename=sourcepackagerelease.sourcepackagename,
1508
1487
sourcepackagerelease=sourcepackagerelease,
1509
1488
component=get_component(archive, distroseries, component),
1510
1489
section=section,
1511
1490
status=PackagePublishingStatus.PENDING,
1512
1491
datecreated=UTC_NOW,
1515
1493
DistributionSourcePackage.ensure(pub)
1517
1495
if create_dsd_job:
1784
1762
return result_set
1786
def getBinaryPublicationsForSources(self,
1787
one_or_more_source_publications):
1764
def getBinaryPublicationsForSources(
1765
self, one_or_more_source_publications):
1788
1766
"""See `IPublishingSet`."""
1789
# Avoid circular imports.
1790
from lp.soyuz.model.distroarchseries import DistroArchSeries
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 (
1792
1773
source_publication_ids = self._extractIDs(
1793
1774
one_or_more_source_publications)
1974
1955
return self.getBuildStatusSummariesForSourceIdsAndArchive([source_id],
1975
1956
source_publication.archive)[source_id]
1977
def setMultipleDeleted(self, publication_class, ids, removed_by,
1978
removal_comment=None):
1979
"""Mark multiple publication records as deleted."""
1984
permitted_classes = [
1985
BinaryPackagePublishingHistory,
1986
SourcePackagePublishingHistory,
1988
assert publication_class in permitted_classes, "Deleting wrong type."
1990
if removed_by is None:
1991
removed_by_id = None
1993
removed_by_id = removed_by.id
1995
affected_pubs = IMasterStore(publication_class).find(
1996
publication_class, publication_class.id.is_in(ids))
1998
status=PackagePublishingStatus.DELETED,
1999
datesuperseded=UTC_NOW,
2000
removed_byID=removed_by_id,
2001
removal_comment=removal_comment)
2003
1958
def requestDeletion(self, sources, removed_by, removal_comment=None):
2004
1959
"""See `IPublishingSet`."""
2005
sources = list(sources)
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.")
2006
1975
if len(sources) == 0:
2009
spph_ids = [spph.id for spph in sources]
2010
self.setMultipleDeleted(
2011
SourcePackagePublishingHistory, spph_ids, removed_by,
2012
removal_comment=removal_comment)
2014
getUtility(IDistroSeriesDifferenceJobSource).createForSPPHs(sources)
2016
# Mark binary publications deleted.
2019
for source, bpph, bin, bin_name, arch
2020
in self.getBinaryPublicationsForSources(sources)]
2021
if len(bpph_ids) > 0:
2022
self.setMultipleDeleted(
2023
BinaryPackagePublishingHistory, bpph_ids, removed_by,
2024
removal_comment=removal_comment)
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
2026
2019
def getNearestAncestor(
2027
2020
self, package_name, archive, distroseries, pocket=None,