~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/controllers/bundle_ui.py

  • Committer: Michael Hudson
  • Date: 2007-12-12 08:36:51 UTC
  • mto: This revision was merged to the branch mainline in revision 143.
  • Revision ID: michael.hudson@canonical.com-20071212083651-oyh34swjxbzceyi1
add a comment for spiv

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
import time
21
21
 
22
22
import turbogears
23
 
from cherrypy import HTTPRedirect, response
 
23
from cherrypy import HTTPRedirect, InternalError, response
24
24
 
25
25
from loggerhead import util
26
26
 
34
34
 
35
35
    @turbogears.expose()
36
36
    def default(self, *args, **kw):
37
 
        # /bundle/<rev_id>/filename
 
37
        # /bundle/<rev_id>/[<compare_rev_id>/]filename
38
38
        z = time.time()
39
39
        h = self._branch.get_history()
40
40
 
41
 
        if len(args) < 1:
42
 
            raise HTTPRedirect(self._branch.url('/changes'))
43
 
        revid = h.fix_revid(args[0])
44
 
 
 
41
        h._branch.lock_read()
45
42
        try:
46
 
            bundle_data = h.get_bundle(revid)
47
 
        except Exception, x:
48
 
            self.log.error('Exception fetching bundle: %s' % (x,))
49
 
            util.log_exception(self.log)
50
 
            raise HTTPRedirect(self._branch.url('/changes'))
51
 
            
52
 
        response.headers['Content-Type'] = 'text/plain'
53
 
        response.headers['Content-Length'] = len(bundle_data)
54
 
        response.body = bundle_data
55
 
        self.log.info('/bundle: %r seconds' % (time.time() - z,))
56
 
        return response.body
 
43
            if len(args) < 1:
 
44
                raise HTTPRedirect(self._branch.url('/changes'))
 
45
            revid = h.fix_revid(args[0])
 
46
            if len(args) >= 3:
 
47
                compare_revid = h.fix_revid(args[1])
 
48
            else:
 
49
                compare_revid = None
 
50
 
 
51
            try:
 
52
                bundle_data = h.get_bundle(revid, compare_revid)
 
53
            except:
 
54
                self.log.exception('Exception fetching bundle')
 
55
                raise InternalError('Could not fetch bundle')
 
56
 
 
57
            response.headers['Content-Type'] = 'application/octet-stream'
 
58
            response.headers['Content-Length'] = len(bundle_data)
 
59
            response.body = bundle_data
 
60
            self.log.info('/bundle: %r seconds' % (time.time() - z,))
 
61
            return response.body
 
62
        finally:
 
63
            h._branch.unlock()