23
from bzrlib import branch, errors
25
from loggerhead import util
23
from bzrlib import branch
26
25
from loggerhead.controllers import TemplatedBranchView
29
27
class DirEntry(object):
31
28
def __init__(self, dirname, parity, branch):
32
29
self.dirname = dirname
33
30
self.parity = parity
34
31
self.branch = branch
35
32
if branch is not None:
36
# If a branch is empty, bzr raises an exception when trying this
38
self.last_change = datetime.datetime.fromtimestamp(
39
branch.repository.get_revision(
40
branch.last_revision()).timestamp)
42
self.last_change = None
33
self.last_change = datetime.datetime.fromtimestamp(
34
branch.repository.get_revision(branch.last_revision()).timestamp)
45
36
class DirectoryUI(TemplatedBranchView):
49
40
template_path = 'loggerhead.templates.directory'
51
def __init__(self, static_url_base, transport, name):
42
def __init__(self, static_url_base, path, name):
53
43
class _branch(object):
58
return self._static_url_base + path
59
45
self._branch = _branch
60
self._history_callable = lambda: None
62
49
self._static_url_base = static_url_base
63
self.transport = transport
64
50
self.log = logging.getLogger('')
66
def get_values(self, path, kwargs, response):
67
listing = [d for d in self.transport.list_dir('.')
68
if not d.startswith('.')]
52
def get_values(self, h, args, kwargs, response):
53
listing = [d for d in os.listdir(self._path)
54
if not d.startswith('.')
55
and os.path.isdir(os.path.join(self._path, d))]
69
56
listing.sort(key=lambda x: x.lower())
60
return self._static_url_base + path
62
p = os.path.join(self._path, d)
74
b = branch.Branch.open_from_transport(self.transport.clone(d))
75
if b.get_config().get_user_option('http_serve') == 'False':
64
b = branch.Branch.open(p)
79
if not stat.S_ISDIR(self.transport.stat(d).st_mode):
81
except errors.NoSuchFile:
84
67
dirs.append(DirEntry(d, parity, b))
85
68
parity = 1 - parity
86
# Create breadcrumb trail
87
directory_breadcrumbs = util.directory_breadcrumbs(
93
71
'name': self._name,
94
'directory_breadcrumbs': directory_breadcrumbs,
72
'static_url': static_url,