23
from breezy import branch, errors
25
from loggerhead import util
26
from loggerhead.controllers import TemplatedBranchView
23
from breezy import branch, errors, urlutils
26
from breezy.transport import NoSuchFile
28
from breezy.errors import NoSuchFile
31
from ..controllers import TemplatedBranchView
29
34
class DirEntry(object):
31
36
def __init__(self, dirname, parity, branch):
32
self.dirname = dirname
37
self.dirname = urlutils.unquote(dirname)
33
38
self.parity = parity
34
39
self.branch = branch
35
40
if branch is not None:
36
41
# If a branch is empty, bzr raises an exception when trying this
38
self.last_change = datetime.datetime.utcfromtimestamp(
39
branch.repository.get_revision(
40
branch.last_revision()).timestamp)
42
self.last_change = None
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
45
50
class DirectoryUI(TemplatedBranchView):
49
template_path = 'loggerhead.templates.directory'
54
template_name = 'directory'
51
56
def __init__(self, static_url_base, transport, name):
74
79
b = branch.Branch.open_from_transport(self.transport.clone(d))
75
if b.get_config().get_user_option('http_serve') == 'False':
81
# TODO(jelmer): don't catch all exceptions here
79
83
if not stat.S_ISDIR(self.transport.stat(d).st_mode):
81
except errors.NoSuchFile:
89
if not b.get_config().get_user_option_as_bool('http_serve', default=True):
84
91
dirs.append(DirEntry(d, parity, b))
85
92
parity = 1 - parity
86
93
# Create breadcrumb trail