3944.1.1
by Francis J. Lacoste
Use system version python2.4 for scripts. |
1 |
#!/usr/bin/python2.4
|
5703.1.5
by Celso Providelo
process-death-row to using LaunchpadScript. |
2 |
# Copyright 2004-2008 Canonical Ltd. All rights reserved.
|
3 |
||
5703.1.6
by Celso Providelo
applying review comments, r=mwh. |
4 |
# Stop lint warning about relative import:
|
5 |
# pylint: disable-msg=W0403
|
|
6 |
||
7 |
||
5703.1.5
by Celso Providelo
process-death-row to using LaunchpadScript. |
8 |
"""Death row processor script.
|
9 |
||
10 |
This script removes obsolete files from the selected archive(s) pool.
|
|
11 |
||
12 |
You can select a specific distribution or let it default to 'ubuntu'.
|
|
13 |
||
14 |
It operates in 2 modes:
|
|
15 |
* all distribution archive (PRIMARY and PARTNER) [default]
|
|
16 |
* all PPAs [--ppa]
|
|
17 |
||
18 |
You can optionally specify a different 'pool-root' path which will be used
|
|
19 |
as the base path for removing files, instead of the real archive pool root.
|
|
20 |
This feature is used to inspect the removed files without actually modifying
|
|
21 |
the archive tree.
|
|
22 |
||
23 |
There is also a 'dry-run' mode that can be used to operate on the real
|
|
24 |
archive tree without removing the files.
|
|
25 |
"""
|
|
3691.93.1
by Christian Reis
Factor the death row processing into a separate script. Implement the DeathRow processor, with size calculation, some optimizations and properly restricting it to a specific distribution, and a process-death-row script, which has a dry run mode. Do minor cleanups in DAR.publish(), implementing a DR.isUnstable() method. Test DeathRow. Change DiskPool file removal code to return the filesize of the file removed. Implement Source/BinaryPackageFilePublishing.displayname, with tests. Clean up publish-distro as much as I can.. |
26 |
|
27 |
import _pythonpath |
|
28 |
||
4785.4.2
by Celso Providelo
Fix #128126 (extend process-deathrow to support PPA removals. '--ppa' mode). |
29 |
from zope.component import getUtility |
30 |
||
5703.1.5
by Celso Providelo
process-death-row to using LaunchpadScript. |
31 |
from canonical.archivepublisher.deathrow import getDeathRow |
32 |
from canonical.config import config |
|
4785.4.2
by Celso Providelo
Fix #128126 (extend process-deathrow to support PPA removals. '--ppa' mode). |
33 |
from canonical.launchpad.interfaces import IDistributionSet |
5703.1.5
by Celso Providelo
process-death-row to using LaunchpadScript. |
34 |
from canonical.launchpad.scripts.base import LaunchpadScript |
35 |
||
36 |
||
37 |
class DeathRowProcessor(LaunchpadScript): |
|
38 |
||
39 |
def add_my_options(self): |
|
40 |
self.parser.add_option( |
|
41 |
"-n", "--dry-run", action="store_true", default=False, |
|
42 |
help="Dry run: goes through the motions but commits to nothing.") |
|
43 |
||
44 |
self.parser.add_option( |
|
45 |
"-d", "--distribution", metavar="DISTRO", default='ubuntu', |
|
46 |
help="Specified the distribution name.") |
|
47 |
||
48 |
self.parser.add_option( |
|
49 |
"-p", "--pool-root", metavar="PATH", |
|
50 |
help="Override the path to the pool folder") |
|
51 |
||
52 |
self.parser.add_option( |
|
53 |
"--ppa", action="store_true", default=False, |
|
54 |
help="Run only over PPA archives.") |
|
55 |
||
56 |
def main(self): |
|
57 |
distribution = getUtility(IDistributionSet).getByName( |
|
58 |
self.options.distribution) |
|
59 |
||
60 |
if self.options.ppa: |
|
61 |
archives = distribution.getAllPPAs() |
|
62 |
else: |
|
63 |
archives = distribution.all_distro_archives |
|
64 |
||
65 |
for archive in archives: |
|
66 |
self.processDeathRow(archive) |
|
67 |
||
68 |
def processDeathRow(self, archive): |
|
69 |
"""Process death-row for the given archive.
|
|
70 |
||
71 |
It handles the current DB transaction according with the results
|
|
72 |
of the operatin just executed, i.e, commits successfull runs and
|
|
73 |
aborts runs with errors. It also respects 'dry-run' command-line
|
|
74 |
option.
|
|
75 |
"""
|
|
76 |
death_row = getDeathRow( |
|
77 |
archive, self.logger, self.options.pool_root) |
|
78 |
self.logger.debug( |
|
79 |
"Unpublishing death row for %s." % archive.title) |
|
4376.2.26
by Julian Edwards
Make deathrow processing archive-aware. It will now loop through |
80 |
try: |
5703.1.5
by Celso Providelo
process-death-row to using LaunchpadScript. |
81 |
death_row.reap(self.options.dry_run) |
82 |
except: |
|
83 |
self.logger.exception( |
|
84 |
"Unexpected exception while doing death-row unpublish") |
|
85 |
self.txn.abort() |
|
86 |
else: |
|
87 |
if self.options.dry_run: |
|
88 |
self.logger.debug("Dry run mode; rolling back.") |
|
89 |
self.txn.abort() |
|
4376.2.26
by Julian Edwards
Make deathrow processing archive-aware. It will now loop through |
90 |
else: |
5703.1.5
by Celso Providelo
process-death-row to using LaunchpadScript. |
91 |
self.logger.debug("Committing") |
92 |
self.txn.commit() |
|
3691.93.1
by Christian Reis
Factor the death row processing into a separate script. Implement the DeathRow processor, with size calculation, some optimizations and properly restricting it to a specific distribution, and a process-death-row script, which has a dry run mode. Do minor cleanups in DAR.publish(), implementing a DR.isUnstable() method. Test DeathRow. Change DiskPool file removal code to return the filesize of the file removed. Implement Source/BinaryPackageFilePublishing.displayname, with tests. Clean up publish-distro as much as I can.. |
93 |
|
3691.93.15
by Christian Reis
Fix for bug #54345: archivepublisher module imports monolithically |
94 |
|
3691.93.1
by Christian Reis
Factor the death row processing into a separate script. Implement the DeathRow processor, with size calculation, some optimizations and properly restricting it to a specific distribution, and a process-death-row script, which has a dry run mode. Do minor cleanups in DAR.publish(), implementing a DR.isUnstable() method. Test DeathRow. Change DiskPool file removal code to return the filesize of the file removed. Implement Source/BinaryPackageFilePublishing.displayname, with tests. Clean up publish-distro as much as I can.. |
95 |
if __name__ == "__main__": |
5703.1.5
by Celso Providelo
process-death-row to using LaunchpadScript. |
96 |
script = DeathRowProcessor( |
97 |
'process-death-row', dbuser=config.archivepublisher.dbuser) |
|
98 |
script.lock_and_run() |
|
99 |