~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/controllers/bundle_ui.py

  • Committer: Martin Albisetti
  • Date: 2008-11-17 18:08:38 UTC
  • mto: This revision was merged to the branch mainline in revision 242.
  • Revision ID: argentina@gmail.com-20081117180838-lwumzgappr8t93vm
* Use head in the download URL when viewing HEAD of BRANCH
* Some cleanups

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#
2
 
# Copyright (C) 2006  Robey Pointer <robey@lag.net>
3
 
#
4
 
# This program is free software; you can redistribute it and/or modify
5
 
# it under the terms of the GNU General Public License as published by
6
 
# the Free Software Foundation; either version 2 of the License, or
7
 
# (at your option) any later version.
8
 
#
9
 
# This program is distributed in the hope that it will be useful,
10
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 
# GNU General Public License for more details.
13
 
#
14
 
# You should have received a copy of the GNU General Public License
15
 
# along with this program; if not, write to the Free Software
16
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
 
#
18
 
 
19
 
import os
20
 
import time
21
 
 
22
 
import turbogears
23
 
from cherrypy import HTTPRedirect, InternalError, response
24
 
 
25
 
from loggerhead import util
26
 
 
27
 
 
28
 
class BundleUI (object):
29
 
 
30
 
    def __init__(self, branch):
31
 
        # BranchView object
32
 
        self._branch = branch
33
 
        self.log = branch.log
34
 
 
35
 
    @turbogears.expose()
36
 
    def default(self, *args, **kw):
37
 
        # /bundle/<rev_id>/[<compare_rev_id>/]filename
38
 
        z = time.time()
39
 
        h = self._branch.get_history()
40
 
 
41
 
        h._branch.lock_read()
42
 
        try:
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'] = 'text/plain'
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()