~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-02-28 04:34:51 UTC
  • mto: This revision was merged to the branch mainline in revision 147.
  • Revision ID: michael.hudson@canonical.com-20080228043451-nuyn35437fuphe9y
more prep

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
31
29
 
52
50
        z = time.time()
53
51
        h = self._branch.get_history()
54
52
        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
53
 
 
54
        h._branch.lock_read()
65
55
        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
 
56
            if len(args) > 0:
 
57
                revid = h.fix_revid(args[0])
 
58
            else:
 
59
                revid = h.last_revid
 
60
 
 
61
            path = None
 
62
            if len(args) > 1:
 
63
                path = '/'.join(args[1:])
 
64
                if not path.startswith('/'):
 
65
                    path = '/' + path
 
66
 
 
67
            file_id = kw.get('file_id', None)
 
68
            if (file_id is None) and (path is None):
 
69
                raise HTTPError(400, 'No file_id or filename provided to annotate')
 
70
 
 
71
            if file_id is None:
 
72
                file_id = h.get_file_id(revid, path)
 
73
 
 
74
            # no navbar for revisions
 
75
            navigation = util.Container()
 
76
 
 
77
            if path is None:
 
78
                path = h.get_path(revid, file_id)
 
79
            filename = os.path.basename(path)
 
80
 
 
81
            vals = {
 
82
                'branch': self._branch,
 
83
                'util': util,
 
84
                'revid': revid,
 
85
                'file_id': file_id,
 
86
                'path': path,
 
87
                'filename': filename,
 
88
                'history': h,
 
89
                'navigation': navigation,
 
90
                'change': h.get_changes([ revid ])[0],
 
91
                'contents': list(h.annotate_file(file_id, revid)),
 
92
            }
 
93
            h.flush_cache()
 
94
            self.log.info('/annotate: %r secs' % (time.time() - z,))
 
95
            return vals
 
96
        finally:
 
97
            h._branch.unlock()