]>
git.ipfire.org Git - people/shoehn/ipfire.org.git/blob - webapp/handlers_mirrors.py
6 from handlers_base
import *
8 class MirrorIndexHandler(BaseHandler
):
10 ip_addr
= self
.get_argument("addr", None)
12 ip_addr
= self
.get_remote_ip()
14 location
= self
.geoip
.get_location(ip_addr
)
16 # Get a list of all mirrors.
17 mirrors
= self
.mirrors
.get_all()
19 # Choose the preferred ones by their location.
20 preferred_mirrors
= mirrors
.get_for_location(location
)
22 self
.render("mirrors.html",
23 preferred_mirrors
=preferred_mirrors
, mirrors
=mirrors
)
26 class MirrorItemHandler(BaseHandler
):
28 mirror
= self
.mirrors
.get_by_hostname(what
)
30 mirror
= self
.mirrors
.get(id)
33 raise tornado
.web
.HTTPError(404, what
)
35 ip_addr
= self
.get_argument("addr", None)
37 ip_addr
= self
.get_remote_ip()
38 client_location
= self
.geoip
.get_location(ip_addr
)
40 client_distance
= mirror
.distance_to(client_location
, ignore_preference
=True)
42 self
.render("mirrors-item.html", item
=mirror
, client_distance
=client_distance
)
45 class MirrorHandler(BaseHandler
):
47 self
.redirect("mirrors/all")
50 class MirrorAllHandler(BaseHandler
):
52 self
.render("downloads-mirrors.html", mirrors
=self
.mirrors
.list())
55 class MirrorDetailHandler(BaseHandler
):
57 self
.render("download-mirror-detail.html", mirror
=self
.mirrors
.get(id))
60 class MirrorListPakfire2Handler(BaseHandler
):
62 suffix
= self
.get_argument("suffix", "")
63 development
= self
.get_argument("development", None)
65 self
.set_header("Content-Type", "text/plain")
67 # Get all mirror servers that are currently up.
68 mirrors
= self
.mirrors
.get_all_up()
75 # Skip all non-development mirrors
76 # if we run in development mode.
77 if development
and not m
.development
:
80 path
= [m
.path
, "pakfire2"]
87 # Remove double slashes.
88 path
= path
.replace("//", "/")
90 # Remove leading slash.
91 if path
.startswith("/"):
94 # Remove trailing slash.
95 if path
.endswith("/"):
98 line
= ("HTTP", m
.hostname
, path
, "")
99 lines
.append(";".join(line
))
101 self
.finish("\r\n".join(lines
))