self.add_handlers(r"mirrors(\.dev)?\.ipfire\.org", [
(r"/", MirrorIndexHandler),
(r"/mirror/(.*)", MirrorItemHandler),
- (r"/lists/pakfire2", MirrorListPakfire2Handler),
] + static_handlers)
# planet.ipfire.org
return MirrorSet(self.backend, sorted(mirrors))
- def get_all_up(self):
- res = self.db.query("SELECT * FROM mirrors WHERE enabled = %s AND state = %s \
- ORDER BY hostname", True, "UP")
-
- mirrors = []
- for row in res:
- m = Mirror(self.backend, row.id, row)
- mirrors.append(m)
-
- return MirrorSet(self.backend, mirrors)
-
def get_by_hostname(self, hostname):
ret = self.db.get("SELECT * FROM mirrors WHERE hostname = %s", hostname)
class MirrorDetailHandler(BaseHandler):
def get(self, id):
self.render("download-mirror-detail.html", mirror=self.mirrors.get(id))
-
-
-class MirrorListPakfire2Handler(BaseHandler):
- def get(self):
- suffix = self.get_argument("suffix", "")
- development = self.get_argument("development", None)
-
- self.set_header("Content-Type", "text/plain")
-
- # Get all mirror servers that are currently up.
- mirrors = self.mirrors.get_all_up()
-
- lines = []
- for m in mirrors:
- if not m.mirrorlist:
- continue
-
- # Skip all non-development mirrors
- # if we run in development mode.
- if development and not m.development:
- continue
-
- path = [m.path, "pakfire2"]
-
- if suffix:
- path.append(suffix)
-
- path = "/".join(path)
-
- # Remove double slashes.
- path = path.replace("//", "/")
-
- # Remove leading slash.
- if path.startswith("/"):
- path = path[1:]
-
- # Remove trailing slash.
- if path.endswith("/"):
- path = path[:-1]
-
- line = ("HTTP", m.hostname, path, "")
- lines.append(";".join(line))
-
- self.finish("\r\n".join(lines))