/loggerhead/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/loggerhead/trunk
9 by Robey Pointer
starting work on the inventory page, and some starting work on getting a changelog per-path
1
#
2
# Copyright (C) 2006  Robey Pointer <robey@lag.net>
23 by Robey Pointer
lots of little changes:
3
# Copyright (C) 2006  Goffredo Baroncelli <kreijack@inwind.it>
9 by Robey Pointer
starting work on the inventory page, and some starting work on getting a changelog per-path
4
#
5
# This program is free software; you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 2 of the License, or
8
# (at your option) any later version.
9
#
10
# This program is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with this program; if not, write to the Free Software
17
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
#
19
13 by Robey Pointer
clean up revision navigation so that the "revlist" you're browsing is
20
import logging
9 by Robey Pointer
starting work on the inventory page, and some starting work on getting a changelog per-path
21
import posixpath
18 by Robey Pointer
add a caching system for revision/change entries, since those should never
22
import time
9 by Robey Pointer
starting work on the inventory page, and some starting work on getting a changelog per-path
23
159.2.30 by Michael Hudson
trim down turbosimpletal and move it inside loggerhead package.
24
from paste.httpexceptions import HTTPServerError
25
from paste.request import path_info_pop
26
128.6.37 by Michael Hudson
convert annotate.pt to using metal in preparation for getting rid of the bizarro "here" hack
27
from loggerhead import util
128.6.36 by Michael Hudson
move the templatefunctions to a better location
28
from loggerhead.templatefunctions import templatefunctions
159.2.30 by Michael Hudson
trim down turbosimpletal and move it inside loggerhead package.
29
from loggerhead.zptsupport import load_template
9 by Robey Pointer
starting work on the inventory page, and some starting work on getting a changelog per-path
30
31
13 by Robey Pointer
clean up revision navigation so that the "revlist" you're browsing is
32
log = logging.getLogger("loggerhead.controllers")
33
9 by Robey Pointer
starting work on the inventory page, and some starting work on getting a changelog per-path
34
def dirname(path):
35
    while path.endswith('/'):
36
        path = path[:-1]
37
    path = posixpath.dirname(path)
38
    return path
39
40
        
41
class InventoryUI (object):
42
48 by Robey Pointer
the big migration of branch-specific data to a BranchView object: actually
43
    def __init__(self, branch):
44
        # BranchView object
45
        self._branch = branch
46
        self.log = branch.log
47
159.2.5 by Michael Hudson
basic functionality complete
48
    def default(self, request, response):
18 by Robey Pointer
add a caching system for revision/change entries, since those should never
49
        z = time.time()
159.2.5 by Michael Hudson
basic functionality complete
50
        h = self._branch.history
51
        kw = request.GET
97 by Robey Pointer
big checkpoint commit. added some functions to util for tracking browsing
52
        util.set_context(kw)
128.1.44 by Michael Hudson
delete wasteful doubled code
53
128.1.53 by Michael Hudson
grab a bzrlib read lock around the whole business of computing the data for the
54
        h._branch.lock_read()
128.1.38 by Michael Hudson
rewrite get_filelist to not loop over all the entries in the inventory
55
        try:
159.2.5 by Michael Hudson
basic functionality complete
56
            args = []
57
            while 1:
58
                arg = path_info_pop(request.environ)
59
                if arg is None:
60
                    break
61
                args.append(arg)
62
128.1.53 by Michael Hudson
grab a bzrlib read lock around the whole business of computing the data for the
63
            if len(args) > 0:
64
                revid = h.fix_revid(args[0])
65
            else:
66
                revid = h.last_revid
67
68
            try:
69
                inv = h.get_inventory(revid)
70
            except:
71
                self.log.exception('Exception fetching changes')
159.2.6 by Michael Hudson
less cherry
72
                raise HTTPServerError('Could not fetch changes')
128.1.53 by Michael Hudson
grab a bzrlib read lock around the whole business of computing the data for the
73
74
            file_id = kw.get('file_id', inv.root.file_id)
151.1.4 by Michael Hudson
propagate start_revid through to changes links on inventory pages
75
            start_revid = kw.get('start_revid', None)
128.1.53 by Michael Hudson
grab a bzrlib read lock around the whole business of computing the data for the
76
            sort_type = kw.get('sort', None)
77
78
            # no navbar for revisions
79
            navigation = util.Container()
80
81
            change = h.get_changes([ revid ])[0]
82
            # add parent & merge-point branch-nick info, in case it's useful
83
            h.get_branch_nicks([ change ])
84
85
            path = inv.id2path(file_id)
86
            if not path.startswith('/'):
87
                path = '/' + path
88
            idpath = inv.get_idpath(file_id)
89
            if len(idpath) > 1:
90
                updir = dirname(path)
91
                updir_file_id = idpath[-2]
92
            else:
93
                updir = None
94
                updir_file_id = None
95
            if updir == '/':
96
                updir_file_id = None
97
98
            vals = {
99
                'branch': self._branch,
100
                'util': util,
101
                'revid': revid,
102
                'change': change,
103
                'file_id': file_id,
104
                'path': path,
105
                'updir': updir,
106
                'updir_file_id': updir_file_id,
107
                'filelist': h.get_filelist(inv, file_id, sort_type),
108
                'history': h,
109
                'posixpath': posixpath,
110
                'navigation': navigation,
128.6.75 by Michael Hudson
a touch less duplication
111
                'url': self._branch.context_url,
151.1.4 by Michael Hudson
propagate start_revid through to changes links on inventory pages
112
                'start_revid': start_revid,
128.1.53 by Michael Hudson
grab a bzrlib read lock around the whole business of computing the data for the
113
            }
128.6.32 by Michael Hudson
fixes that i don't really understand how the tests didn't show the need for
114
            vals.update(templatefunctions)
128.1.53 by Michael Hudson
grab a bzrlib read lock around the whole business of computing the data for the
115
            self.log.info('/inventory %r: %r secs' % (revid, time.time() - z))
159.2.5 by Michael Hudson
basic functionality complete
116
            response.headers['Content-Type'] = 'text/html'
159.2.30 by Michael Hudson
trim down turbosimpletal and move it inside loggerhead package.
117
            template = load_template('loggerhead.templates.inventory')
118
            template.expand_into(response, **vals)
128.1.53 by Michael Hudson
grab a bzrlib read lock around the whole business of computing the data for the
119
        finally:
120
            h._branch.unlock()