return mirror
- def get_mirrors_for_address(self, address):
+ async def get_mirrors_for_address(self, address):
"""
Returns all mirrors in random order with preferred mirrors first
"""
return r
# Fetch all mirrors and shuffle them, but put preferred mirrors first
- return sorted(self, key=__sort)
+ return sorted([mirror async for mirror in self], key=__sort)
@functools.cached_property
def location(self):
Returns True if this mirror is preferred for clients on the given network.
"""
# If the AS matches, we will prefer this
- if self.asn and self.asn.number == network.asn:
+ if self.asn and self.asn == network.asn:
return True
# If the mirror and client are in the same country, we prefer this
###############################################################################
import configparser
+import os.path
+import pakfire
import tornado.web
from . import base
self.redirect("/distros/%s" % repo.distro.slug)
-class MirrorlistHandler(BaseHandler):
- def get(self, **kwargs):
+class MirrorlistHandler(base.NoAuthMixin, BaseHandler):
+ async def get(self, **kwargs):
# Fetch the repository
- repo = self._get_repo(**kwargs)
+ repo = await self._get_repo(**kwargs)
# Send nothing if repository isn't supposed to be mirrored
if not repo.mirrored:
# Fetch architecture
arch = self.get_argument("arch")
- mirrors = []
+ # Check if we support the architecture
+ if not arch in pakfire.supported_arches():
+ raise tornado.web.HTTPError(400, "Unsupported architecture: %s" % arch)
# Fetch mirrors
- for mirror in self.backend.mirrors.get_mirrors_for_address(self.current_address):
- mirrors.append({
- "url" : "/".join((mirror.url, repo.path, arch)),
+ mirrors = [
+ {
+ "url" : os.path.join(mirror.url, repo.path, arch),
"location" : mirror.country_code,
- })
+ }
+ for mirror in await self.backend.mirrors.get_mirrors_for_address(self.current_address)
+ ]
# Always use the buildservice itself as last resort
mirrors.append({
- "url" : "/".join((repo.download_url, arch)),
+ "url" : os.path.join(repo.download_url, arch),
})
self.finish({