2
"""Death row kickoff script."""
2
# Copyright 2004-2008 Canonical Ltd. All rights reserved.
4
"""Death row processor script.
6
This script removes obsolete files from the selected archive(s) pool.
8
You can select a specific distribution or let it default to 'ubuntu'.
10
It operates in 2 modes:
11
* all distribution archive (PRIMARY and PARTNER) [default]
14
You can optionally specify a different 'pool-root' path which will be used
15
as the base path for removing files, instead of the real archive pool root.
16
This feature is used to inspect the removed files without actually modifying
19
There is also a 'dry-run' mode that can be used to operate on the real
20
archive tree without removing the files.
6
from optparse import OptionParser
8
25
from zope.component import getUtility
27
from canonical.archivepublisher.deathrow import getDeathRow
28
from canonical.config import config
10
29
from canonical.launchpad.interfaces import IDistributionSet
11
from canonical.config import config
12
from canonical.launchpad.scripts import (
13
execute_zcml_for_scripts, logger, logger_options)
14
from canonical.lp import initZopeless
16
from canonical.archivepublisher.deathrow import getDeathRow
20
parser = OptionParser()
21
parser.add_option("-n", "--dry-run", action="store_true",
22
dest="dry_run", metavar="", default=False,
23
help=("Dry run: goes through the motions but "
24
"commits to nothing."))
25
parser.add_option("-d", "--distribution",
26
dest="distribution", metavar="DISTRO",
27
help="Specified the distribution name.")
28
parser.add_option("-p", "--pool-root", metavar="PATH",
29
help="Override the path to the pool folder")
30
parser.add_option("--ppa", action="store_true",
31
dest="ppa", metavar="PPA", default=False,
32
help="Run only over PPA archives.")
34
logger_options(parser)
35
(options, args) = parser.parse_args()
36
log = logger(options, "deathrow-distro")
38
log.debug("Initialising zopeless.")
40
txn = initZopeless(dbuser=config.archivepublisher.dbuser)
41
execute_zcml_for_scripts()
43
distribution = getUtility(IDistributionSet).getByName(
47
archives = distribution.all_distro_archives
49
archives = distribution.getAllPPAs()
51
for archive in archives:
52
death_row = getDeathRow(archive, log, options.pool_root)
30
from canonical.launchpad.scripts.base import LaunchpadScript
33
class DeathRowProcessor(LaunchpadScript):
35
def add_my_options(self):
36
self.parser.add_option(
37
"-n", "--dry-run", action="store_true", default=False,
38
help="Dry run: goes through the motions but commits to nothing.")
40
self.parser.add_option(
41
"-d", "--distribution", metavar="DISTRO", default='ubuntu',
42
help="Specified the distribution name.")
44
self.parser.add_option(
45
"-p", "--pool-root", metavar="PATH",
46
help="Override the path to the pool folder")
48
self.parser.add_option(
49
"--ppa", action="store_true", default=False,
50
help="Run only over PPA archives.")
53
distribution = getUtility(IDistributionSet).getByName(
54
self.options.distribution)
57
archives = distribution.getAllPPAs()
59
archives = distribution.all_distro_archives
61
for archive in archives:
62
self.processDeathRow(archive)
64
def processDeathRow(self, archive):
65
"""Process death-row for the given archive.
67
It handles the current DB transaction according with the results
68
of the operatin just executed, i.e, commits successfull runs and
69
aborts runs with errors. It also respects 'dry-run' command-line
72
death_row = getDeathRow(
73
archive, self.logger, self.options.pool_root)
75
"Unpublishing death row for %s." % archive.title)
55
log.debug("Unpublishing death row for %s." % archive.title)
56
death_row.reap(options.dry_run)
59
log.debug("Dry run mode; rolling back.")
77
death_row.reap(self.options.dry_run)
79
self.logger.exception(
80
"Unexpected exception while doing death-row unpublish")
83
if self.options.dry_run:
84
self.logger.debug("Dry run mode; rolling back.")
62
log.debug("Committing")
65
log.exception("Unexpected exception while doing death-row "
68
# Continue with other archives.
87
self.logger.debug("Committing")
71
91
if __name__ == "__main__":
92
script = DeathRowProcessor(
93
'process-death-row', dbuser=config.archivepublisher.dbuser)