summaryrefslogtreecommitdiffstats
path: root/g2h/tree_page.py
diff options
context:
space:
mode:
Diffstat (limited to 'g2h/tree_page.py')
-rw-r--r--g2h/tree_page.py31
1 files changed, 23 insertions, 8 deletions
diff --git a/g2h/tree_page.py b/g2h/tree_page.py
index 977e981..9b7a0d5 100644
--- a/g2h/tree_page.py
+++ b/g2h/tree_page.py
@@ -1,14 +1,14 @@
import os
+from .file import sanitize_file_name, tree_join
from .page import Page
-
-def tree_prefix(sha, tree):
- return os.path.join(sha, 't', tree)
+from .tree import safe_join
class TreePage(Page):
def __init__(self, out_dir, name, commit, sub_tree, repo, content_subdir):
- super(TreePage, self).__init__('tree.md', out_dir, os.path.join(tree_prefix(commit.hexsha, sub_tree), 'index.md'), name, content_subdir)
- self.tree = commit.tree.join(sub_tree) if sub_tree else commit.tree
+ tree = safe_join(commit.tree, sub_tree)
+ super(TreePage, self).__init__('tree.md', out_dir, os.path.join(tree_join(commit, tree.path), '_index.md'), name, content_subdir)
+ self.tree = tree
self.repo = repo
self.commit = commit
self.sub_tree = sub_tree
@@ -17,8 +17,16 @@ class TreePage(Page):
entries = []
for node in nodes:
latest_commit = next(self.repo.iter_commits(self.commit, max_count=1, paths=node.path))
+ name = node.name
+ file_name = name
+ if node.type == 'tree':
+ name += '/'
+ file_name = name
+ else:
+ file_name = sanitize_file_name(name, self.tree.blobs)
entry = {
- 'name': node.name + str('/' if node.type == 'tree' else ''),
+ 'file_name': file_name,
+ 'name': name,
'modified': latest_commit.committed_datetime
}
entries.append(entry)
@@ -35,7 +43,8 @@ class TreePage(Page):
return {
'content_subdir': self.content_subdir,
'entries': self._get_entries(),
- 'subdir': '/'.join([self.content_subdir, tree_prefix(self.commit.hexsha, self.tree.path)]),
+ # TODO: Make this fit the rest of the system.
+ 'subdir': '/'.join([self.content_subdir, tree_join(self.commit, self.tree.path)]),
'title': self.name + ': Tree'
}
@@ -47,10 +56,16 @@ class TreePage(Page):
current = remaining.pop()
if not current in visited:
visited.add(current)
- tree = self.commit.tree.join(current) if current else self.commit.tree
+ tree = safe_join(self.commit.tree, current)
tree_pages.append(factory.new_tree(self.commit, tree.path, self.repo))
for sub_tree in tree.trees:
remaining.append(sub_tree.path)
return tree_pages
+ def get_files(self):
+ file_paths = []
+ for blob in self.tree.blobs:
+ file_paths.append(blob.path)
+
+ return file_paths