-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathmirrors_checker.py
executable file
·111 lines (90 loc) · 2.61 KB
/
mirrors_checker.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/usr/bin/env python
# -*- Mode: python; coding: utf-8 -*-
#
# Cherokee Web Site
#
# Authors:
# Alvaro Lopez Ortega <alvaro@alobbs.com>
#
# Copyright (C) 2001-2011 Alvaro Lopez Ortega
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of version 2 of the GNU General Public
# License as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
#
import os
import re
import sys
import time
import cPickle
import pycurl
import cStringIO
from mirrors import main_site, mirror_list
def check_mirror (mirror):
http = mirror.get('http')
mirror['status_stamp'] = time.time()
mirror['up_to_date'] = False
mirror['latest'] = None
mirror['error'] = None
# HTTP request
res = cStringIO.StringIO()
c = pycurl.Curl()
c.setopt(pycurl.URL, http)
c.setopt(pycurl.FOLLOWLOCATION, 1)
c.setopt(pycurl.MAXREDIRS, 5)
c.setopt(pycurl.CONNECTTIMEOUT, 15)
c.setopt(pycurl.TIMEOUT, 25)
c.setopt(pycurl.NOSIGNAL, 1)
c.setopt(pycurl.WRITEFUNCTION, res.write)
try:
c.perform()
except:
mirror['error'] = 'HTTP error'
return
# Check latest
try:
latest = re.findall (r'LATEST_is_([\d\.]+)', res.getvalue(), re.M)[0]
except:
mirror['error'] = 'No LASTEST_is link'
return
mirror['latest'] = latest
# Outdated
if main_site.get('latest') and \
main_site.get('latest') != latest:
return
# Report version
mirror['up_to_date'] = True
def check_mirrors():
global main_site
# Main site
check_mirror (main_site)
# Check mirrors
results = mirror_list[:]
for mirror in results:
# Current mirror
print mirror['http'],
sys.stdout.flush()
# HTTP Request
response = check_mirror (mirror)
# Report
if mirror['error']:
print mirror['error']
elif mirror['up_to_date']:
print mirror['latest'], "OK"
else:
print mirror['latest'], "Outdated"
# Save
cPickle.dump (results, open("mirrors.pickle", 'w+'))
os.system ("ls -l mirrors.pickle")
if __name__ == '__main__':
check_mirrors()