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 |
#
|
14027.3.2
by Jeroen Vermeulen
Merge devel, resolve conflicts. |
3 |
# Copyright 2009-2011 Canonical Ltd. This software is licensed under the
|
8687.15.7
by Karl Fogel
Add the copyright header block to more files. |
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 |
||
14612.2.8
by William Grant
cronscripts |
10 |
import _pythonpath |
11 |
||
14027.3.2
by Jeroen Vermeulen
Merge devel, resolve conflicts. |
12 |
import os |
13 |
||
14 |
from lp.registry.interfaces.distributionmirror import MirrorContent |
|
15 |
from lp.registry.scripts.distributionmirror_prober import DistroMirrorProber |
|
14612.2.8
by William Grant
cronscripts |
16 |
from lp.services.config import config |
8356.1.1
by Leonard Richardson
Partial move. |
17 |
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 |
18 |
LaunchpadCronScript, |
19 |
LaunchpadScriptFailure, |
|
11882.2.2
by Jonathan Lange
Clear up a heck of a lot of imports from canonical.launchpad.interfaces. |
20 |
)
|
12000.2.13
by Jonathan Lange
Move a bunch of the logic out of the cronscript and into the module |
21 |
|
22 |
||
23 |
class DistroMirrorProberScript(LaunchpadCronScript): |
|
4285.2.5
by Mark Shuttleworth
Test fixes for renamed series |
24 |
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) |
25 |
'[--no-owner-notification] [--max-mirrors=N]') |
3691.348.13
by kiko
Convert a couple of cronscripts over to LaunchpadScript |
26 |
|
27 |
def add_my_options(self): |
|
28 |
self.parser.add_option('--content-type', |
|
29 |
dest='content_type', default=None, action='store', |
|
30 |
help='Probe only mirrors of the given type') |
|
31 |
self.parser.add_option('--force', |
|
32 |
dest='force', default=False, action='store_true', |
|
7222.2.4
by Curtis Hovey
Happify lint. |
33 |
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. |
34 |
self.parser.add_option('--no-owner-notification', |
35 |
dest='no_owner_notification', default=False, action='store_true', |
|
36 |
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 |
37 |
self.parser.add_option('--no-remote-hosts', |
38 |
dest='no_remote_hosts', default=False, action='store_true', |
|
39 |
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) |
40 |
self.parser.add_option('--max-mirrors', |
41 |
dest='max_mirrors', default=None, action='store', type="int", |
|
42 |
help='Only probe N mirrors.') |
|
3691.348.13
by kiko
Convert a couple of cronscripts over to LaunchpadScript |
43 |
|
12000.2.12
by Jonathan Lange
Try to separate out some of the script's logic. |
44 |
def main(self): |
45 |
if self.options.content_type == 'archive': |
|
46 |
content_type = MirrorContent.ARCHIVE |
|
47 |
elif self.options.content_type == 'cdimage': |
|
48 |
content_type = MirrorContent.RELEASE |
|
49 |
else: |
|
50 |
raise LaunchpadScriptFailure( |
|
51 |
'Wrong value for argument --content-type: %s' |
|
52 |
% self.options.content_type) |
|
53 |
||
54 |
if config.distributionmirrorprober.use_proxy: |
|
55 |
os.environ['http_proxy'] = config.launchpad.http_proxy |
|
56 |
self.logger.debug("Using %s as proxy." % os.environ['http_proxy']) |
|
57 |
else: |
|
58 |
self.logger.debug("Not using any proxy.") |
|
59 |
||
12000.2.19
by Jonathan Lange
Docstring, better name |
60 |
DistroMirrorProber(self.txn, self.logger).probe( |
12000.2.16
by Jonathan Lange
Correct test failure |
61 |
content_type, self.options.no_remote_hosts, self.options.force, |
62 |
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. |
63 |
|
2908.4.9
by Guilherme Salgado
Implementation of the mirror prober and a bunch other things |
64 |
|
65 |
if __name__ == '__main__': |
|
12000.2.13
by Jonathan Lange
Move a bunch of the logic out of the cronscript and into the module |
66 |
script = DistroMirrorProberScript( |
67 |
'distributionmirror-prober', |
|
68 |
dbuser=config.distributionmirrorprober.dbuser) |
|
14022.3.2
by William Grant
LaunchpadScript no longer uses initZopeless. |
69 |
script.lock_and_run(isolation='autocommit') |