8687.15.17
by Karl Fogel
Add the copyright header block to the rest of the files under lib/lp/. |
1 |
# Copyright 2009 Canonical Ltd. This software is licensed under the
|
2 |
# GNU Affero General Public License version 3 (see the file LICENSE).
|
|
3 |
||
8455.1.2
by Celso Providelo
Logging reorganization and code moving for process-death-row.py. |
4 |
"""Death row processor base script class
|
5 |
||
6 |
This script removes obsolete files from the selected archive(s) pool.
|
|
7 |
"""
|
|
8455.1.3
by Celso Providelo
fixing lint issues. |
8 |
# Disable warning on catching bare 'Exception', it's needed as a
|
9 |
# production artifact for continuing processing data that doesn't
|
|
10 |
# have problems.
|
|
11 |
# pylint: disable-msg=W0703
|
|
12 |
||
8455.1.2
by Celso Providelo
Logging reorganization and code moving for process-death-row.py. |
13 |
__metaclass__ = type |
14 |
||
15 |
__all__ = [ |
|
16 |
'DeathRowProcessor', |
|
17 |
]
|
|
18 |
||
19 |
||
20 |
from zope.component import getUtility |
|
21 |
||
8426.7.7
by Julian Edwards
Fix a bad import in the death row script. |
22 |
from lp.archivepublisher.deathrow import getDeathRow |
11403.1.4
by Henning Eggers
Reformatted imports using format-imports script r32. |
23 |
from lp.registry.interfaces.distribution import IDistributionSet |
9428.1.1
by Julian Edwards
process death row script is now a LaunchpadCronScript so that it writes to scriptactivity |
24 |
from lp.services.scripts.base import LaunchpadCronScript |
8455.1.2
by Celso Providelo
Logging reorganization and code moving for process-death-row.py. |
25 |
|
26 |
||
9428.1.1
by Julian Edwards
process death row script is now a LaunchpadCronScript so that it writes to scriptactivity |
27 |
class DeathRowProcessor(LaunchpadCronScript): |
8455.1.2
by Celso Providelo
Logging reorganization and code moving for process-death-row.py. |
28 |
|
29 |
def add_my_options(self): |
|
30 |
self.parser.add_option( |
|
31 |
"-n", "--dry-run", action="store_true", default=False, |
|
32 |
help="Dry run: goes through the motions but commits to nothing.") |
|
33 |
||
34 |
self.parser.add_option( |
|
35 |
"-d", "--distribution", metavar="DISTRO", default='ubuntu', |
|
36 |
help="Specified the distribution name.") |
|
37 |
||
38 |
self.parser.add_option( |
|
39 |
"-p", "--pool-root", metavar="PATH", |
|
40 |
help="Override the path to the pool folder") |
|
41 |
||
42 |
self.parser.add_option( |
|
43 |
"--ppa", action="store_true", default=False, |
|
44 |
help="Run only over PPA archives.") |
|
45 |
||
46 |
def main(self): |
|
47 |
distribution = getUtility(IDistributionSet).getByName( |
|
48 |
self.options.distribution) |
|
49 |
||
50 |
if self.options.ppa: |
|
51 |
archives = distribution.getAllPPAs() |
|
52 |
else: |
|
53 |
archives = distribution.all_distro_archives |
|
54 |
||
55 |
for archive in archives: |
|
56 |
self.logger.info("Processing %s" % archive.archive_url) |
|
57 |
self.processDeathRow(archive) |
|
58 |
||
59 |
def processDeathRow(self, archive): |
|
60 |
"""Process death-row for the given archive.
|
|
61 |
||
62 |
It handles the current DB transaction according with the results
|
|
63 |
of the operatin just executed, i.e, commits successfull runs and
|
|
64 |
aborts runs with errors. It also respects 'dry-run' command-line
|
|
65 |
option.
|
|
66 |
"""
|
|
67 |
death_row = getDeathRow( |
|
68 |
archive, self.logger, self.options.pool_root) |
|
69 |
self.logger.debug( |
|
70 |
"Unpublishing death row for %s." % archive.displayname) |
|
71 |
try: |
|
72 |
death_row.reap(self.options.dry_run) |
|
8455.1.3
by Celso Providelo
fixing lint issues. |
73 |
except Exception, e: |
8455.1.2
by Celso Providelo
Logging reorganization and code moving for process-death-row.py. |
74 |
self.logger.exception( |
75 |
"Unexpected exception while doing death-row unpublish") |
|
76 |
self.txn.abort() |
|
77 |
else: |
|
78 |
if self.options.dry_run: |
|
79 |
self.logger.info("Dry run mode; rolling back.") |
|
80 |
self.txn.abort() |
|
81 |
else: |
|
82 |
self.logger.debug("Committing") |
|
83 |
self.txn.commit() |
|
84 |