/loggerhead/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/loggerhead/trunk

« back to all changes in this revision

Viewing changes to loggerhead/controllers/inventory_ui.py

  • Committer: Jelmer Vernooij
  • Date: 2018-09-08 15:16:32 UTC
  • mto: (491.6.1 breezy)
  • mto: This revision was merged to the branch mainline in revision 494.
  • Revision ID: jelmer@jelmer.uk-20180908151632-hsc80tbdusz1nz31
s/bazaar.conf/breezy.conf.

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
 
25
25
from paste.httpexceptions import HTTPNotFound, HTTPMovedPermanently
26
26
 
27
 
from breezy import (
28
 
    errors,
29
 
    osutils,
30
 
    urlutils,
31
 
    )
 
27
from breezy import errors
32
28
from breezy.revision import is_null as is_null_rev
33
29
 
34
 
from .. import util
35
 
from ..controllers import TemplatedBranchView
 
30
from loggerhead import util
 
31
from loggerhead.controllers import TemplatedBranchView
36
32
 
37
33
 
38
34
 
39
35
def dirname(path):
40
36
    if path is not None:
41
37
        path = path.rstrip('/')
42
 
        path = urlutils.escape(posixpath.dirname(path))
 
38
        path = urllib.quote(posixpath.dirname(path).encode('utf-8'))
43
39
    return path
44
40
 
45
41
 
46
42
class InventoryUI(TemplatedBranchView):
47
43
 
48
 
    template_name = 'inventory'
 
44
    template_path = 'loggerhead.templates.inventory'
49
45
    supports_json = True
50
46
 
51
47
    def get_filelist(self, tree, path, sort_type, revno_url):
64
60
 
65
61
        revid_set = set()
66
62
 
67
 
        child_entries = []
 
63
        child_entries = list(tree.iter_child_entries(path))
68
64
 
69
 
        for entry in tree.iter_child_entries(path):
70
 
            child_path = osutils.pathjoin(path, entry.name)
71
 
            child_revision = tree.get_file_revision(child_path)
72
 
            revid_set.add(child_revision)
73
 
            child_entries.append((child_path, entry, child_revision))
 
65
        for entry in child_entries:
 
66
            revid_set.add(entry.revision)
74
67
 
75
68
        change_dict = {}
76
69
        for change in self._history.get_changes(list(revid_set)):
77
70
            change_dict[change.revid] = change
78
71
 
79
 
        for child_path, entry, child_revision in child_entries:
 
72
        for entry in child_entries:
80
73
            pathname = entry.name
81
 
            contents_changed_rev = None
82
74
            if entry.kind == 'directory':
83
75
                pathname += '/'
84
 
                size = None
 
76
            if path == '':
 
77
                absolutepath = pathname
85
78
            else:
86
 
                size = entry.text_size
87
 
 
88
 
            file_timestamp = change_dict[child_revision].timestamp
 
79
                absolutepath = path + '/' + pathname
 
80
            revid = entry.revision
89
81
 
90
82
            # TODO: For the JSON rendering, this inlines the "change" aka
91
83
            # revision information attached to each file. Consider either
94
86
            # back the revision info.
95
87
            file = util.Container(
96
88
                filename=entry.name, executable=entry.executable,
97
 
                kind=entry.kind, absolutepath=child_path,
98
 
                size=size, revid=child_revision,
99
 
                change=change_dict[child_revision], contents_changed_rev=contents_changed_rev)
 
89
                kind=entry.kind, absolutepath=absolutepath,
 
90
                file_id=entry.file_id, size=entry.text_size, revid=revid,
 
91
                change=change_dict[revid])
100
92
            file_list.append(file)
101
93
 
102
94
        if sort_type == 'filename':
103
95
            file_list.sort(key=lambda x: x.filename.lower()) # case-insensitive
104
96
        elif sort_type == 'size':
105
 
            def size_key(x):
106
 
                if x.size is None:
107
 
                    return -1
108
 
                return x.size
109
 
            file_list.sort(key=size_key)
 
97
            file_list.sort(key=lambda x: x.size)
110
98
        elif sort_type == 'date':
111
 
            file_list.sort(key=lambda x: x.change.date, reverse=True)
 
99
            file_list.sort(key=lambda x: x.change.date)
112
100
 
113
 
        if sort_type != 'date':
114
 
        # Don't always sort directories first.
115
 
            file_list.sort(key=lambda x: x.kind != 'directory')
 
101
        # Always sort directories first.
 
102
        file_list.sort(key=lambda x: x.kind != 'directory')
116
103
 
117
104
        return file_list
118
105
 
125
112
        except errors.NoSuchRevision:
126
113
            raise HTTPNotFound()
127
114
 
 
115
        file_id = kwargs.get('file_id', None)
128
116
        start_revid = kwargs.get('start_revid', None)
129
117
        sort_type = kwargs.get('sort', 'filename')
130
118
 
131
 
        if path is None:
132
 
            path = "/"
133
 
 
134
 
        path = path.rstrip('/')
135
 
        if not rev_tree.has_filename(path) and not is_null_rev(revid):
136
 
            raise HTTPNotFound()
 
119
        if path is not None:
 
120
            path = path.rstrip('/')
 
121
            file_id = rev_tree.path2id(path)
 
122
            if file_id is None:
 
123
                raise HTTPNotFound()
 
124
        else:
 
125
            if file_id is None:
 
126
                path = ''
 
127
            else:
 
128
                try:
 
129
                    path = rev_tree.id2path(file_id)
 
130
                except errors.NoSuchId:
 
131
                    raise HTTPNotFound()
137
132
 
138
133
        # Are we at the top of the tree
139
134
        if path in ['/', '']:
142
137
            updir = dirname(path)
143
138
 
144
139
        if not is_null_rev(revid):
145
 
            change = history.get_changes([revid])[0]
 
140
            change = history.get_changes([ revid ])[0]
146
141
            # If we're looking at the tip, use head: in the URL instead
147
142
            if revid == branch.last_revision():
148
143
                revno_url = 'head:'