~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/controllers/download_ui.py

[rs=mwhudson] many many improvements to loggerhead -- faster
        templating, leaner HTTP server, less caching, cleaner urls

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
import mimetypes
22
22
import time
23
23
 
24
 
import turbogears
25
 
from cherrypy import HTTPRedirect, response
26
 
 
 
24
from paste import httpexceptions
 
25
from paste.request import path_info_pop
27
26
 
28
27
log = logging.getLogger("loggerhead.controllers")
29
28
 
35
34
        self._branch = branch
36
35
        self.log = branch.log
37
36
 
38
 
    @turbogears.expose()
39
 
    def default(self, *args, **kw):
 
37
    def default(self, request, response):
40
38
        # /download/<rev_id>/<file_id>/[filename]
41
39
        z = time.time()
42
 
        h = self._branch.get_history()
43
 
        
 
40
        h = self._branch.history
 
41
 
44
42
        h._branch.lock_read()
45
43
        try:
 
44
            args = []
 
45
            while 1:
 
46
                arg = path_info_pop(request.environ)
 
47
                if arg is None:
 
48
                    break
 
49
                args.append(arg)
 
50
 
46
51
            if len(args) < 2:
47
 
                raise HTTPRedirect(self._branch.url('/changes'))
 
52
                raise httpexceptions.HTTPMovedPermanently(self._branch.url('../changes'))
48
53
 
49
54
            revid = h.fix_revid(args[0])
50
55
            file_id = args[1]
57
62
            response.headers['Content-Type'] = mime_type
58
63
            response.headers['Content-Length'] = len(content)
59
64
            response.headers['Content-Disposition'] = 'attachment; filename=%s'%(filename,)
60
 
            response.body = content
61
 
            return response.body
 
65
            response.write(content)
62
66
        finally:
63
67
            h._branch.unlock()