36 lines
796 B
Python
36 lines
796 B
Python
import os
|
|
import subprocess
|
|
import sys
|
|
import threading
|
|
import time
|
|
from flask import Flask, Response
|
|
|
|
|
|
app = Flask(__name__)
|
|
|
|
@app.route('/', defaults={'path': ''})
|
|
@app.route('/<path:path>')
|
|
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])
|