Spaces:
Sleeping
Sleeping
File size: 2,137 Bytes
45a1acf 66f8fc1 45a1acf 66f8fc1 45a1acf 66f8fc1 45a1acf 66f8fc1 45a1acf 66f8fc1 45a1acf 66f8fc1 45a1acf 329f9c0 45a1acf 329f9c0 45a1acf |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
from flask import Flask, request, send_from_directory, render_template_string
import os
import subprocess
app = Flask(__name__)
# Directory to save uploaded ISS files and generated EXEs
UPLOAD_FOLDER = 'uploads'
COMPILE_FOLDER = 'compiled'
os.makedirs(UPLOAD_FOLDER, exist_ok=True)
os.makedirs(COMPILE_FOLDER, exist_ok=True)
# HTML template for the interface
html_template = """
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Inno Setup Compiler</title>
</head>
<body>
<h1>Upload your .iss file to compile</h1>
<form action="/upload" method="post" enctype="multipart/form-data">
<input type="file" name="iss_file" accept=".iss" required>
<button type="submit">Upload and Compile</button>
</form>
<pre>{{ logs }}</pre>
</body>
</html>
"""
@app.route('/')
def index():
return render_template_string(html_template, logs="")
@app.route('/upload', methods=['POST'])
def upload_iss():
if 'iss_file' not in request.files:
return "No file part"
file = request.files['iss_file']
if file.filename == '':
return "No selected file"
# Save the ISS file
iss_path = os.path.join(UPLOAD_FOLDER, file.filename)
file.save(iss_path)
# Compile the ISS file using Inno Setup
exe_name = file.filename.replace('.iss', '.exe')
exe_path = os.path.join(COMPILE_FOLDER, exe_name)
# Command to run Inno Setup
compile_command = f'inno-setup-compiler "{iss_path}"'
# Run the command and capture logs
result = subprocess.run(compile_command, shell=True, capture_output=True, text=True)
logs = result.stdout + result.stderr
if result.returncode == 0:
return f'Compilation successful! Download <a href="/download/{exe_name}">here</a>'
else:
return f'Compilation failed: <pre>{logs}</pre>'
@app.route('/download/<filename>')
def download_file(filename):
return send_from_directory(COMPILE_FOLDER, filename)
if __name__ == '__main__':
app.run(host='0.0.0.0', port=7860, debug=True)
|