~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/controllers/inventory_ui.py

  • Committer: Martin Albisetti
  • Date: 2008-06-13 19:45:59 UTC
  • mto: (157.1.3 loggerhead)
  • mto: This revision was merged to the branch mainline in revision 187.
  • Revision ID: argentina@gmail.com-20080613194559-cjxqao4r8kl47sze
 * Small CSS tweaks
 * Remove unused template code
 * Small visual tweaks to the changelog

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
 
import os
23
21
import posixpath
24
 
import textwrap
25
22
import time
26
23
 
27
24
import turbogears
28
 
from cherrypy import HTTPRedirect, session
 
25
from cherrypy import InternalError
29
26
 
30
27
from loggerhead import util
 
28
from loggerhead.templatefunctions import templatefunctions
31
29
 
32
30
 
33
31
log = logging.getLogger("loggerhead.controllers")
41
39
        
42
40
class InventoryUI (object):
43
41
 
44
 
    @turbogears.expose(html='loggerhead.templates.inventory')
 
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='zpt:loggerhead.templates.inventory')
45
49
    def default(self, *args, **kw):
46
50
        z = time.time()
47
 
        h = util.get_history()
48
 
        
49
 
        if len(args) > 0:
50
 
            revid = h.fix_revid(args[0])
51
 
        else:
52
 
            revid = None
53
 
        
54
 
        path = kw.get('path', None)
55
 
        if (path == '/') or (path == ''):
56
 
            path = None
 
51
        h = self._branch.get_history()
 
52
        util.set_context(kw)
57
53
 
 
54
        h._branch.lock_read()
58
55
        try:
59
 
            revlist, revid = h.get_navigation(revid, path)
60
 
            rev = h.get_revision(revid)
61
 
            inv = h.get_inventory(revid)
62
 
        except Exception, x:
63
 
            log.error('Exception fetching changes: %r, %s' % (x, x))
64
 
            raise HTTPRedirect(turbogears.url('/changes'))
65
 
 
66
 
        if path is None:
67
 
            path = '/'
68
 
            file_id = None
69
 
        else:
70
 
            file_id = inv.path2id(path)
71
 
            
72
 
        # no navbar for revisions
73
 
        navigation = util.Container()
74
 
 
75
 
        # add parent & merge-point branch-nick info, in case it's useful
76
 
        change = h.get_change(revid)
77
 
        for p in change.parents:
78
 
            p.branch_nick = h.get_change(p.revid).branch_nick
79
 
        for p in change.merge_points:
80
 
            p.branch_nick = h.get_change(p.revid).branch_nick
81
 
 
82
 
        vals = {
83
 
            'branch_name': util.get_config().get('branch_name'),
84
 
            'util': util,
85
 
            'revid': revid,
86
 
            'change': change,
87
 
            'path': path,
88
 
            'updir': dirname(path),
89
 
            'filelist': h.get_filelist(inv, path),
90
 
            'history': h,
91
 
            'posixpath': posixpath,
92
 
            'navigation': navigation,
93
 
        }
94
 
        h.flush_cache()
95
 
        log.info('/inventory %r: %r secs' % (revid, time.time() - z))
96
 
        return vals
 
56
            if len(args) > 0:
 
57
                revid = h.fix_revid(args[0])
 
58
            else:
 
59
                revid = h.last_revid
 
60
 
 
61
            try:
 
62
                inv = h.get_inventory(revid)
 
63
            except:
 
64
                self.log.exception('Exception fetching changes')
 
65
                raise InternalError('Could not fetch changes')
 
66
 
 
67
            file_id = kw.get('file_id', inv.root.file_id)
 
68
            start_revid = kw.get('start_revid', None)
 
69
            sort_type = kw.get('sort', None)
 
70
 
 
71
            # no navbar for revisions
 
72
            navigation = util.Container()
 
73
 
 
74
            change = h.get_changes([ revid ])[0]
 
75
            # add parent & merge-point branch-nick info, in case it's useful
 
76
            h.get_branch_nicks([ change ])
 
77
 
 
78
            path = inv.id2path(file_id)
 
79
            if not path.startswith('/'):
 
80
                path = '/' + path
 
81
            idpath = inv.get_idpath(file_id)
 
82
            if len(idpath) > 1:
 
83
                updir = dirname(path)
 
84
                updir_file_id = idpath[-2]
 
85
            else:
 
86
                updir = None
 
87
                updir_file_id = None
 
88
            if updir == '/':
 
89
                updir_file_id = None
 
90
 
 
91
            vals = {
 
92
                'branch': self._branch,
 
93
                'util': util,
 
94
                'revid': revid,
 
95
                'change': change,
 
96
                'file_id': file_id,
 
97
                'path': path,
 
98
                'updir': updir,
 
99
                'updir_file_id': updir_file_id,
 
100
                'filelist': h.get_filelist(inv, file_id, sort_type),
 
101
                'history': h,
 
102
                'posixpath': posixpath,
 
103
                'navigation': navigation,
 
104
                'url': self._branch.context_url,
 
105
                'start_revid': start_revid,
 
106
            }
 
107
            vals.update(templatefunctions)
 
108
            h.flush_cache()
 
109
            self.log.info('/inventory %r: %r secs' % (revid, time.time() - z))
 
110
            return vals
 
111
        finally:
 
112
            h._branch.unlock()