~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-07-28 05:26:13 UTC
  • mfrom: (128.13.91 new_theme_trunk)
  • Revision ID: michael.hudson@canonical.com-20080728052613-35uxs2xz28dsqdgz
merge the new theme created by Martin Albisetti
(this work sponsored by Canonical)

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 logging
21
20
import os
22
21
import posixpath
23
 
import time
24
 
 
25
 
import turbogears
26
 
from cherrypy import HTTPError
27
 
 
 
22
 
 
23
from paste.httpexceptions import HTTPBadRequest
 
24
 
 
25
from loggerhead.controllers import TemplatedBranchView
28
26
from loggerhead import util
29
27
 
30
28
 
31
 
log = logging.getLogger("loggerhead.controllers")
32
 
 
33
29
def dirname(path):
34
30
    while path.endswith('/'):
35
31
        path = path[:-1]
36
32
    path = posixpath.dirname(path)
37
33
    return path
38
34
 
39
 
        
40
 
class AnnotateUI (object):
41
 
 
42
 
    def __init__(self, branch):
43
 
        # BranchView object
44
 
        self._branch = branch
45
 
        self.log = branch.log
46
 
 
47
 
    @util.strip_whitespace
48
 
    @turbogears.expose(html='loggerhead.templates.annotate')
49
 
    def default(self, *args, **kw):
50
 
        z = time.time()
51
 
        h = self._branch.get_history()
52
 
        util.set_context(kw)
53
 
 
54
 
        h._branch.lock_read()
55
 
        try:
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()
 
35
class AnnotateUI (TemplatedBranchView):
 
36
 
 
37
    template_path = 'loggerhead.templates.annotate'
 
38
 
 
39
    def get_values(self, h, args, kw, headers):
 
40
        if len(args) > 0:
 
41
            revid = h.fix_revid(args[0])
 
42
        else:
 
43
            revid = h.last_revid
 
44
 
 
45
        path = None
 
46
        if len(args) > 1:
 
47
            path = '/'.join(args[1:])
 
48
            if not path.startswith('/'):
 
49
                path = '/' + path
 
50
 
 
51
        file_id = kw.get('file_id', None)
 
52
        if (file_id is None) and (path is None):
 
53
            raise HTTPBadRequest('No file_id or filename provided to annotate')
 
54
 
 
55
        if file_id is None:
 
56
            file_id = h.get_file_id(revid, path)
 
57
 
 
58
        # no navbar for revisions
 
59
        navigation = util.Container()
 
60
 
 
61
        if path is None:
 
62
            path = h.get_path(revid, file_id)
 
63
        filename = os.path.basename(path)
 
64
 
 
65
        return {
 
66
            'revid': revid,
 
67
            'file_id': file_id,
 
68
            'path': path,
 
69
            'filename': filename,
 
70
            'navigation': navigation,
 
71
            'change': h.get_changes([ revid ])[0],
 
72
            'contents': list(h.annotate_file(file_id, revid)),
 
73
            'fileview_active': True,
 
74
        }