46
58
return DistributionSourcePackage(self.distribution,
47
59
self.sourcepackagename)
62
def _find(cls, distro, archive=None):
63
"""The set of all source package info caches for this distribution.
65
If 'archive' is not given it will return all caches stored for the
66
distribution main archives (PRIMARY and PARTNER).
68
if archive is not None:
69
archives = [archive.id]
71
archives = distro.all_distro_archive_ids
73
result = IStore(DistributionSourcePackageCache).find(
74
(DistributionSourcePackageCache, SourcePackageName),
75
DistributionSourcePackageCache.distribution == distro,
76
DistributionSourcePackageCache.archiveID.is_in(archives),
77
SourcePackageName.id ==
78
DistributionSourcePackageCache.sourcepackagenameID,
79
).order_by(DistributionSourcePackageCache.name)
80
return DecoratedResultSet(result, itemgetter(0))
83
def removeOld(cls, distro, archive, log):
84
"""Delete any cache records for removed packages.
86
Also purges all existing cache records for disabled archives.
88
:param archive: target `IArchive`.
89
:param log: the context logger object able to print DEBUG level
93
# Get the set of source package names to deal with.
94
spns = set(SourcePackageName.select("""
95
SourcePackagePublishingHistory.distroseries =
97
DistroSeries.distribution = %s AND
99
SourcePackagePublishingHistory.archive = Archive.id AND
100
SourcePackagePublishingHistory.sourcepackagerelease =
101
SourcePackageRelease.id AND
102
SourcePackageRelease.sourcepackagename =
103
SourcePackageName.id AND
104
SourcePackagePublishingHistory.dateremoved is NULL AND
105
Archive.enabled = TRUE
106
""" % sqlvalues(distro, archive),
111
'SourcePackagePublishingHistory',
112
'SourcePackageRelease']))
114
# Remove the cache entries for packages we no longer publish.
115
for cache in cls._find(distro, archive):
116
if cache.sourcepackagename not in spns:
118
"Removing source cache for '%s' (%s)"
119
% (cache.name, cache.id))
123
def _update(cls, distro, sourcepackagename, archive, log):
124
"""Update cached source package details.
126
Update cache details for a given ISourcePackageName, including
127
generated binarypackage names, summary and description fti.
128
'log' is required and only prints debug level information.
131
# Get the set of published sourcepackage releases.
132
sprs = list(SourcePackageRelease.select("""
133
SourcePackageRelease.sourcepackagename = %s AND
134
SourcePackageRelease.id =
135
SourcePackagePublishingHistory.sourcepackagerelease AND
136
SourcePackagePublishingHistory.distroseries =
138
DistroSeries.distribution = %s AND
139
SourcePackagePublishingHistory.archive = %s AND
140
SourcePackagePublishingHistory.dateremoved is NULL
141
""" % sqlvalues(sourcepackagename, distro, archive),
143
clauseTables=['SourcePackagePublishingHistory', 'DistroSeries'],
147
log.debug("No sources releases found.")
150
# Find or create the cache entry.
151
cache = DistributionSourcePackageCache.selectOne("""
152
distribution = %s AND
154
sourcepackagename = %s
155
""" % sqlvalues(distro, archive, sourcepackagename))
157
log.debug("Creating new source cache entry.")
158
cache = DistributionSourcePackageCache(
161
sourcepackagename=sourcepackagename)
163
# Make sure the name is correct.
164
cache.name = sourcepackagename.name
166
# Get the sets of binary package names, summaries, descriptions.
168
# XXX Julian 2007-04-03:
169
# This bit of code needs fixing up, it is doing stuff that
170
# really needs to be done in SQL, such as sorting and uniqueness.
171
# This would also improve the performance.
173
binpkgsummaries = set()
174
binpkgdescriptions = set()
177
log.debug("Considering source version %s" % spr.version)
178
# changelog may be empty, in which case we don't want to add it
179
# to the set as the join would fail below.
180
if spr.changelog_entry is not None:
181
sprchangelog.add(spr.changelog_entry)
182
binpkgs = BinaryPackageRelease.select("""
183
BinaryPackageRelease.build = BinaryPackageBuild.id AND
184
BinaryPackageBuild.source_package_release = %s
185
""" % sqlvalues(spr.id),
186
clauseTables=['BinaryPackageBuild'])
187
for binpkg in binpkgs:
188
log.debug("Considering binary '%s'" % binpkg.name)
189
binpkgnames.add(binpkg.name)
190
binpkgsummaries.add(binpkg.summary)
191
binpkgdescriptions.add(binpkg.description)
194
cache.binpkgnames = ' '.join(sorted(binpkgnames))
195
cache.binpkgsummaries = ' '.join(sorted(binpkgsummaries))
196
cache.binpkgdescriptions = ' '.join(sorted(binpkgdescriptions))
197
cache.changelog = ' '.join(sorted(sprchangelog))
200
def updateAll(cls, distro, archive, log, ztm, commit_chunk=500):
201
"""Update the source package cache.
203
Consider every non-REMOVED sourcepackage and entirely skips updates
204
for disabled archives.
206
:param archive: target `IArchive`;
207
:param log: logger object for printing debug level information;
208
:param ztm: transaction used for partial commits, every chunk of
209
'commit_chunk' updates is committed;
210
:param commit_chunk: number of updates before commit, defaults to 500.
212
:return the number packages updated done
214
# Do not create cache entries for disabled archives.
215
if not archive.enabled:
218
# Get the set of source package names to deal with.
219
spns = list(SourcePackageName.select("""
220
SourcePackagePublishingHistory.distroseries =
222
DistroSeries.distribution = %s AND
223
SourcePackagePublishingHistory.archive = %s AND
224
SourcePackagePublishingHistory.sourcepackagerelease =
225
SourcePackageRelease.id AND
226
SourcePackageRelease.sourcepackagename =
227
SourcePackageName.id AND
228
SourcePackagePublishingHistory.dateremoved is NULL
229
""" % sqlvalues(distro, archive),
232
clauseTables=['SourcePackagePublishingHistory', 'DistroSeries',
233
'SourcePackageRelease']))
235
number_of_updates = 0
238
log.debug("Considering source '%s'" % spn.name)
239
cls._update(distro, spn, archive, log)
241
number_of_updates += 1
242
if chunk_size == commit_chunk:
244
log.debug("Committing")
247
return number_of_updates