~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-16 08:08:33 UTC
  • mto: This revision was merged to the branch mainline in revision 164.
  • Revision ID: michael.hudson@canonical.com-20080616080833-2rz64gwvi407ocbv
no more cherrypy! in the code anyway, tests currently screwed of course

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