From: Michael Tremer Date: Tue, 10 Oct 2017 12:47:25 +0000 (+0100) Subject: mirror list: Use new arch concept X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=087a5f098c5c51abc6a3dd0bc8eebcd7b7d769c0;p=pbs.git mirror list: Use new arch concept Signed-off-by: Michael Tremer --- diff --git a/src/buildservice/arches.py b/src/buildservice/arches.py index f8d2849e..e9c2fc76 100644 --- a/src/buildservice/arches.py +++ b/src/buildservice/arches.py @@ -26,7 +26,20 @@ class Arches(base.Object): res = self.db.query("SELECT name FROM arches \ WHERE NOT name = ANY(%s)", ("noarch", "src")) - return sorted((a.name for a in res), key=priority) + return iter(sorted((a.name for a in res), key=priority)) + + def exists(self, name): + # noarch doesn't really exist + if name == "noarch": + return False + + res = self.db.get("SELECT 1 FROM arches \ + WHERE name = %s", name) + + if res: + return True + + return False def get_all(self, really=False): query = "SELECT * FROM arches" diff --git a/src/web/handlers.py b/src/web/handlers.py index 2d88d55a..b1b3eca8 100644 --- a/src/web/handlers.py +++ b/src/web/handlers.py @@ -209,10 +209,8 @@ class RepositoryMirrorlistHandler(BaseHandler): self.set_header("Content-Type", "text/plain") arch = self.get_argument("arch", None) - arch = self.pakfire.arches.get_by_name(arch) - - if not arch: - raise tornado.web.HTTPError(400, "You must specify the architecture.") + if not arch or not self.backend.arches.exists(arch): + raise tornado.web.HTTPError(400, "You must specify a valid architecture") ret = { "type" : "mirrorlist", @@ -229,7 +227,7 @@ class RepositoryMirrorlistHandler(BaseHandler): # Select a list of preferred mirrors for mirror in self.mirrors.get_for_location(self.current_address): mirrors.append({ - "url" : "/".join((mirror.url, distro.identifier, repo.identifier, arch.name)), + "url" : "/".join((mirror.url, distro.identifier, repo.identifier, arch)), "location" : mirror.country_code, "preferred" : 1, }) @@ -240,7 +238,7 @@ class RepositoryMirrorlistHandler(BaseHandler): for mirror in remaining_mirrors: mirrors.append({ - "url" : "/".join((mirror.url, distro.identifier, repo.identifier, arch.name)), + "url" : "/".join((mirror.url, distro.identifier, repo.identifier, arch)), "location" : mirror.country_code, "preferred" : 0, }) @@ -256,7 +254,7 @@ class RepositoryMirrorlistHandler(BaseHandler): continue mirror = { - "url" : "/".join((mirror.url, distro.identifier, repo.identifier, arch.name)), + "url" : "/".join((mirror.url, distro.identifier, repo.identifier, arch)), "location" : mirror.country_code, "preferred" : 0, }