]>
git.ipfire.org Git - ipfire.org.git/blob - webapp/handlers_mirrors.py
70973d643d5ca3f3854d49279ffdebd0f3303607
6 from handlers_base
import *
8 class MirrorIndexHandler(BaseHandler
):
10 ip_addr
= self
.get_argument("addr", self
.request
.remote_ip
)
12 # Get a list of all mirrors.
13 all_mirrors
= self
.mirrors
.get_all()
15 # Choose the preferred ones by their location.
16 preferred_mirrors
= all_mirrors
.get_for_location(ip_addr
)
18 # Remove the preferred ones from the list of the rest.
19 other_mirrors
= all_mirrors
- preferred_mirrors
21 self
.render("mirrors.html",
22 preferred_mirrors
=preferred_mirrors
, other_mirrors
=other_mirrors
)
25 class MirrorItemHandler(BaseHandler
):
27 mirror
= self
.mirrors
.get(id)
29 raise tornado
.web
.HTTPError(404)
31 ip_addr
= self
.get_argument("addr", self
.request
.remote_ip
)
32 client_location
= self
.geoip
.get_all(ip_addr
)
34 client_distance
= mirror
.distance_to(client_location
, ignore_preference
=True)
35 client_distance
*= 111.32 # to km
37 self
.render("mirrors-item.html", item
=mirror
,
38 client_distance
=client_distance
)
41 class MirrorHandler(BaseHandler
):
43 self
.redirect("mirrors/all")
46 class MirrorAllHandler(BaseHandler
):
48 self
.render("downloads-mirrors.html", mirrors
=self
.mirrors
.list())
51 class MirrorDetailHandler(BaseHandler
):
53 self
.render("download-mirror-detail.html", mirror
=self
.mirrors
.get(id))
56 class MirrorListPakfire2Handler(BaseHandler
):
58 suffix
= self
.get_argument("suffix", "")
59 development
= self
.get_argument("development", None)
61 self
.set_header("Content-Type", "text/plain")
63 # Get all mirror servers that are currently up.
64 mirrors
= self
.mirrors
.get_all_up()
68 if not m
.mirrorlist
or not m
.is_pakfire2():
71 # Skip all non-development mirrors
72 # if we run in development mode.
73 if development
and not m
.development
:
79 path
.append("pakfire2")
86 # Remove double slashes.
87 path
= path
.replace("//", "/")
89 # Remove leading slash.
90 if path
.startswith("/"):
93 # Remove trailing slash.
94 if path
.endswith("/"):
97 line
= ("HTTP", m
.hostname
, path
, "")
98 lines
.append(";".join(line
))
100 self
.finish("\r\n".join(lines
))