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
|
2908.4.9
by Guilherme Salgado
Implementation of the mirror prober and a bunch other things |
7 |
|
8 |
"""Script to probe distribution mirrors and check how up-to-date they are."""
|
|
9 |
||
10 |
import _pythonpath |
|
11 |
||
3691.214.40
by Guilherme Salgado
Fix a bunch of trivial mirror prober bugs: 46662, 68395 and 107473 |
12 |
import os |
2908.4.9
by Guilherme Salgado
Implementation of the mirror prober and a bunch other things |
13 |
|
14 |
from canonical.config import config |
|
12415.1.1
by William Grant
Stop using txn.set_isolation_level in scripts... run() has an argument for that purpose. |
15 |
from canonical.database.sqlbase import ISOLATION_LEVEL_AUTOCOMMIT |
8356.1.1
by Leonard Richardson
Partial move. |
16 |
from lp.services.scripts.base import ( |
12000.2.13
by Jonathan Lange
Move a bunch of the logic out of the cronscript and into the module |
17 |
LaunchpadCronScript, |
18 |
LaunchpadScriptFailure, |
|
11882.2.2
by Jonathan Lange
Clear up a heck of a lot of imports from canonical.launchpad.interfaces. |
19 |
)
|
12000.2.13
by Jonathan Lange
Move a bunch of the logic out of the cronscript and into the module |
20 |
from lp.registry.interfaces.distributionmirror import MirrorContent |
21 |
from lp.registry.scripts.distributionmirror_prober import DistroMirrorProber |
|
22 |
||
23 |
||
24 |
class DistroMirrorProberScript(LaunchpadCronScript): |
|
4285.2.5
by Mark Shuttleworth
Test fixes for renamed series |
25 |
usage = ('%prog --content-type=(archive|cdimage) [--force] ' |
4687.1.1
by Guilherme Salgado
Implement a limit to the number of mirrors we probe. (Fix https://bugs.launchpad.net/launchpad/+bug/123954) |
26 |
'[--no-owner-notification] [--max-mirrors=N]') |
3691.348.13
by kiko
Convert a couple of cronscripts over to LaunchpadScript |
27 |
|
28 |
def add_my_options(self): |
|
29 |
self.parser.add_option('--content-type', |
|
30 |
dest='content_type', default=None, action='store', |
|
31 |
help='Probe only mirrors of the given type') |
|
32 |
self.parser.add_option('--force', |
|
33 |
dest='force', default=False, action='store_true', |
|
7222.2.4
by Curtis Hovey
Happify lint. |
34 |
help='Force the probing of mirrors that were probed recently') |
3691.214.22
by Guilherme Salgado
Add an option to the mirror-prober script to not send notification to mirror owners. |
35 |
self.parser.add_option('--no-owner-notification', |
36 |
dest='no_owner_notification', default=False, action='store_true', |
|
37 |
help='Do not send failure notification to mirror owners.') |
|
3691.214.24
by Guilherme Salgado
Implement the new +countrymirrors-archive page, together with some fixes to its underlying bits, new/improved tests and a new argument to the prober script, which causes it to not connect to anything other than localhost |
38 |
self.parser.add_option('--no-remote-hosts', |
39 |
dest='no_remote_hosts', default=False, action='store_true', |
|
40 |
help='Do not try to connect to any host other than localhost.') |
|
4687.1.1
by Guilherme Salgado
Implement a limit to the number of mirrors we probe. (Fix https://bugs.launchpad.net/launchpad/+bug/123954) |
41 |
self.parser.add_option('--max-mirrors', |
42 |
dest='max_mirrors', default=None, action='store', type="int", |
|
43 |
help='Only probe N mirrors.') |
|
3691.348.13
by kiko
Convert a couple of cronscripts over to LaunchpadScript |
44 |
|
12000.2.12
by Jonathan Lange
Try to separate out some of the script's logic. |
45 |
def main(self): |
46 |
if self.options.content_type == 'archive': |
|
47 |
content_type = MirrorContent.ARCHIVE |
|
48 |
elif self.options.content_type == 'cdimage': |
|
49 |
content_type = MirrorContent.RELEASE |
|
50 |
else: |
|
51 |
raise LaunchpadScriptFailure( |
|
52 |
'Wrong value for argument --content-type: %s' |
|
53 |
% self.options.content_type) |
|
54 |
||
55 |
if config.distributionmirrorprober.use_proxy: |
|
56 |
os.environ['http_proxy'] = config.launchpad.http_proxy |
|
57 |
self.logger.debug("Using %s as proxy." % os.environ['http_proxy']) |
|
58 |
else: |
|
59 |
self.logger.debug("Not using any proxy.") |
|
60 |
||
12000.2.19
by Jonathan Lange
Docstring, better name |
61 |
DistroMirrorProber(self.txn, self.logger).probe( |
12000.2.16
by Jonathan Lange
Correct test failure |
62 |
content_type, self.options.no_remote_hosts, self.options.force, |
63 |
self.options.max_mirrors, not self.options.no_owner_notification) |
|
12000.2.12
by Jonathan Lange
Try to separate out some of the script's logic. |
64 |
|
2908.4.9
by Guilherme Salgado
Implementation of the mirror prober and a bunch other things |
65 |
|
66 |
if __name__ == '__main__': |
|
12000.2.13
by Jonathan Lange
Move a bunch of the logic out of the cronscript and into the module |
67 |
script = DistroMirrorProberScript( |
68 |
'distributionmirror-prober', |
|
69 |
dbuser=config.distributionmirrorprober.dbuser) |
|
12415.1.1
by William Grant
Stop using txn.set_isolation_level in scripts... run() has an argument for that purpose. |
70 |
script.lock_and_run(isolation=ISOLATION_LEVEL_AUTOCOMMIT) |