228
228
(archive.purpose, getPubConfig(archive))
229
229
for archive in self.archives)
231
def locateIndexesMarker(self, distroseries):
231
def locateIndexesMarker(self, suite):
232
232
"""Give path for marker file whose presence marks index creation.
234
The file will be created once the archive indexes for
235
`distroseries` have been created. This is how future runs will
236
know that this work is done.
234
The file will be created once the archive indexes for `suite`
235
have been created. This is how future runs will know that this
238
238
archive_root = self.configs[ArchivePurpose.PRIMARY].archiveroot
240
archive_root, ".created-indexes-for-%s" % distroseries.name)
239
return os.path.join(archive_root, ".created-indexes-for-%s" % suite)
242
def needsIndexesCreated(self, distroseries):
243
"""Does `distroseries` still need its archive indexes created?
241
def listSuitesNeedingIndexes(self, distroseries):
242
"""Find suites in `distroseries` that need indexes created.
245
244
Checks for the marker left by `markIndexCreationComplete`.
249
248
# is in any other state yet has not been marked as having
250
249
# its indexes created, that's because it predates automatic
251
250
# index creation.
253
252
distro = distroseries.distribution
254
253
publisher_config_set = getUtility(IPublisherConfigSet)
255
254
if publisher_config_set.getByDistribution(distro) is None:
256
255
# We won't be able to do a thing without a publisher config,
257
256
# but that's alright: we have those for all distributions
258
257
# that we want to publish.
260
return not file_exists(self.locateIndexesMarker(distroseries))
262
def markIndexCreationComplete(self, distroseries):
263
"""Note that archive indexes for `distroseries` have been created.
265
This tells `needsIndexesCreated` that no, this series no longer needs
266
archive indexes to be set up.
260
# May need indexes for this series.
262
distroseries.getSuite(pocket)
263
for pocket in pocketsuffix.iterkeys()]
265
suite for suite in suites
266
if not file_exists(self.locateIndexesMarker(suite))]
268
def markIndexCreationComplete(self, suite):
269
"""Note that archive indexes for `suite` have been created.
271
This tells `listSuitesNeedingIndexes` that no, this suite no
272
longer needs archive indexes to be set up.
268
with file(self.locateIndexesMarker(distroseries), "w") as marker:
274
with file(self.locateIndexesMarker(suite), "w") as marker:
270
276
"Indexes for %s were created on %s.\n"
271
% (distroseries, datetime.now(utc)))
277
% (suite, datetime.now(utc)))
273
def createIndexes(self, distroseries):
279
def createIndexes(self, suite):
274
280
"""Create archive indexes for `distroseries`."""
276
"Creating archive indexes for series %s.", distroseries)
278
distroseries.getSuite(pocket)
279
for pocket in pocketsuffix.iterkeys()]
280
self.runPublishDistro(args=['-A'], suites=suites)
281
self.markIndexCreationComplete(distroseries)
281
self.logger.info("Creating archive indexes for %s.", suite)
282
self.runPublishDistro(args=['-A'], suites=[suite])
283
self.markIndexCreationComplete(suite)
283
285
def processAccepted(self):
284
286
"""Run the process-accepted script."""
556
558
self.recoverWorkingDists()
558
560
for series in self.distribution.series:
559
if self.needsIndexesCreated(series):
560
self.createIndexes(series)
561
suites_needing_indexes = self.listSuitesNeedingIndexes(series)
562
if len(suites_needing_indexes) > 0:
563
for suite in suites_needing_indexes:
564
self.createIndexes(suite)
561
565
# Don't try to do too much in one run. Leave the rest
562
566
# of the work for next time.