~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/controllers/inventory_ui.py

merge in fix for 115174

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#
 
2
# Copyright (C) 2006  Robey Pointer <robey@lag.net>
 
3
# Copyright (C) 2006  Goffredo Baroncelli <kreijack@inwind.it>
 
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
 
 
20
import datetime
 
21
import logging
 
22
import os
 
23
import posixpath
 
24
import textwrap
 
25
import time
 
26
 
 
27
import turbogears
 
28
from cherrypy import InternalError, session
 
29
 
 
30
from loggerhead import util
 
31
 
 
32
 
 
33
log = logging.getLogger("loggerhead.controllers")
 
34
 
 
35
def dirname(path):
 
36
    while path.endswith('/'):
 
37
        path = path[:-1]
 
38
    path = posixpath.dirname(path)
 
39
    return path
 
40
 
 
41
        
 
42
class InventoryUI (object):
 
43
 
 
44
    def __init__(self, branch):
 
45
        # BranchView object
 
46
        self._branch = branch
 
47
        self.log = branch.log
 
48
 
 
49
    @util.strip_whitespace
 
50
    @turbogears.expose(html='loggerhead.templates.inventory')
 
51
    def default(self, *args, **kw):
 
52
        z = time.time()
 
53
        h = self._branch.get_history()
 
54
        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
        sort_type = kw.get('sort', None)
 
63
 
 
64
        try:
 
65
            revid_list, revid = h.get_file_view(revid, file_id)
 
66
            rev = h.get_revision(revid)
 
67
            inv = h.get_inventory(revid)
 
68
        except:
 
69
            self.log.exception('Exception fetching changes')
 
70
            raise InternalError('Could not fetch changes')
 
71
 
 
72
        # no navbar for revisions
 
73
        navigation = util.Container()
 
74
 
 
75
        change = h.get_changes([ revid ])[0]
 
76
        # add parent & merge-point branch-nick info, in case it's useful
 
77
        h.get_branch_nicks([ change ])
 
78
        
 
79
        path = inv.id2path(file_id)
 
80
        if not path.startswith('/'):
 
81
            path = '/' + path
 
82
        idpath = inv.get_idpath(file_id)
 
83
        if len(idpath) > 1:
 
84
            updir = dirname(path)
 
85
            updir_file_id = idpath[-2]
 
86
        else:
 
87
            updir = None
 
88
            updir_file_id = None
 
89
        if updir == '/':
 
90
            updir_file_id = None
 
91
 
 
92
        vals = {
 
93
            'branch': self._branch,
 
94
            'util': util,
 
95
            'revid': revid,
 
96
            'change': change,
 
97
            'file_id': file_id,
 
98
            'path': path,
 
99
            'updir': updir,
 
100
            'updir_file_id': updir_file_id,
 
101
            'filelist': h.get_filelist(inv, path, sort_type),
 
102
            'history': h,
 
103
            'posixpath': posixpath,
 
104
            'navigation': navigation,
 
105
        }
 
106
        h.flush_cache()
 
107
        self.log.info('/inventory %r: %r secs' % (revid, time.time() - z))
 
108
        return vals