self.redirect_to_mirror(filename, log_download=True)
def find_mirror(self, filename):
- # Get all mirrors...
- mirrors = self.mirrors.get_all()
- mirrors = mirrors.get_with_file(filename)
- mirrors = mirrors.get_with_state("UP")
-
- if not mirrors:
+ exists = self.mirrors.file_exists(filename)
+ if not exists:
raise tornado.web.HTTPError(404, "File not found: %s" % filename)
# Find mirrors located near to the user.
- # If we have not found any, we use all.
+ # If we have not found any, we use a random one.
remote_location = self.get_remote_location()
if remote_location:
- mirrors_nearby = mirrors.get_for_location(remote_location)
+ mirrors = self.mirrors.get_for_location(remote_location, filename=filename)
- if mirrors_nearby:
- mirrors = mirrors_nearby
+ if mirrors:
+ return random.choice(mirrors)
- return mirrors.get_random()
+ return self.mirrors.get_random(filename=filename)
def redirect_to_mirror(self, filename, log_download=False):
# Find a random mirror.
class DownloadCompatHandler(BaseHandler):
def get(self, path, url):
- _filename = None
-
for filename in self.mirrors.get_all_files():
- if filename.endswith("/%s" % url):
- _filename = filename
- break
+ if not filename.endswith("/%s" % url):
+ continue
- if not _filename:
- raise tornado.web.HTTPError(404)
+ self.redirect("/%s" % filename)
+ return
- self.redirect("/%s" % _filename)
+ raise tornado.web.HTTPError(404)
class DownloadSplashHandler(BaseHandler):