10637.3.1
by Guilherme Salgado
Use the default python version instead of a hard-coded version |
1 |
#!/usr/bin/python -S
|
8687.15.7
by Karl Fogel
Add the copyright header block to more files. |
2 |
#
|
3 |
# Copyright 2009 Canonical Ltd. This software is licensed under the
|
|
4 |
# GNU Affero General Public License version 3 (see the file LICENSE).
|
|
5 |
||
4935.3.7
by Curtis Hovey
Added bad name suppression to cronscripts. |
6 |
# pylint: disable-msg=C0103,W0403
|
3691.173.1
by Stuart Bishop
Helper to extract referenced OOPS codes from the database |
7 |
|
8 |
"""Cronscript to prune old and unreferenced OOPS reports from the archive."""
|
|
9 |
||
10 |
__metaclass__ = type |
|
11 |
||
12 |
import _pythonpath |
|
3691.173.2
by Stuart Bishop
Add tests for oops pruner |
13 |
import os |
3691.348.1
by kiko
Remove the original lockfile class and use our contributed GlobalLock everywhere to avoid stale locks making our scripts stop to run. Update a bunch of scripts to use it. Hopefully backwards-compatible enough to survive tests. |
14 |
|
3691.173.2
by Stuart Bishop
Add tests for oops pruner |
15 |
from canonical.config import config |
5842.1.1
by James Henstridge
Rename the transaction isolation level constants to match the psycopg2 |
16 |
from canonical.database.sqlbase import ISOLATION_LEVEL_AUTOCOMMIT |
8356.1.1
by Leonard Richardson
Partial move. |
17 |
from lp.services.scripts.base import ( |
4264.2.1
by James Henstridge
add a LaunchpadCronScript subclass, and make cronscripts/*.py use it |
18 |
LaunchpadCronScript, LaunchpadScriptFailure) |
3691.173.5
by Stuart Bishop
Remove empty directories |
19 |
from canonical.launchpad.scripts.oops import ( |
5842.1.1
by James Henstridge
Rename the transaction isolation level constants to match the psycopg2 |
20 |
unwanted_oops_files, prune_empty_oops_directories) |
3691.348.18
by kiko
Convert most other scripts; 6 remain, of which one looks like it's going to be a bit tricky... |
21 |
|
3691.173.1
by Stuart Bishop
Helper to extract referenced OOPS codes from the database |
22 |
|
3691.187.1
by Stuart Bishop
Oops pruner should use a lockfile |
23 |
default_lock_filename = '/var/lock/oops-prune.lock' |
24 |
||
4264.2.1
by James Henstridge
add a LaunchpadCronScript subclass, and make cronscripts/*.py use it |
25 |
class OOPSPruner(LaunchpadCronScript): |
3691.348.18
by kiko
Convert most other scripts; 6 remain, of which one looks like it's going to be a bit tricky... |
26 |
def add_my_options(self): |
27 |
self.parser.add_option( |
|
28 |
'-n', '--dry-run', default=False, action='store_true', |
|
29 |
dest="dry_run", help="Do a test run. No files are removed." |
|
30 |
)
|
|
31 |
||
32 |
def main(self): |
|
33 |
# Default to using the OOPS directory in config file.
|
|
34 |
if not self.args: |
|
6204.2.1
by Curtis Hovey
Added a test to verify the default root_path is config.error_reports.error_dir. |
35 |
self.args = [config.error_reports.error_dir] |
3691.348.18
by kiko
Convert most other scripts; 6 remain, of which one looks like it's going to be a bit tricky... |
36 |
|
37 |
oops_directories = [] |
|
38 |
for oops_dir in self.args: |
|
39 |
if not os.path.isdir(oops_dir): |
|
5899.1.14
by Curtis Hovey
Lint fixes. |
40 |
raise LaunchpadScriptFailure( |
41 |
"%s is not a directory" % oops_dir) |
|
3691.348.18
by kiko
Convert most other scripts; 6 remain, of which one looks like it's going to be a bit tricky... |
42 |
|
43 |
oops_directories.append(oops_dir) |
|
44 |
||
5842.1.1
by James Henstridge
Rename the transaction isolation level constants to match the psycopg2 |
45 |
self.txn.set_isolation_level(ISOLATION_LEVEL_AUTOCOMMIT) |
3691.187.1
by Stuart Bishop
Oops pruner should use a lockfile |
46 |
for oops_directory in oops_directories: |
5899.1.14
by Curtis Hovey
Lint fixes. |
47 |
for oops_path in unwanted_oops_files(oops_directory, |
48 |
40, self.logger): |
|
3691.348.18
by kiko
Convert most other scripts; 6 remain, of which one looks like it's going to be a bit tricky... |
49 |
self.logger.info("Removing %s", oops_path) |
50 |
if not self.options.dry_run: |
|
3691.187.1
by Stuart Bishop
Oops pruner should use a lockfile |
51 |
os.unlink(oops_path) |
52 |
||
5842.1.1
by James Henstridge
Rename the transaction isolation level constants to match the psycopg2 |
53 |
prune_empty_oops_directories(oops_directory) |
3691.187.1
by Stuart Bishop
Oops pruner should use a lockfile |
54 |
|
3691.173.1
by Stuart Bishop
Helper to extract referenced OOPS codes from the database |
55 |
|
56 |
if __name__ == '__main__': |
|
3691.348.18
by kiko
Convert most other scripts; 6 remain, of which one looks like it's going to be a bit tricky... |
57 |
script = OOPSPruner('oops-prune', dbuser='oopsprune') |
58 |
script.lock_and_run() |
|
59 |