started working to integrate vm and site

This commit is contained in:
2015-04-03 01:42:04 -04:00
parent 20913ff264
commit decf25ed29
11 changed files with 558 additions and 16 deletions

37
public/vm/cc0.cgi Executable file
View File

@@ -0,0 +1,37 @@
#!/usr/bin/python
from subprocess import call, CalledProcessError
from urllib import quote_plus, unquote_plus
from json import dumps
import cgitb, cgi
import sys
cgitb.enable()
form = cgi.FieldStorage()
infile = open('/tmp/a.c0', 'w')
infile.write(unquote_plus(form["data"].value))
infile.close()
stderr = open('/tmp/a.err', 'w')
if call(['/afs/andrew.cmu.edu/course/15/122/bin/cc0', '-b', '/tmp/a.c0',
'-o', '/tmp/a.bc0'], stderr=stderr, stdout=stderr) == 0:
bytecode = open('/tmp/a.bc0', 'r')
data = bytecode.read()
bytecode.close()
stderr.close()
else:
stderr.close()
stderr = open('/tmp/a.err', 'r')
data = stderr.read()
stderr.close()
name = "test"
print("Content-type:text/json\n\n")
print dumps({"data": quote_plus(data),
"name": quote_plus(name),
"input": form["data"].value)})