Created
February 26, 2013 11:10
-
-
Save yaniv-aknin/5037735 to your computer and use it in GitHub Desktop.
compileror: a file compilation service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import os | |
from subprocess import Popen | |
from tempfile import mkdtemp | |
from httplib import BAD_REQUEST | |
from flask import Flask, request, send_from_directory | |
from werkzeug.utils import secure_filename | |
app = Flask(__name__) | |
@app.route('/', methods=['POST']) | |
def upload_file(): | |
temp_dir = mkdtemp() | |
for field, uploaded in request.files.iteritems(): | |
filename = secure_filename(uploaded.filename) | |
uploaded.save(os.path.join(temp_dir, filename)) | |
assert os.path.exists(os.path.join(temp_dir, 'main.c')), 'no main.c' | |
process = Popen(['gcc', 'main.c', '-o', 'executable'], cwd=temp_dir) | |
if process.wait() != 0: | |
return 'ERROR', BAD_REQUEST | |
return send_from_directory(temp_dir, 'executable', as_attachment=True, attachment_filename='executable') | |
if __name__ == '__main__': | |
app.run(debug='DEBUG' in os.environ, port=int(os.environ.get('PORT', 5000)), host='0.0.0.0') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
web: ./compileror $PORT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Flask==0.9 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment