]>
git.ipfire.org Git - ipfire.org.git/blob - src/web/download.py
6 from . import handlers_base
as base
8 from . import ui_modules
10 class IndexHandler(base
.BaseHandler
):
12 release
= self
.backend
.releases
.get_latest()
14 raise tornado
.web
.HTTPError(404)
16 self
.render("download/index.html", release
=release
)
19 class ReleaseHandler(base
.BaseHandler
):
21 release
= self
.backend
.releases
.get_by_sname(slug
)
23 raise tornado
.web
.HTTPError(404)
25 self
.render("download/release.html", release
=release
)
28 class FileHandler(base
.BaseHandler
):
30 self
.set_header("Pragma", "no-cache")
32 def head(self
, filename
):
33 self
.redirect_to_mirror(filename
)
35 def get(self
, filename
):
36 self
.redirect_to_mirror(filename
, log_download
=True)
38 def find_mirror(self
, filename
):
39 exists
= self
.mirrors
.file_exists(filename
)
41 raise tornado
.web
.HTTPError(404, "File not found: %s" % filename
)
43 # Find mirrors located near to the user.
44 # If we have not found any, we use a random one.
45 remote_location
= self
.get_remote_location()
48 mirrors
= self
.mirrors
.get_for_location(remote_location
, filename
=filename
)
51 return random
.choice(mirrors
)
53 return self
.mirrors
.get_random(filename
=filename
)
55 def redirect_to_mirror(self
, filename
, log_download
=False):
56 # Find a random mirror.
57 mirror
= self
.find_mirror(filename
)
59 # Construct the redirection URL.
60 download_url
= mirror
.build_url(filename
)
62 # Redirect the request.
63 self
.redirect(download_url
)
68 remote_location
= self
.get_remote_location()
70 country_code
= remote_location
.country
74 self
.db
.execute("INSERT INTO log_download(filename, mirror, country_code) \
75 VALUES(%s, %s, %s)", filename
, mirror
.id, country_code
)
78 class ButtonModule(ui_modules
.UIModule
):
79 def render(self
, release
):
80 for arch
in release
.arches
:
81 for file in release
.get_files_by_arch(arch
):
82 return self
.render_string("download/modules/button.html", release
=release
, file=file)