aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/server.py
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2022-04-11 03:48:03 +0200
committerEgor Tensin <Egor.Tensin@gmail.com>2022-04-11 03:48:03 +0200
commit997196078d03e3ed7171368a4734ca16d6394f63 (patch)
tree8904f7f7d3d2b266b08bc55af0a865cef509fd99 /src/server.py
parentdebian: 1.2-2 (diff)
parentREADME: update (diff)
downloadlinux-status-997196078d03e3ed7171368a4734ca16d6394f63.tar.gz
linux-status-997196078d03e3ed7171368a4734ca16d6394f63.zip
Merge tag 'v2.0' into debian
Diffstat (limited to '')
-rwxr-xr-xsrc/server.py (renamed from server.py)29
1 files changed, 21 insertions, 8 deletions
diff --git a/server.py b/src/server.py
index 0ebe5d5..75723bd 100755
--- a/server.py
+++ b/src/server.py
@@ -24,6 +24,10 @@ def script_dir():
return os.path.dirname(os.path.realpath(__file__))
+def default_html_dir():
+ return os.path.join(script_dir(), 'html')
+
+
class RequestHandler(http.server.SimpleHTTPRequestHandler):
def do_GET(self):
try:
@@ -40,6 +44,14 @@ class RequestHandler(http.server.SimpleHTTPRequestHandler):
return
+def make_server(port):
+ addr = ('', port)
+ server = http.server.HTTPServer
+ if sys.version_info >= (3, 7):
+ server = http.server.ThreadingHTTPServer
+ return server(addr, RequestHandler)
+
+
def parse_args(args=None):
if args is None:
args = sys.argv[1:]
@@ -47,19 +59,20 @@ def parse_args(args=None):
parser.add_argument('-p', '--port', metavar='PORT',
type=int, default=DEFAULT_PORT,
help='set port number')
+ parser.add_argument('-d', '--dir', metavar='DIR',
+ default=default_html_dir(),
+ help='HTML directory path')
return parser.parse_args(args)
def main(args=None):
- # It's a failsafe; this script is only allowed to serve the directory it
- # resides in.
- os.chdir(script_dir())
args = parse_args(args)
- addr = ('', args.port)
- server = http.server.HTTPServer
- if sys.version_info >= (3, 7):
- server = http.server.ThreadingHTTPServer
- httpd = server(addr, RequestHandler)
+
+ # It's a failsafe; the script is not allowed to serve a random current
+ # working directory.
+ os.chdir(args.dir)
+
+ httpd = make_server(args.port)
try:
httpd.serve_forever()
except KeyboardInterrupt: