From 7c22096681a3e6d3c88cf34809fdbae5efd134a5 Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Thu, 1 Jun 2023 16:57:42 +0000 Subject: Make textgen script more generic --- main.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 main.py diff --git a/main.py b/main.py new file mode 100644 index 0000000..eaad486 --- /dev/null +++ b/main.py @@ -0,0 +1,35 @@ +import os +import subprocess +import sys +import threading +import time +from flask import Flask, Response + + +app = Flask(__name__) + +@app.route('/', defaults={'path': ''}) +@app.route('/') +def handler(path): + if path == 'favicon.ico': + return Response(status=204) + + def run(): + try: + proc = subprocess.Popen( + map(lambda x: x.replace('{PATH}', path), sys.argv[2:]), + stdout=subprocess.PIPE + ) + for c in iter(lambda: proc.stdout.read(1), b''): + yield c + finally: + proc.kill() + + return Response(run(), mimetype='text/plain') + +def fixperms(): + time.sleep(0.05) + os.chmod(sys.argv[1], 660) + +threading.Thread(target=fixperms).start() +app.run(host='unix://' + sys.argv[1]) -- cgit v1.2.3-70-g09d2