Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(56)

Unified Diff: tools/md_browser/md_browser.py

Issue 2742683002: add basic directory listing support (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/md_browser/md_browser.py
diff --git a/tools/md_browser/md_browser.py b/tools/md_browser/md_browser.py
index d423c66c1ca5c28b82d00de7517b52d202093420..5118b30b245a26c8d18555b656aaa0ecfdff96fc 100755
--- a/tools/md_browser/md_browser.py
+++ b/tools/md_browser/md_browser.py
@@ -139,7 +139,7 @@ class Handler(SimpleHTTPServer.SimpleHTTPRequestHandler):
elif os.path.exists(full_path + '/README.md'):
self._DoMD(path + '/README.md')
else:
- self._DoUnknown()
+ self._DoDirListing(full_path)
def _DoMD(self, path):
extensions = [
@@ -186,10 +186,41 @@ class Handler(SimpleHTTPServer.SimpleHTTPRequestHandler):
self.wfile.write('<html><body>%s not found</body></html>' % self.path)
def _DoUnknown(self):
- self._WriteHeader('text/html')
+ self._WriteHeader('text/html', status_code=501)
self.wfile.write('<html><body>I do not know how to serve %s.</body>'
'</html>' % self.path)
+ def _DoDirListing(self, full_path):
+ self._WriteHeader('text/html')
+ self._WriteTemplate('header.html')
+
+ self.wfile.write('<div class="Breadcrumbs">\n')
+ self.wfile.write('<a class="Breadcrumbs-crumb">%s</a>\n' % self.path)
+ self.wfile.write('</div>\n')
+
+ for _, dirs, files in os.walk(full_path):
+ for f in sorted(files):
+ if f.startswith('.'):
+ continue
+ if f.endswith('.md'):
+ bold = ('<b>', '</b>')
+ else:
+ bold = ('', '')
+ self.wfile.write('<a href="%s/%s">%s%s%s</a><br/>\n' %
+ (self.path.rstrip('/'), f, bold[0], f, bold[1]))
+
+ self.wfile.write('<br/>\n')
+
+ for d in sorted(dirs):
+ if d.startswith('.'):
+ continue
+ self.wfile.write('<a href="%s/%s">%s/</a><br/>\n' %
+ (self.path.rstrip('/'), d, d))
+
+ break
+
+ self._WriteTemplate('footer.html')
+
def _Read(self, relpath, relative_to=None):
if relative_to is None:
relative_to = self.server.top_level
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698