Allow CLI change of the http server port

master
pictuga 2015-08-28 19:22:23 +02:00
parent 9c7660fd63
commit 31fc939d52
1 changed files with 22 additions and 3 deletions

View File

@ -667,15 +667,34 @@ def cli_app():
log('done') log('done')
def isInt(string):
try:
int(string)
return True
except ValueError:
return False
def main(): def main():
if 'REQUEST_URI' in os.environ: if 'REQUEST_URI' in os.environ:
# mod_cgi # mod_cgi
wsgiref.handlers.CGIHandler().run(cgi_wrapper) 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 # 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() httpd.serve_forever()
else: else: