18
17
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25
from paste.httpexceptions import HTTPNotFound, HTTPMovedPermanently
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, revno_url):
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)
61
if dir_ie.kind != 'directory':
62
raise HTTPMovedPermanently(self._branch.context_url(['/view', revno_url, path]))
66
for filename, entry in dir_ie.children.iteritems():
67
revid_set.add(entry.revision)
70
for change in self._history.get_changes(list(revid_set)):
71
change_dict[change.revid] = change
73
for filename, entry in dir_ie.children.iteritems():
75
if entry.kind == 'directory':
78
absolutepath = pathname
80
absolutepath = path + '/' + pathname
81
revid = entry.revision
83
file = util.Container(
84
filename=filename, executable=entry.executable,
85
kind=entry.kind, absolutepath=absolutepath,
86
file_id=entry.file_id, size=entry.text_size, revid=revid,
87
change=change_dict[revid])
88
file_list.append(file)
90
if sort_type == 'filename':
91
file_list.sort(key=lambda x: x.filename.lower()) # case-insensitive
92
elif sort_type == 'size':
93
file_list.sort(key=lambda x: x.size)
94
elif sort_type == 'date':
95
file_list.sort(key=lambda x: x.change.date)
97
# Always sort directories first.
98
file_list.sort(key=lambda x: x.kind != 'directory')
102
def get_values(self, path, kwargs, headers):
103
history = self._history
104
branch = history._branch
42
class InventoryUI (object):
44
def __init__(self, branch):
49
@turbogears.expose(html='loggerhead.templates.inventory')
50
def default(self, *args, **kw):
52
h = self._branch.get_history()
55
revid = h.fix_revid(args[0])
59
file_id = kw.get('file_id', None)
60
sort_type = kw.get('sort', None)
106
revid = self.get_revid()
107
rev_tree = branch.repository.revision_tree(revid)
108
except errors.NoSuchRevision:
111
file_id = kwargs.get('file_id', None)
112
start_revid = kwargs.get('start_revid', None)
113
sort_type = kwargs.get('sort', 'filename')
63
revid_list, revid = h.get_file_view(revid, file_id)
64
rev = h.get_revision(revid)
65
inv = h.get_inventory(revid)
67
self.log.error('Exception fetching changes: %s' % (x,))
68
util.log_exception(self.log)
69
raise HTTPRedirect(self._branch.url('/changes'))
115
71
# no navbar for revisions
116
72
navigation = util.Container()
119
path = path.rstrip('/')
120
file_id = rev_tree.path2id(path)
128
path = rev_tree.id2path(file_id)
129
except errors.NoSuchId:
132
# Are we at the top of the tree
133
if path in ['/', '']:
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 ])
78
path = inv.id2path(file_id)
79
if not path.startswith('/'):
81
idpath = inv.get_idpath(file_id)
136
83
updir = dirname(path)
138
# Directory Breadcrumbs
139
directory_breadcrumbs = util.directory_breadcrumbs(
140
self._branch.friendly_name,
141
self._branch.is_root,
144
if not is_null_rev(revid):
146
change = history.get_changes([ revid ])[0]
147
# If we're looking at the tip, use head: in the URL instead
148
if revid == branch.last_revision():
151
revno_url = history.get_revno(revid)
152
history.add_branch_nicks(change)
154
# Create breadcrumb trail for the path within the branch
155
branch_breadcrumbs = util.branch_breadcrumbs(path, rev_tree, 'files')
156
filelist = self.get_filelist(rev_tree.inventory, path, sort_type, revno_url)
84
updir_file_id = idpath[-2]
163
branch_breadcrumbs = []
167
92
'branch': self._branch,
170
'revno_url': revno_url,
174
'filelist': filelist,
99
'updir_file_id': updir_file_id,
100
'filelist': h.get_filelist(inv, path, sort_type),
102
'posixpath': posixpath,
175
103
'navigation': navigation,
176
'url': self._branch.context_url,
177
'start_revid': start_revid,
178
'fileview_active': True,
179
'directory_breadcrumbs': directory_breadcrumbs,
180
'branch_breadcrumbs': branch_breadcrumbs,
106
self.log.info('/inventory %r: %r secs' % (revid, time.time() - z))