~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-12-09 17:36:09 UTC
  • mfrom: (253.2.1 trunk)
  • Revision ID: argentina@gmail.com-20081209173609-vzkq72abocxwkzbi
Use configobj from bzr rather than external configobj. (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#
 
2
# Copyright (C) 2008  Canonical Ltd.
2
3
# Copyright (C) 2006  Robey Pointer <robey@lag.net>
3
4
# Copyright (C) 2006  Goffredo Baroncelli <kreijack@inwind.it>
4
5
#
19
20
 
20
21
import logging
21
22
import posixpath
 
23
import urllib
22
24
 
23
25
from paste.httpexceptions import HTTPServerError
24
26
 
 
27
from bzrlib.revision import is_null as is_null_rev
 
28
 
25
29
from loggerhead import util
26
30
from loggerhead.controllers import TemplatedBranchView
27
31
 
28
32
 
29
33
log = logging.getLogger("loggerhead.controllers")
30
34
 
 
35
 
31
36
def dirname(path):
32
 
    while path.endswith('/'):
33
 
        path = path[:-1]
34
 
    path = posixpath.dirname(path)
 
37
    if path is not None:
 
38
        while path.endswith('/'):
 
39
            path = path[:-1]
 
40
        path = urllib.quote(posixpath.dirname(path))
35
41
    return path
36
42
 
37
43
 
39
45
 
40
46
    template_path = 'loggerhead.templates.inventory'
41
47
 
42
 
    def get_values(self, h, args, kw, headers):
43
 
        if len(args) > 0:
44
 
            revid = h.fix_revid(args[0])
45
 
        else:
46
 
            revid = h.last_revid
 
48
    def get_values(self, path, kwargs, headers):
 
49
        history = self._history
 
50
        revid = self.get_revid()
47
51
 
48
52
        try:
49
 
            inv = h.get_inventory(revid)
 
53
            inv = history.get_inventory(revid)
50
54
        except:
51
55
            self.log.exception('Exception fetching changes')
52
56
            raise HTTPServerError('Could not fetch changes')
53
57
 
54
 
        file_id = kw.get('file_id', inv.root.file_id)
55
 
        start_revid = kw.get('start_revid', None)
56
 
        sort_type = kw.get('sort', None)
 
58
        file_id = kwargs.get('file_id', None)
 
59
        start_revid = kwargs.get('start_revid', None)
 
60
        sort_type = kwargs.get('sort', None)
57
61
 
58
62
        # no navbar for revisions
59
63
        navigation = util.Container()
60
64
 
61
 
        change = h.get_changes([ revid ])[0]
 
65
        change = history.get_changes([ revid ])[0]
62
66
        # add parent & merge-point branch-nick info, in case it's useful
63
 
        h.get_branch_nicks([ change ])
64
 
 
65
 
        path = inv.id2path(file_id)
66
 
        if not path.startswith('/'):
67
 
            path = '/' + path
68
 
        idpath = inv.get_idpath(file_id)
69
 
        if len(idpath) > 1:
70
 
            updir = dirname(path)
71
 
            updir_file_id = idpath[-2]
72
 
        else:
73
 
            updir = None
74
 
            updir_file_id = None
75
 
        if updir == '/':
76
 
            updir_file_id = None
 
67
        history.get_branch_nicks([ change ])
 
68
 
 
69
        if path is not None:
 
70
            if not path.startswith('/'):
 
71
                path = '/' + path
 
72
            file_id = history.get_file_id(revid, path)
 
73
        else:
 
74
            path = inv.id2path(file_id)
 
75
 
 
76
        if file_id is None:
 
77
            file_id = inv.root.file_id
 
78
 
 
79
        # Are we at the top of the tree
 
80
        if inv.is_root(file_id):
 
81
            updir = None
 
82
        else:
 
83
            updir = dirname(path)[1:]
 
84
 
 
85
        # Directory Breadcrumbs
 
86
        directory_breadcrumbs = util.directory_breadcrumbs(
 
87
                self._branch.friendly_name,
 
88
                self._branch.is_root,
 
89
                'files')
 
90
 
 
91
        if not is_null_rev(revid):
 
92
            try:
 
93
                inv = history.get_inventory(revid)
 
94
            except:
 
95
                self.log.exception('Exception fetching changes')
 
96
                raise HTTPServerError('Could not fetch changes')
 
97
 
 
98
            change = history.get_changes([ revid ])[0]
 
99
            # If we're looking at the tip, use head: in the URL instead
 
100
            if revid == history.last_revid:
 
101
                revno_url = 'head:'
 
102
            else:
 
103
                revno_url = history.get_revno(revid)
 
104
            # add parent & merge-point branch-nick info, in case it's useful
 
105
            history.get_branch_nicks([ change ])
 
106
 
 
107
            # Create breadcrumb trail for the path within the branch
 
108
            branch_breadcrumbs = util.branch_breadcrumbs(path, inv, 'files')
 
109
            filelist = history.get_filelist(inv, file_id, sort_type)
 
110
        else:
 
111
            inv = None
 
112
            file_id = None
 
113
            start_revid = None
 
114
            sort_type = None
 
115
            change = None
 
116
            path = "/"
 
117
            updir = None
 
118
            branch_breadcrumbs = []
 
119
            filelist = []
77
120
 
78
121
        return {
79
122
            'branch': self._branch,
80
123
            'util': util,
81
124
            'revid': revid,
 
125
            'revno_url': revno_url,
82
126
            'change': change,
83
127
            'file_id': file_id,
84
128
            'path': path,
85
129
            'updir': updir,
86
 
            'updir_file_id': updir_file_id,
87
 
            'filelist': h.get_filelist(inv, file_id, sort_type),
88
 
            'history': h,
 
130
            'filelist': filelist,
 
131
            'history': history,
89
132
            'posixpath': posixpath,
90
133
            'navigation': navigation,
91
134
            'url': self._branch.context_url,
92
135
            'start_revid': start_revid,
93
136
            'fileview_active': True,
 
137
            'directory_breadcrumbs': directory_breadcrumbs,
 
138
            'branch_breadcrumbs': branch_breadcrumbs,
94
139
        }