~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-10-25 19:27:10 UTC
  • mfrom: (219.2.15 abstract_path)
  • Revision ID: martin.albisetti@canonical.com-20081025192710-js2p07p94c7twp9t
 * Use paths to navigate instead of file_ids
 * Cleanups on different methods and variables
 * Fixed bugs: #260363, #269365 and #128926

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
 
32
34
 
33
35
 
34
36
def dirname(path):
35
 
    while path.endswith('/'):
36
 
        path = path[:-1]
37
 
    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))
38
41
    return path
39
42
 
40
43
 
42
45
 
43
46
    template_path = 'loggerhead.templates.inventory'
44
47
 
45
 
    def get_values(self, h, args, kw, headers):
46
 
        if len(args) > 0:
47
 
            revid = h.fix_revid(args[0])
48
 
        else:
49
 
            revid = h.last_revid
 
48
    def get_values(self, history, revid, path, kwargs, headers):
 
49
 
 
50
        try:
 
51
            inv = history.get_inventory(revid)
 
52
        except:
 
53
            self.log.exception('Exception fetching changes')
 
54
            raise HTTPServerError('Could not fetch changes')
 
55
 
 
56
        file_id = kwargs.get('file_id', None)
 
57
        start_revid = kwargs.get('start_revid', None)
 
58
        sort_type = kwargs.get('sort', None)
50
59
 
51
60
        # no navbar for revisions
52
61
        navigation = util.Container()
 
62
 
 
63
        change = history.get_changes([ revid ])[0]
 
64
        # add parent & merge-point branch-nick info, in case it's useful
 
65
        history.get_branch_nicks([ change ])
 
66
 
 
67
        if path is not None:
 
68
            if not path.startswith('/'):
 
69
                path = '/' + path
 
70
            file_id = history.get_file_id(revid, path)
 
71
        else:
 
72
            path = inv.id2path(file_id)
 
73
        
 
74
        if file_id is None:
 
75
            file_id = inv.root.file_id
 
76
 
 
77
 
 
78
        idpath = inv.get_idpath(file_id)
 
79
        if len(idpath) > 1:
 
80
            updir = dirname(path)[1:]
 
81
        else:
 
82
            updir = None
 
83
 
53
84
        # Directory Breadcrumbs
54
85
        directory_breadcrumbs = util.directory_breadcrumbs(
55
86
                self._branch.friendly_name,
58
89
 
59
90
        if not is_null_rev(revid):
60
91
            try:
61
 
                inv = h.get_inventory(revid)
 
92
                inv = history.get_inventory(revid)
62
93
            except:
63
94
                self.log.exception('Exception fetching changes')
64
95
                raise HTTPServerError('Could not fetch changes')
65
96
 
66
 
            file_id = kw.get('file_id', inv.root.file_id)
67
 
            start_revid = kw.get('start_revid', None)
68
 
            sort_type = kw.get('sort', None)
69
 
 
70
 
            change = h.get_changes([revid])[0]
 
97
            change = history.get_changes([ revid ])[0]
71
98
            # add parent & merge-point branch-nick info, in case it's useful
72
 
            h.get_branch_nicks([change])
73
 
 
74
 
            path = inv.id2path(file_id)
75
 
            if not path.startswith('/'):
76
 
                path = '/' + path
77
 
            idpath = inv.get_idpath(file_id)
78
 
            if len(idpath) > 1:
79
 
                updir = dirname(path)
80
 
                updir_file_id = idpath[-2]
81
 
            else:
82
 
                updir = None
83
 
                updir_file_id = None
84
 
            if updir == '/':
85
 
                updir_file_id = None
 
99
            history.get_branch_nicks([ change ])
86
100
 
87
101
            # Create breadcrumb trail for the path within the branch
88
102
            branch_breadcrumbs = util.branch_breadcrumbs(path, inv, 'files')
89
 
            filelist = h.get_filelist(inv, file_id, sort_type)
 
103
            filelist = history.get_filelist(inv, file_id, sort_type)
90
104
        else:
91
105
            inv = None
92
106
            file_id = None
96
110
            path = "/"
97
111
            idpath = None
98
112
            updir = None
99
 
            updir_file_id = None
100
113
            branch_breadcrumbs = []
101
114
            filelist = []
102
115
 
108
121
            'file_id': file_id,
109
122
            'path': path,
110
123
            'updir': updir,
111
 
            'updir_file_id': updir_file_id,
112
124
            'filelist': filelist,
113
 
            'history': h,
 
125
            'history': history,
114
126
            'posixpath': posixpath,
115
127
            'navigation': navigation,
116
128
            'url': self._branch.context_url,