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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
import os
from sedot import SEDOT_BASE
from status import PackageStatus, NoStatusError
__all__ = ['Package', 'NoPackageError']
class NoPackageError(Exception):
def __init__(self, value):
self.value = value
def __str__(self):
print repr(self.value)
class MirrorSize:
def __init__(self, package):
self.package = package
self._load()
self.size = None
self.time = None
self._load()
def _load(self):
global SEDOT_BASE
dir = os.path.join(SEDOT_BASE, "log", "mirror-size")
logname = os.path.join(dir, "%s.log" % self.package)
if not os.path.isfile(logname):
return
lines = open(logname).readlines()[-1]
try:
(time, size) = lines.split(" ")
self.time = int(time)
self.size = float(size)
except ValueError:
self.time = None
self.size = None
def __str__(self):
return str(self.size)
class Package:
def __init__(self, package):
self.package = package
self.status = None
self._load()
def _load(self):
global SEDOT_BASE
self.dir = os.path.join(SEDOT_BASE, "pkgs", self.package)
if not os.path.isdir(self.dir):
raise NoPackageError(self.package)
self.source = self._read("source")
self.target = self._read("target")
self.method = self._read("method")
self.name = self._read("name")
self.cron = self._read("cron")
self.color = self._read_color("color")
self.urls = self._read_urls("url")
self.size = MirrorSize(self.package)
def _read(self, file):
fname = os.path.join(self.dir, file)
if os.path.isfile(fname):
f = open(fname)
for line in f.readlines():
line = line.strip()
if len(line) > 0 and line[0] != '#':
return line
return None
def _read_color(self, file):
fname = os.path.join(self.dir, file)
if os.path.isfile(fname):
f = open(fname)
for line in f.readlines():
line = line.strip()
if line[0] != '':
return line
return "#FF0000"
def _read_urls(self, file):
fname = os.path.join(self.dir, file)
res = {
'http': None,
'ftp': None,
'rsync': None
}
if os.path.isfile(fname):
f = open(fname)
for line in f.readlines():
line = line.strip()
if line[0:7] == 'http://' and res['http'] == None:
res['http'] = line
elif line[0:6] == 'ftp://' and res['ftp'] == None:
res['ftp'] = line
elif line[0:8] == 'rsync://' and res['rsync'] == None:
res['rsync'] = line
return res
def load_status(self):
try:
self.status = PackageStatus(self.package)
except NoStatusError:
self.status = None
|