2
# Copyright (C) 2006 Robey Pointer <robey@lag.net>
3
# Copyright (C) 2006 Goffredo Baroncelli <kreijack@inwind.it>
5
# This program is free software; you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 2 of the License, or
8
# (at your option) any later version.
10
# This program is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
15
# You should have received a copy of the GNU General Public License
16
# along with this program; if not, write to the Free Software
17
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29
from cherrypy import HTTPRedirect, response, session
31
from loggerhead import util
34
log = logging.getLogger("loggerhead.controllers")
37
class DownloadUI (object):
39
def __init__(self, branch):
45
def default(self, *args, **kw):
46
# /download/<rev_id>/<file_id>/[filename]
48
h = self._branch.get_history()
51
raise HTTPRedirect(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))
61
response.headers['Content-Type'] = mime_type
62
response.headers['Content-Length'] = len(content)
63
response.headers['Content-Disposition'] = 'attachment; filename=%s'%(filename,)
64
response.body = content