~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/controllers/annotate_ui.py

  • Committer: robey
  • Date: 2006-12-15 10:05:25 UTC
  • mto: This revision was merged to the branch mainline in revision 26.
  • Revision ID: robey@tavi.lag.net-20061215100525-93qef6byfk0nopv6
use python2.4 from the env, not mac-style :)

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
import time
26
26
 
27
27
import turbogears
28
 
from cherrypy import HTTPError, InternalError, session
 
28
from cherrypy import HTTPRedirect, session
29
29
 
30
30
from loggerhead import util
31
31
 
41
41
        
42
42
class AnnotateUI (object):
43
43
 
44
 
    def __init__(self, branch):
45
 
        # BranchView object
46
 
        self._branch = branch
47
 
        self.log = branch.log
48
 
 
49
 
    @util.strip_whitespace
50
44
    @turbogears.expose(html='loggerhead.templates.annotate')
51
45
    def default(self, *args, **kw):
52
46
        z = time.time()
53
 
        h = self._branch.get_history()
54
 
        util.set_context(kw)
 
47
        h = util.get_history()
 
48
        
 
49
        if len(args) > 0:
 
50
            revid = h.fix_revid(args[0])
 
51
        else:
 
52
            revid = None
 
53
        
 
54
        path = kw.get('path', None)
 
55
        if (path == '/') or (path == '') or (path is None):
 
56
            raise HTTPRedirect(turbogears.url('/changes'))
55
57
 
56
 
        h._branch.lock_read()
57
58
        try:
58
 
            if len(args) > 0:
59
 
                revid = h.fix_revid(args[0])
60
 
            else:
61
 
                revid = h.last_revid
62
 
 
63
 
            path = None
64
 
            if len(args) > 1:
65
 
                path = '/'.join(args[1:])
66
 
                if not path.startswith('/'):
67
 
                    path = '/' + path
68
 
 
69
 
            file_id = kw.get('file_id', None)
70
 
            if (file_id is None) and (path is None):
71
 
                raise HTTPError(400, 'No file_id or filename provided to annotate')
72
 
 
73
 
            if file_id is None:
74
 
                file_id = h.get_file_id(revid, path)
75
 
 
76
 
            # no navbar for revisions
77
 
            navigation = util.Container()
78
 
 
79
 
            if path is None:
80
 
                path = h.get_path(revid, file_id)
81
 
            filename = os.path.basename(path)
82
 
 
83
 
            vals = {
84
 
                'branch': self._branch,
85
 
                'util': util,
86
 
                'revid': revid,
87
 
                'file_id': file_id,
88
 
                'path': path,
89
 
                'filename': filename,
90
 
                'history': h,
91
 
                'navigation': navigation,
92
 
                'change': h.get_changes([ revid ])[0],
93
 
                'contents': list(h.annotate_file(file_id, revid)),
94
 
            }
95
 
            h.flush_cache()
96
 
            self.log.info('/annotate: %r secs' % (time.time() - z,))
97
 
            return vals
98
 
        finally:
99
 
            h._branch.unlock()
 
59
            revlist, revid = h.get_navigation(revid, path)
 
60
            file_id = h.get_inventory(revid).path2id(path)
 
61
        except Exception, x:
 
62
            log.error('Exception fetching changes: %r, %s' % (x, x))
 
63
            raise HTTPRedirect(turbogears.url('/changes'))
 
64
            
 
65
        # no navbar for revisions
 
66
        navigation = util.Container()
 
67
 
 
68
        vals = {
 
69
            'branch_name': util.get_config().get('branch_name'),
 
70
            'util': util,
 
71
            'revid': revid,
 
72
            'path': path,
 
73
            'history': h,
 
74
            'navigation': navigation,
 
75
            'change': h.get_change(revid),
 
76
            'contents': list(h.annotate_file(file_id, revid)),
 
77
        }
 
78
        h.flush_cache()
 
79
        log.info('/annotate: %r secs' % (time.time() - z,))
 
80
        return vals