~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/controllers/bundle_ui.py

  • Committer: Michael Hudson
  • Date: 2008-06-23 01:40:28 UTC
  • mto: This revision was merged to the branch mainline in revision 169.
  • Revision ID: michael.hudson@canonical.com-20080623014028-1ia0mbz6k32o1j60
more loggerhead.conf compatible vhosting

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
import time
20
20
 
21
 
import turbogears
22
 
from cherrypy import HTTPRedirect, InternalError, response
 
21
from paste import httpexceptions
 
22
from paste.request import path_info_pop
23
23
 
24
24
 
25
25
class BundleUI (object):
29
29
        self._branch = branch
30
30
        self.log = branch.log
31
31
 
32
 
    @turbogears.expose()
33
 
    def default(self, *args, **kw):
 
32
    def default(self, request, response):
34
33
        # /bundle/<rev_id>/[<compare_rev_id>/]filename
35
34
        z = time.time()
36
 
        h = self._branch.get_history()
 
35
        h = self._branch.history
37
36
 
38
37
        h._branch.lock_read()
39
38
        try:
 
39
            args = []
 
40
            while 1:
 
41
                arg = path_info_pop(request.environ)
 
42
                if arg is None:
 
43
                    break
 
44
                args.append(arg)
40
45
            if len(args) < 1:
41
 
                raise HTTPRedirect(self._branch.url('/changes'))
 
46
                raise httpexceptions.HTTPMovedPermanently('../changes')
42
47
            revid = h.fix_revid(args[0])
43
48
            if len(args) >= 3:
44
49
                compare_revid = h.fix_revid(args[1])
49
54
                bundle_data = h.get_bundle(revid, compare_revid)
50
55
            except:
51
56
                self.log.exception('Exception fetching bundle')
52
 
                raise InternalError('Could not fetch bundle')
 
57
                raise httpexceptions.HTTPServerError('Could not fetch bundle')
53
58
 
54
59
            response.headers['Content-Type'] = 'application/octet-stream'
55
60
            response.headers['Content-Length'] = len(bundle_data)
56
 
            response.body = bundle_data
 
61
            response.write(bundle_data)
57
62
            self.log.info('/bundle: %r seconds' % (time.time() - z,))
58
 
            return response.body
59
63
        finally:
60
64
            h._branch.unlock()