From 0a003782ee0f192406fd74fdebd6f02784151104 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Tue, 25 Jun 2013 13:24:12 +0200 Subject: [PATCH] mirrors: Automatically generate mirror lists for pakfire 2. --- webapp/__init__.py | 1 + webapp/backend/mirrors.py | 2 ++ webapp/handlers_mirrors.py | 40 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+) diff --git a/webapp/__init__.py b/webapp/__init__.py index 3788e5f6..86a69504 100644 --- a/webapp/__init__.py +++ b/webapp/__init__.py @@ -118,6 +118,7 @@ class Application(tornado.web.Application): self.add_handlers(r"mirrors\.ipfire\.org", [ (r"/", MirrorIndexHandler), (r"/mirror/([0-9]+)", MirrorItemHandler), + (r"/lists/pakfire2", MirrorListPakfire2Handler), ] + static_handlers) # planet.ipfire.org diff --git a/webapp/backend/mirrors.py b/webapp/backend/mirrors.py index 38040464..4f6fc665 100644 --- a/webapp/backend/mirrors.py +++ b/webapp/backend/mirrors.py @@ -535,3 +535,5 @@ class Mirror(object): def priority(self): return self._info.get("priority", 10) + def is_pakfire2(self): + return self.type in ("full", "pakfire2") diff --git a/webapp/handlers_mirrors.py b/webapp/handlers_mirrors.py index d1a8a640..8278ee0d 100644 --- a/webapp/handlers_mirrors.py +++ b/webapp/handlers_mirrors.py @@ -51,3 +51,43 @@ class MirrorAllHandler(BaseHandler): 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", "") + + self.set_header("Content-Type", "text/plain") + + mirrors = self.mirrors.get_all() + + lines = [] + for m in mirrors: + if not m.is_pakfire2(): + continue + + path = [m.path,] + + if m.type == "full": + path.append("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)) -- 2.47.3