18
17
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25
from paste.httpexceptions import HTTPNotFound
27
from bzrlib import errors
28
from bzrlib.revision import is_null as is_null_rev
28
from cherrypy import HTTPRedirect, session
30
30
from loggerhead import util
31
from loggerhead.controllers import TemplatedBranchView
34
33
log = logging.getLogger("loggerhead.controllers")
39
path = path.rstrip('/')
40
path = urllib.quote(posixpath.dirname(path))
36
while path.endswith('/'):
38
path = posixpath.dirname(path)
44
class InventoryUI(TemplatedBranchView):
46
template_path = 'loggerhead.templates.inventory'
48
def get_filelist(self, inv, path, sort_type):
50
return the list of all files (and their attributes) within a given
53
@param inv: The inventory.
54
@param path: The path of a directory within the inventory.
55
@param sort_type: How to sort the results... XXX.
57
file_id = inv.path2id(path)
63
for filename, entry in dir_ie.children.iteritems():
64
revid_set.add(entry.revision)
67
for change in self._history.get_changes(list(revid_set)):
68
change_dict[change.revid] = change
70
for filename, entry in dir_ie.children.iteritems():
72
if entry.kind == 'directory':
75
absolutepath = pathname
77
absolutepath = path + '/' + pathname
78
revid = entry.revision
80
file = util.Container(
81
filename=filename, executable=entry.executable,
82
kind=entry.kind, absolutepath=absolutepath,
83
file_id=entry.file_id, size=entry.text_size, revid=revid,
84
change=change_dict[revid])
85
file_list.append(file)
87
if sort_type == 'filename':
88
file_list.sort(key=lambda x: x.filename.lower()) # case-insensitive
89
elif sort_type == 'size':
90
file_list.sort(key=lambda x: x.size)
91
elif sort_type == 'date':
92
file_list.sort(key=lambda x: x.change.date)
94
# Always sort directories first.
95
file_list.sort(key=lambda x: x.kind != 'directory')
99
def get_values(self, path, kwargs, headers):
100
history = self._history
101
branch = history._branch
42
class InventoryUI (object):
44
@turbogears.expose(html='loggerhead.templates.inventory')
45
def default(self, *args, **kw):
47
h = util.get_history()
50
revid = h.fix_revid(args[0])
54
file_id = kw.get('file_id', None)
55
sort_type = kw.get('sort', None)
103
revid = self.get_revid()
104
rev_tree = branch.repository.revision_tree(revid)
105
except errors.NoSuchRevision:
108
file_id = kwargs.get('file_id', None)
109
start_revid = kwargs.get('start_revid', None)
110
sort_type = kwargs.get('sort', 'filename')
58
revlist, revid = h.get_navigation(revid, file_id)
59
rev = h.get_revision(revid)
60
inv = h.get_inventory(revid)
62
log.error('Exception fetching changes: %r, %s' % (x, x))
63
raise HTTPRedirect(turbogears.url('/changes'))
112
65
# no navbar for revisions
113
66
navigation = util.Container()
116
path = path.rstrip('/')
117
file_id = rev_tree.path2id(path)
125
path = rev_tree.id2path(file_id)
126
except errors.NoSuchId:
129
# Are we at the top of the tree
130
if path in ['/', '']:
68
change = h.get_changes([ revid ])[0]
69
# add parent & merge-point branch-nick info, in case it's useful
70
h.get_branch_nicks([ change ])
72
path = inv.id2path(file_id)
73
if not path.startswith('/'):
75
idpath = inv.get_idpath(file_id)
133
77
updir = dirname(path)
135
# Directory Breadcrumbs
136
directory_breadcrumbs = util.directory_breadcrumbs(
137
self._branch.friendly_name,
138
self._branch.is_root,
141
if not is_null_rev(revid):
143
change = history.get_changes([ revid ])[0]
144
# If we're looking at the tip, use head: in the URL instead
145
if revid == branch.last_revision():
148
revno_url = history.get_revno(revid)
149
history.add_branch_nicks(change)
151
# Create breadcrumb trail for the path within the branch
152
branch_breadcrumbs = util.branch_breadcrumbs(path, rev_tree, 'files')
153
filelist = self.get_filelist(rev_tree.inventory, path, sort_type)
78
updir_file_id = idpath[-2]
160
branch_breadcrumbs = []
164
'branch': self._branch,
86
'branch_name': util.get_config().get('branch_name'),
167
'revno_url': revno_url,
171
'filelist': filelist,
93
'updir_file_id': updir_file_id,
94
'filelist': h.get_filelist(inv, path, sort_type),
96
'posixpath': posixpath,
172
97
'navigation': navigation,
173
'url': self._branch.context_url,
174
'start_revid': start_revid,
175
'fileview_active': True,
176
'directory_breadcrumbs': directory_breadcrumbs,
177
'branch_breadcrumbs': branch_breadcrumbs,
100
log.info('/inventory %r: %r secs' % (revid, time.time() - z))