From 31fc939d5269156cf0022b41c8b64ecd7e246196 Mon Sep 17 00:00:00 2001 From: pictuga Date: Fri, 28 Aug 2015 19:22:23 +0200 Subject: [PATCH] Allow CLI change of the http server port --- morss/morss.py | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/morss/morss.py b/morss/morss.py index 3256f8f..7d2303c 100644 --- a/morss/morss.py +++ b/morss/morss.py @@ -667,15 +667,34 @@ def cli_app(): log('done') +def isInt(string): + try: + int(string) + return True + except ValueError: + return False + + def main(): if 'REQUEST_URI' in os.environ: # mod_cgi wsgiref.handlers.CGIHandler().run(cgi_wrapper) - elif len(sys.argv) <= 1: + elif len(sys.argv) <= 1 or isInt(sys.argv[1]): # start internal (basic) http server - print('Serving http://localhost:%s/'%PORT) - httpd = wsgiref.simple_server.make_server('', PORT, cgi_wrapper) + + if isInt(sys.argv[1]): + argPort = int(sys.argv[1]) + if argPort > 0: + port = argPort + else: + raise MorssException('Port must be positive integer') + + else: + port = PORT + + print('Serving http://localhost:%s/'%port) + httpd = wsgiref.simple_server.make_server('', port, cgi_wrapper) httpd.serve_forever() else: