15
15
from storm.locals import RawStr
16
16
from zope.interface import implements
18
from canonical.database.sqlbase import SQLBase
18
from canonical.database.sqlbase import (
22
from canonical.launchpad.interfaces.lpstorm import IStore
19
23
from lp.soyuz.interfaces.distroseriespackagecache import (
20
24
IDistroSeriesPackageCache,
26
from lp.soyuz.model.binarypackagename import BinaryPackageName
24
29
class DistroSeriesPackageCache(SQLBase):
39
44
summaries = StringCol(notNull=False, default=None)
40
45
descriptions = StringCol(notNull=False, default=None)
48
def find(cls, distroseries, archive=None):
49
"""All of the cached binary package records for this distroseries.
51
If 'archive' is not given it will return all caches stored for the
52
distroseries main archives (PRIMARY and PARTNER).
54
if archive is not None:
55
archives = [archive.id]
57
archives = distroseries.distribution.all_distro_archive_ids
59
return IStore(cls).find(
61
cls.distroseries == distroseries,
62
cls.archiveID.is_in(archives)).order_by(cls.name)
65
def removeOld(cls, distroseries, archive, log):
66
"""Delete any records that are no longer applicable.
68
Consider all binarypackages marked as REMOVED.
70
Also purges all existing cache records for disabled archives.
72
:param archive: target `IArchive`.
73
:param log: the context logger object able to print DEBUG level
76
# get the set of package names that should be there
77
bpns = set(BinaryPackageName.select("""
78
BinaryPackagePublishingHistory.distroarchseries =
79
DistroArchSeries.id AND
80
DistroArchSeries.distroseries = %s AND
82
BinaryPackagePublishingHistory.archive = Archive.id AND
83
BinaryPackagePublishingHistory.binarypackagerelease =
84
BinaryPackageRelease.id AND
85
BinaryPackageRelease.binarypackagename =
86
BinaryPackageName.id AND
87
BinaryPackagePublishingHistory.dateremoved is NULL AND
88
Archive.enabled = TRUE
89
""" % sqlvalues(distroseries.id, archive.id),
94
'BinaryPackagePublishingHistory',
95
'BinaryPackageRelease']))
97
# remove the cache entries for binary packages we no longer want
98
for cache in cls.find(distroseries, archive):
99
if cache.binarypackagename not in bpns:
101
"Removing binary cache for '%s' (%s)"
102
% (cache.name, cache.id))