~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/controllers/annotate_ui.py

  • Committer: Michael Hudson
  • Date: 2008-06-13 05:33:39 UTC
  • mto: This revision was merged to the branch mainline in revision 164.
  • Revision ID: michael.hudson@canonical.com-20080613053339-w1in3qyd8gq3e8zg
more progress

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
18
#
19
19
 
20
 
import datetime
21
20
import logging
22
21
import os
23
22
import posixpath
24
 
import textwrap
25
23
import time
26
24
 
27
25
import turbogears
28
 
from cherrypy import HTTPRedirect, session
 
26
from cherrypy import HTTPError
29
27
 
30
28
from loggerhead import util
 
29
from loggerhead.templatefunctions import templatefunctions
31
30
 
32
31
 
33
32
log = logging.getLogger("loggerhead.controllers")
47
46
        self.log = branch.log
48
47
 
49
48
    @util.strip_whitespace
50
 
    @turbogears.expose(html='loggerhead.templates.annotate')
 
49
    @turbogears.expose(html='zpt:loggerhead.templates.annotate')
51
50
    def default(self, *args, **kw):
52
51
        z = time.time()
53
52
        h = self._branch.get_history()
54
53
        util.set_context(kw)
55
 
        
56
 
        if len(args) > 0:
57
 
            revid = h.fix_revid(args[0])
58
 
        else:
59
 
            revid = None
60
 
        
61
 
        file_id = kw.get('file_id', None)
62
 
        if file_id is None:
63
 
            raise HTTPRedirect(self._branch.url('/changes'))
64
54
 
 
55
        h._branch.lock_read()
65
56
        try:
66
 
            revid_list, revid = h.get_file_view(revid, file_id)
67
 
        except Exception, x:
68
 
            self.log.error('Exception fetching changes: %s' % (x,))
69
 
            util.log_exception(self.log)
70
 
            raise HTTPRedirect(self._branch.url('/changes'))
71
 
            
72
 
        # no navbar for revisions
73
 
        navigation = util.Container()
74
 
        
75
 
        path = h.get_path(revid, file_id)
76
 
        filename = os.path.basename(path)
77
 
 
78
 
        vals = {
79
 
            'branch': self._branch,
80
 
            'util': util,
81
 
            'revid': revid,
82
 
            'file_id': file_id,
83
 
            'path': path,
84
 
            'filename': filename,
85
 
            'history': h,
86
 
            'navigation': navigation,
87
 
            'change': h.get_changes([ revid ])[0],
88
 
            'contents': list(h.annotate_file(file_id, revid)),
89
 
        }
90
 
        h.flush_cache()
91
 
        self.log.info('/annotate: %r secs' % (time.time() - z,))
92
 
        return vals
 
57
            if len(args) > 0:
 
58
                revid = h.fix_revid(args[0])
 
59
            else:
 
60
                revid = h.last_revid
 
61
 
 
62
            path = None
 
63
            if len(args) > 1:
 
64
                path = '/'.join(args[1:])
 
65
                if not path.startswith('/'):
 
66
                    path = '/' + path
 
67
 
 
68
            file_id = kw.get('file_id', None)
 
69
            if (file_id is None) and (path is None):
 
70
                raise HTTPError(400, 'No file_id or filename provided to annotate')
 
71
 
 
72
            if file_id is None:
 
73
                file_id = h.get_file_id(revid, path)
 
74
 
 
75
            # no navbar for revisions
 
76
            navigation = util.Container()
 
77
 
 
78
            if path is None:
 
79
                path = h.get_path(revid, file_id)
 
80
            filename = os.path.basename(path)
 
81
 
 
82
            vals = {
 
83
                'branch': self._branch,
 
84
                'util': util,
 
85
                'revid': revid,
 
86
                'file_id': file_id,
 
87
                'path': path,
 
88
                'filename': filename,
 
89
                'history': h,
 
90
                'navigation': navigation,
 
91
                'change': h.get_changes([ revid ])[0],
 
92
                'contents': list(h.annotate_file(file_id, revid)),
 
93
                'url': self._branch.context_url,
 
94
            }
 
95
            vals.update(templatefunctions)
 
96
            h.flush_cache()
 
97
            self.log.info('/annotate: %r secs' % (time.time() - z,))
 
98
            return vals
 
99
        finally:
 
100
            h._branch.unlock()