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

Unified Diff: tools/md_browser/md_browser.py

Issue 1952533002: Generalize md_browser to work on other repos (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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 2b968525320c8477f944307f599cc5178d69da94..1878807d65807d3850397d7901e51cf78d9098bb 100644
--- a/tools/md_browser/md_browser.py
+++ b/tools/md_browser/md_browser.py
@@ -25,10 +25,11 @@ def main(argv):
parser = argparse.ArgumentParser(prog='md_browser')
parser.add_argument('-p', '--port', type=int, default=8080,
help='port to run on (default = %(default)s)')
+ parser.add_argument('-d', '--directory', type=str, default=SRC_DIR)
args = parser.parse_args(argv)
try:
- s = Server(args.port, SRC_DIR)
+ s = Server(args.port, args.directory)
print("Listening on http://localhost:%s/" % args.port)
print(" Try loading http://localhost:%s/docs/README.md" % args.port)
Dirk Pranke 2016/05/06 01:23:41 Does it still make sense to execute line 34 if arg
agable 2016/05/09 21:00:00 Good point, put in something smarter.
s.serve_forever()
@@ -89,7 +90,7 @@ class Handler(SimpleHTTPServer.SimpleHTTPRequestHandler):
full_path = os.path.abspath(os.path.join(self.server.top_level, path[1:]))
- if not full_path.startswith(SRC_DIR):
+ if not full_path.startswith(self.server.top_level):
Dirk Pranke 2016/05/06 01:23:41 self.server.top_level isn't guaranteed to be an ab
agable 2016/05/09 21:00:00 Fixed, it becomes an abspath at Server.__init__ ti
self._DoUnknown()
elif path == '/doc.css':
self._DoCSS('doc.css')
@@ -142,6 +143,12 @@ class Handler(SimpleHTTPServer.SimpleHTTPRequestHandler):
self.wfile.write('<html><body>I do not know how to serve %s.</body>'
'</html>' % self.path)
+ def _ReadBoilerplate(self, relpath):
Dirk Pranke 2016/05/06 01:23:41 maybe just change _Read to take a second, optional
agable 2016/05/09 21:00:00 Done.
+ assert not relpath.startswith(os.sep)
+ path = os.path.join(SRC_DIR, relpath)
+ with codecs.open(path, encoding='utf-8') as fp:
+ return fp.read()
+
def _Read(self, relpath):
assert not relpath.startswith(os.sep)
path = os.path.join(self.server.top_level, relpath)
@@ -154,7 +161,8 @@ class Handler(SimpleHTTPServer.SimpleHTTPRequestHandler):
self.end_headers()
def _WriteTemplate(self, template):
- contents = self._Read(os.path.join('tools', 'md_browser', template))
+ contents = self._ReadBoilerplate(
+ os.path.join('tools', 'md_browser', template))
self.wfile.write(contents.encode('utf-8'))
« 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