]>
Commit | Line | Data |
---|---|---|
940227cb MT |
1 | #!/usr/bin/python |
2 | ||
3 | import socket | |
4 | import tornado.web | |
5 | ||
6 | from handlers_base import * | |
7 | ||
8 | class MirrorIndexHandler(BaseHandler): | |
9 | def get(self): | |
0673d1b0 | 10 | ip_addr = self.get_argument("addr", self.request.remote_ip) |
940227cb | 11 | |
0673d1b0 MT |
12 | # Get a list of all mirrors. |
13 | all_mirrors = self.mirrors.get_all() | |
14 | ||
15 | # Choose the preferred ones by their location. | |
16 | preferred_mirrors = all_mirrors.get_for_location(ip_addr) | |
17 | ||
18 | # Remove the preferred ones from the list of the rest. | |
19 | other_mirrors = all_mirrors - preferred_mirrors | |
20 | ||
21 | self.render("mirrors.html", | |
22 | preferred_mirrors=preferred_mirrors, other_mirrors=other_mirrors) | |
940227cb MT |
23 | |
24 | ||
25 | class MirrorItemHandler(BaseHandler): | |
26 | def get(self, id): | |
27 | mirror = self.mirrors.get(id) | |
28 | if not mirror: | |
29 | raise tornado.web.HTTPError(404) | |
30 | ||
119f55d7 MT |
31 | ip_addr = self.get_argument("addr", self.request.remote_ip) |
32 | client_location = self.geoip.get_all(ip_addr) | |
33 | ||
34 | client_distance = mirror.distance_to(client_location, ignore_preference=True) | |
35 | client_distance *= 111.32 # to km | |
36 | ||
37 | self.render("mirrors-item.html", item=mirror, | |
38 | client_distance=client_distance) | |
940227cb MT |
39 | |
40 | ||
41 | class MirrorHandler(BaseHandler): | |
42 | def get(self): | |
43 | self.redirect("mirrors/all") | |
44 | ||
45 | ||
46 | class MirrorAllHandler(BaseHandler): | |
47 | def get(self): | |
48 | self.render("downloads-mirrors.html", mirrors=self.mirrors.list()) | |
49 | ||
50 | ||
51 | class MirrorDetailHandler(BaseHandler): | |
52 | def get(self, id): | |
53 | self.render("download-mirror-detail.html", mirror=self.mirrors.get(id)) | |
0a003782 MT |
54 | |
55 | ||
56 | class MirrorListPakfire2Handler(BaseHandler): | |
57 | def get(self): | |
58 | suffix = self.get_argument("suffix", "") | |
59 | ||
60 | self.set_header("Content-Type", "text/plain") | |
61 | ||
62 | mirrors = self.mirrors.get_all() | |
63 | ||
64 | lines = [] | |
65 | for m in mirrors: | |
66 | if not m.is_pakfire2(): | |
67 | continue | |
68 | ||
69 | path = [m.path,] | |
70 | ||
71 | if m.type == "full": | |
72 | path.append("pakfire2") | |
73 | ||
74 | if suffix: | |
75 | path.append(suffix) | |
76 | ||
77 | path = "/".join(path) | |
78 | ||
79 | # Remove double slashes. | |
80 | path = path.replace("//", "/") | |
81 | ||
82 | # Remove leading slash. | |
83 | if path.startswith("/"): | |
84 | path = path[1:] | |
85 | ||
86 | # Remove trailing slash. | |
87 | if path.endswith("/"): | |
88 | path = path[:-1] | |
89 | ||
90 | line = ("HTTP", m.hostname, path, "") | |
91 | lines.append(";".join(line)) | |
92 | ||
93 | self.finish("\r\n".join(lines)) |