~launchpad-pqm/launchpad/devel

« back to all changes in this revision

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

  • Committer: William Grant
  • Date: 2011-08-23 08:07:50 UTC
  • mto: This revision was merged to the branch mainline in revision 13784.
  • Revision ID: william.grant@canonical.com-20110823080750-k51yo7dkhqo57qil
DistroSeries.{getBinaryPackageCaches,removeOldCacheItems} are now on DistroSeriesPackageCache.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
from storm.locals import RawStr
16
16
from zope.interface import implements
17
17
 
18
 
from canonical.database.sqlbase import SQLBase
 
18
from canonical.database.sqlbase import (
 
19
    SQLBase,
 
20
    sqlvalues,
 
21
    )
 
22
from canonical.launchpad.interfaces.lpstorm import IStore
19
23
from lp.soyuz.interfaces.distroseriespackagecache import (
20
24
    IDistroSeriesPackageCache,
21
25
    )
 
26
from lp.soyuz.model.binarypackagename import BinaryPackageName
22
27
 
23
28
 
24
29
class DistroSeriesPackageCache(SQLBase):
39
44
    summaries = StringCol(notNull=False, default=None)
40
45
    descriptions = StringCol(notNull=False, default=None)
41
46
 
 
47
    @classmethod
 
48
    def find(cls, distroseries, archive=None):
 
49
        """All of the cached binary package records for this distroseries.
 
50
 
 
51
        If 'archive' is not given it will return all caches stored for the
 
52
        distroseries main archives (PRIMARY and PARTNER).
 
53
        """
 
54
        if archive is not None:
 
55
            archives = [archive.id]
 
56
        else:
 
57
            archives = distroseries.distribution.all_distro_archive_ids
 
58
 
 
59
        return IStore(cls).find(
 
60
            cls,
 
61
            cls.distroseries == distroseries,
 
62
            cls.archiveID.is_in(archives)).order_by(cls.name)
 
63
 
 
64
    @classmethod
 
65
    def removeOld(cls, distroseries, archive, log):
 
66
        """Delete any records that are no longer applicable.
 
67
 
 
68
        Consider all binarypackages marked as REMOVED.
 
69
 
 
70
        Also purges all existing cache records for disabled archives.
 
71
 
 
72
        :param archive: target `IArchive`.
 
73
        :param log: the context logger object able to print DEBUG level
 
74
            messages.
 
75
        """
 
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
 
81
            Archive.id = %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),
 
90
            distinct=True,
 
91
            clauseTables=[
 
92
                'Archive',
 
93
                'DistroArchSeries',
 
94
                'BinaryPackagePublishingHistory',
 
95
                'BinaryPackageRelease']))
 
96
 
 
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:
 
100
                log.debug(
 
101
                    "Removing binary cache for '%s' (%s)"
 
102
                    % (cache.name, cache.id))
 
103
                cache.destroySelf()
42
104