Commit 37075b34 authored by augustin_s's avatar augustin_s 🐍
Browse files

added commandline args incl. script dir selection; handle ctrl+c

parent f615daf2
#!/usr/bin/env python3
DIR = "."
HOST = "localhost"
PORT = 9090
import argparse
parser = argparse.ArgumentParser(
description="pier - Python Interpreter Executing Remotely",
parser.add_argument("-d", "--dir", default=DIR, help="directory containing python scripts")
parser.add_argument("-H", "--host", default=HOST, help="host name")
parser.add_argument("-P", "--port", default=PORT, help="port number", type=int)
clargs = parser.parse_args()
from contextlib import redirect_stdout, redirect_stderr
from functools import lru_cache
from glob import glob
from io import StringIO
import os
import http.server
import socketserver
HOST = "localhost"
PORT = 9090
class ScriptServer(http.server.SimpleHTTPRequestHandler):
def do_GET(self):
......@@ -71,10 +87,23 @@ def encode_html(*msg):
if __name__ == "__main__":
except Exception as e:
tn = type(e).__name__
msg = f"{tn}: {e}"
raise SystemExit(msg)
host =
port = clargs.port
socketserver.TCPServer.allow_reuse_address = True
with socketserver.ThreadingTCPServer((HOST, PORT), ScriptServer) as httpd:
print(f"serving at {HOST}:{PORT}")
with socketserver.ThreadingTCPServer((host, port), ScriptServer) as httpd:
print(f"serving at {host}:{port}")
except KeyboardInterrupt:
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment