1
# Copyright (C) 2008 Canonical Ltd.
2
# (Authored by Martin Albisetti <argentina@gmail.com>)
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details.
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA
23
from breezy import branch, errors, urlutils
26
from breezy.transport import NoSuchFile
28
from breezy.errors import NoSuchFile
31
from ..controllers import TemplatedBranchView
34
class DirEntry(object):
36
def __init__(self, dirname, parity, branch):
37
self.dirname = urlutils.unquote(dirname)
40
if branch is not None:
41
# If a branch is empty, bzr raises an exception when trying this
43
self.last_revision = branch.repository.get_revision(branch.last_revision())
44
self.last_change_time = datetime.datetime.utcfromtimestamp(self.last_revision.timestamp)
45
except errors.NoSuchRevision:
46
self.last_revision = None
47
self.last_change_time = None
50
class DirectoryUI(TemplatedBranchView):
54
template_name = 'directory'
56
def __init__(self, static_url_base, transport, name):
58
class _branch(object):
63
return self._static_url_base + path
64
self._branch = _branch
65
self._history_callable = lambda: None
67
self._static_url_base = static_url_base
68
self.transport = transport
69
self.log = logging.getLogger('')
71
def get_values(self, path, kwargs, response):
72
listing = [d for d in self.transport.list_dir('.')
73
if not d.startswith('.')]
74
listing.sort(key=lambda x: x.lower())
79
b = branch.Branch.open_from_transport(self.transport.clone(d))
81
# TODO(jelmer): don't catch all exceptions here
83
if not stat.S_ISDIR(self.transport.stat(d).st_mode):
89
if not b.get_config().get_user_option_as_bool('http_serve', default=True):
91
dirs.append(DirEntry(d, parity, b))
93
# Create breadcrumb trail
94
directory_breadcrumbs = util.directory_breadcrumbs(
101
'directory_breadcrumbs': directory_breadcrumbs,