~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-18 11:32:36 UTC
  • mfrom: (128.9.3 zpt.cleaner_urls)
  • mto: This revision was merged to the branch mainline in revision 164.
  • Revision ID: michael.hudson@canonical.com-20080618113236-g65tjloc0ft7zpp6
merge zpt.cleaner_urls yet again

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
20
21
import os
21
22
import posixpath
 
23
import time
22
24
 
 
25
from paste.request import path_info_pop
23
26
from paste.httpexceptions import HTTPBadRequest
24
27
 
25
 
from loggerhead.controllers import TemplatedBranchView
26
28
from loggerhead import util
27
 
 
 
29
from loggerhead.templatefunctions import templatefunctions
 
30
from loggerhead.zptsupport import load_template
 
31
 
 
32
 
 
33
log = logging.getLogger("loggerhead.controllers")
28
34
 
29
35
def dirname(path):
30
36
    while path.endswith('/'):
32
38
    path = posixpath.dirname(path)
33
39
    return path
34
40
 
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
 
        }
 
41
 
 
42
class AnnotateUI (object):
 
43
 
 
44
    def __init__(self, branch):
 
45
        # BranchView object
 
46
        self._branch = branch
 
47
        self.log = branch.log
 
48
 
 
49
    def default(self, request, response):
 
50
        z = time.time()
 
51
        h = self._branch.history
 
52
        kw = request.GET
 
53
        util.set_context(kw)
 
54
 
 
55
        h._branch.lock_read()
 
56
        try:
 
57
            args = []
 
58
            while 1:
 
59
                arg = path_info_pop(request.environ)
 
60
                if arg is None:
 
61
                    break
 
62
                args.append(arg)
 
63
 
 
64
            if len(args) > 0:
 
65
                revid = h.fix_revid(args[0])
 
66
            else:
 
67
                revid = h.last_revid
 
68
 
 
69
            path = None
 
70
            if len(args) > 1:
 
71
                path = '/'.join(args[1:])
 
72
                if not path.startswith('/'):
 
73
                    path = '/' + path
 
74
 
 
75
            file_id = kw.get('file_id', None)
 
76
            if (file_id is None) and (path is None):
 
77
                raise HTTPBadRequest('No file_id or filename provided to annotate')
 
78
 
 
79
            if file_id is None:
 
80
                file_id = h.get_file_id(revid, path)
 
81
 
 
82
            # no navbar for revisions
 
83
            navigation = util.Container()
 
84
 
 
85
            if path is None:
 
86
                path = h.get_path(revid, file_id)
 
87
            filename = os.path.basename(path)
 
88
 
 
89
            vals = {
 
90
                'branch': self._branch,
 
91
                'util': util,
 
92
                'revid': revid,
 
93
                'file_id': file_id,
 
94
                'path': path,
 
95
                'filename': filename,
 
96
                'history': h,
 
97
                'navigation': navigation,
 
98
                'change': h.get_changes([ revid ])[0],
 
99
                'contents': list(h.annotate_file(file_id, revid)),
 
100
                'url': self._branch.context_url,
 
101
            }
 
102
            vals.update(templatefunctions)
 
103
            self.log.info('/annotate: %r secs' % (time.time() - z,))
 
104
            response.headers['Content-Type'] = 'text/html'
 
105
            template = load_template('loggerhead.templates.annotate')
 
106
            template.expand_into(response, **vals)
 
107
        finally:
 
108
            h._branch.unlock()