-
Notifications
You must be signed in to change notification settings - Fork 5
/
get-mirrors.py
executable file
·58 lines (45 loc) · 1.1 KB
/
get-mirrors.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
#!/usr/bin/python
#
# This is a Python script to parse state.txt file.
#
# The first argument should be the path to the mirmon state (e.g.
# state.txt).
import sys
import string
import os
import re
import socket
import time
verbose = False
timeout = 10
error = __name__ + '.error'
class MirrorError (Exception):
def __init__(self, value):
self.value = value
def __str__(self):
return `self.value`
try:
sys.argv[1]
except IndexError:
print "Usage: " + sys.argv[0] + " <mirror-database>"
sys.exit(0)
if verbose:
print "Opening state database " + sys.argv[1] + "..."
f = open(sys.argv[1])
lines = f.readlines()
for line in lines:
line = string.strip(line)
splitline = string.split(line)
if splitline[2]=='ok':
url = splitline[0]
#age = time.ctime(int(splitline[1]))
age = int(splitline[1])
p = re.compile(r'^(f|ht)tp://(?P<hn>[^/]*)/?.*$')
m = p.search(splitline[0])
mname = m.group('hn')
if time.time()-age<=18*60*60:
if verbose:
print "Allowing mirror " + mname + " [" + time.ctime(age) + "]"
else:
print url
sys.exit()