aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2021-03-04 10:06:26 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2021-03-04 10:06:26 +0300
commit398cfd1bf0ae6b15aa8c981a87f94b5995c07003 (patch)
tree539651eabd95bb013392716cc23a67e940cc8b34
parentupdate README, add some comments, etc. (diff)
downloadlinux-status-398cfd1bf0ae6b15aa8c981a87f94b5995c07003.tar.gz
linux-status-398cfd1bf0ae6b15aa8c981a87f94b5995c07003.zip
server.py: port number is a parameter
-rwxr-xr-xserver.py20
1 files changed, 18 insertions, 2 deletions
diff --git a/server.py b/server.py
index 35099cf..d5a0f35 100755
--- a/server.py
+++ b/server.py
@@ -8,11 +8,16 @@
# This script launches a HTTP server and uses app.py for processing a set of
# custom URLs. See that file for the reasons behind this.
+import argparse
import http.server
+import sys
from app import Request
+DEFAULT_PORT = 18101
+
+
class RequestHandler(http.server.SimpleHTTPRequestHandler):
def do_GET(self):
try:
@@ -28,8 +33,19 @@ class RequestHandler(http.server.SimpleHTTPRequestHandler):
response.write_as_request_handler(self)
-def main():
- addr = ('', 18101)
+def parse_args(args=None):
+ if args is None:
+ args = sys.argv[1:]
+ parser = argparse.ArgumentParser()
+ parser.add_argument('-p', '--port', metavar='PORT',
+ type=int, default=DEFAULT_PORT,
+ help='set port number')
+ return parser.parse_args(args)
+
+
+def main(args=None):
+ args = parse_args(args)
+ addr = ('', args.port)
httpd = http.server.ThreadingHTTPServer(addr, RequestHandler)
try:
httpd.serve_forever()