Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: cms/bin/test_server.py

Issue 29334114: issue 3546 - Add port and hostname options to CMS testing server (Closed)
Patch Set: Created Jan. 20, 2016, 1:39 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
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: cms/bin/test_server.py
===================================================================
--- a/cms/bin/test_server.py
+++ b/cms/bin/test_server.py
@@ -18,6 +18,7 @@
import mimetypes
import os
import sys
+import argparse
import jinja2
@@ -99,6 +100,7 @@
yield fragment.encode(UNICODE_ENCODING)
def handler(environ, start_response):
+
path = environ.get("PATH_INFO")
data = get_data(path)
@@ -115,12 +117,22 @@
return [data]
if __name__ == "__main__":
- if len(sys.argv) < 2:
- source = FileSource(os.curdir)
- elif os.path.isdir(sys.argv[1]):
+
+ parser = argparse.ArgumentParser(description='CMS testing server.')
+ parser.add_argument('-b', '--basepath', type=str, help='Base directory (EG: /path/to/web.eyeo.com)')
Sebastian Noack 2016/01/20 14:35:59 Please keep the path a positional argument rather
juliandoucette 2016/01/21 13:46:23 Done.
+ parser.add_argument('-n', '--hostname', type=str, help='Server hostname (EG: localhost, eyeo.com, 0.0.0.0)')
Sebastian Noack 2016/01/20 14:35:59 Specify "localhost" as default.
juliandoucette 2016/01/21 13:46:23 Done.
+ parser.add_argument('-p', '--port', type=str, help='Port number (EG: 8080, 5000)')
Sebastian Noack 2016/01/20 14:35:59 Specify 5000 as default.
juliandoucette 2016/01/21 13:46:23 Done.
+ args = parser.parse_args()
+
+ # for backwards compatibility
Sebastian Noack 2016/01/20 14:35:59 With the above comments addressed you don't need t
juliandoucette 2016/01/21 13:46:23 Agreed. Thank you for bringing that up.
+ if len(sys.argv) > 1 and os.path.isdir(sys.argv[1]):
source = FileSource(sys.argv[1])
+ hostname = 'localhost'
+ port = 5000
else:
- sys.exit("Usage: %s [source_dir]" % sys.argv[0])
+ source = FileSource(args.basepath or os.curdir)
+ hostname = args.hostname or 'localhost'
+ port = int(args.port or '5000')
try:
from werkzeug.serving import ThreadedWSGIServer, run_simple
@@ -158,4 +170,4 @@
print " * Running on http://%s:%i/" % server.server_address
server.serve_forever()
- run("localhost", 5000, handler, use_reloader=True, use_debugger=True)
+ run(hostname, port, handler, use_reloader=True, use_debugger=True)
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld