260
262
help="Whether to treat this as a dry-run or not.")
262
264
self.parser.add_option(
263
'--derived', action="store_true", dest="derived", default=False,
264
help="Process all Ubuntu-derived distributions.")
265
'-D', '--derived', action="store_true", dest="derived",
266
default=False, help="Process all Ubuntu-derived distributions.")
266
268
self.parser.add_option(
267
269
"--ppa", action="store_true",
286
288
self.txn.commit()
288
def findTargetDistribution(self):
289
distro_name = self.args[0]
290
self.logger.debug("Finding distribution %s." % distro_name)
291
distribution = getUtility(IDistributionSet).getByName(distro_name)
292
if distribution is None:
290
def findDerivedDistros(self):
291
"""Find Ubuntu-derived distributions."""
292
# Avoid circular imports.
293
from lp.registry.model.distribution import Distribution
294
from lp.registry.model.distroseries import DistroSeries
296
ubuntu_id = getUtility(ILaunchpadCelebrities).ubuntu.id
297
return IStore(DistroSeries).find(
299
Distribution.id == DistroSeries.distributionID,
300
DistroSeries.id == DistroSeriesParent.derived_series_id,
301
DistroSeries.distributionID != ubuntu_id).config(distinct=True)
303
def findNamedDistro(self, distro_name):
304
"""Find the `Distribution` called `distro_name`."""
305
self.logger.debug("Finding distribution %s.", distro_name)
306
distro = getUtility(IDistributionSet).getByName(distro_name)
293
308
raise LaunchpadScriptFailure(
294
309
"Distribution '%s' not found." % distro_name)
312
def findTargetDistros(self):
313
"""Find the distribution(s) to process, based on arguments."""
314
if self.options.derived:
315
return self.findDerivedDistros()
317
return [self.findNamedDistro(self.args[0])]
297
319
def validateArguments(self):
298
if len(self.args) != 1:
299
raise OptionValueError(
300
"Need to be given exactly one non-option argument. "
301
"Namely the distribution to process.")
320
"""Validate command-line arguments."""
303
321
if self.options.ppa and self.options.copy_archives:
304
322
raise OptionValueError(
305
323
"Specify only one of copy archives or ppa archives.")
324
if self.options.derived:
325
if len(self.args) != 0:
326
raise OptionValueError(
327
"Can't combine --derived with a distribution name.")
329
if len(self.args) != 1:
330
raise OptionValueError(
331
"Need to be given exactly one non-option argument. "
332
"Namely the distribution to process.")
307
334
def makeTargetPolicy(self):
308
335
"""Pick and instantiate a `TargetPolicy` based on given options."""
338
365
"Successfully processed queue item %d", queue_item.id)
368
def processForDistro(self, distribution, target_policy):
369
"""Process all queue items for a distribution.
371
Commits between items, except in dry-run mode.
373
:param distribution: The `Distribution` to process queue items for.
374
:param target_policy: The applicable `TargetPolicy`.
375
:return: A list of all successfully processed items' ids.
377
processed_queue_ids = []
378
for archive in target_policy.getTargetArchives(distribution):
379
description = target_policy.describeArchive(archive)
380
for distroseries in distribution.series:
382
self.logger.debug("Processing queue for %s %s" % (
383
distroseries.name, description))
385
queue_items = distroseries.getPackageUploads(
386
status=PackageUploadStatus.ACCEPTED, archive=archive)
387
for queue_item in queue_items:
388
if self.processQueueItem(queue_item):
389
processed_queue_ids.append(queue_item.id)
390
# Commit even on error; we may have altered the
391
# on-disk archive, so the partial state must
394
return processed_queue_ids
342
397
"""Entry point for a LaunchpadScript."""
343
398
self.validateArguments()
344
399
target_policy = self.makeTargetPolicy()
345
distribution = self.findTargetDistribution()
347
processed_queue_ids = []
349
for archive in target_policy.getTargetArchives(distribution):
350
description = target_policy.describeArchive(archive)
351
for distroseries in distribution.series:
353
self.logger.debug("Processing queue for %s %s" % (
354
distroseries.name, description))
356
queue_items = distroseries.getPackageUploads(
357
status=PackageUploadStatus.ACCEPTED, archive=archive)
358
for queue_item in queue_items:
359
if self.processQueueItem(queue_item):
360
processed_queue_ids.append(queue_item.id)
361
# Commit even on error; we may have altered the
362
# on-disk archive, so the partial state must
368
target_policy.postprocessSuccesses(processed_queue_ids)
401
for distro in self.findTargetDistros():
402
queue_ids = self.processForDistro(distro, target_policy)
404
target_policy.postprocessSuccesses(queue_ids)
373
408
self.logger.debug("Rolling back any remaining transactions.")