24
from paste import httpexceptions
25
from paste.request import path_info_pop
25
from cherrypy import HTTPRedirect, response
27
28
log = logging.getLogger("loggerhead.controllers")
30
31
class DownloadUI (object):
32
def __init__(self, branch, history):
33
def __init__(self, branch):
33
35
self._branch = branch
34
self._history = history
35
36
self.log = branch.log
37
def __call__(self, environ, start_response):
39
def default(self, *args, **kw):
38
40
# /download/<rev_id>/<file_id>/[filename]
45
arg = path_info_pop(environ)
51
raise httpexceptions.HTTPMovedPermanently(self._branch.url('../changes'))
53
revid = h.fix_revid(args[0])
55
path, filename, content = h.get_file(file_id, revid)
56
mime_type, encoding = mimetypes.guess_type(filename)
58
mime_type = 'application/octet-stream'
60
self.log.info('/download %s @ %s (%d bytes)', path, h.get_revno(revid), len(content))
62
('Content-Type', mime_type),
63
('Content-Length', len(content)),
64
('Content-Disposition', 'attachment; filename=%s'%(filename,)),
66
start_response('200 OK', headers)
42
h = self._branch.get_history()
47
raise HTTPRedirect(self._branch.url('/changes'))
49
revid = h.fix_revid(args[0])
51
path, filename, content = h.get_file(file_id, revid)
52
mime_type, encoding = mimetypes.guess_type(filename)
54
mime_type = 'application/octet-stream'
56
self.log.info('/download %s @ %s (%d bytes)', path, h.get_revno(revid), len(content))
57
response.headers['Content-Type'] = mime_type
58
response.headers['Content-Length'] = len(content)
59
response.headers['Content-Disposition'] = 'attachment; filename=%s'%(filename,)
60
response.body = content