-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.py
executable file
·38 lines (33 loc) · 1.02 KB
/
server.py
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
#!/usr/bin/env python
import web
import tempfile
import os
urls = (
"/", "Index",
"/compile", "Compile",
)
app = web.application(urls, globals())
class Index:
def GET(self):
return web.redirect('/static/index.html')
class Compile:
def POST(self):
fd, filename = tempfile.mkstemp(suffix='.c')
f = os.fdopen(fd, 'w')
data = web.input()
f.write(data['code'])
f.close()
obj_filename = filename[:-1]+'o'
out_filename = filename[:-1]+'s'
#os.spawnl(os.P_WAIT, '/usr/bin/gcc', '-O2', '-c', '-S', filename, '-o', out_filename)
os.spawnl(os.P_WAIT, '/usr/bin/gcc', 'gcc', '-arch', 'armv5', '-O2', '-c', filename, '-o', obj_filename)
os.system('gobjdump -dl %s > %s' % (obj_filename, out_filename))
output = open(out_filename, 'r')
data = output.read()
output.close()
os.unlink(filename)
os.unlink(obj_filename)
os.unlink(out_filename)
return data
if __name__ == "__main__":
app.run()