Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(741)

Unified Diff: experimental/webtry/server.py

Issue 195143004: First pass at a web app that lets you run Skia code and see the results. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: remove stray png Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « experimental/webtry/index.html ('k') | experimental/webtry/template.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: experimental/webtry/server.py
diff --git a/experimental/webtry/server.py b/experimental/webtry/server.py
new file mode 100644
index 0000000000000000000000000000000000000000..8367b3e46ab44381ff5c808bf9cb61bb865880b1
--- /dev/null
+++ b/experimental/webtry/server.py
@@ -0,0 +1,79 @@
+import BaseHTTPServer
+import base64
+import json
+import logging
+import string
+import subprocess
+
+HOST_NAME = 'localhost'
+PORT_NUMBER = 8765
+
+def runCode(usercode):
+ f = open('template.cpp', 'rb')
+ template = string.Template(f.read())
+ f.close()
+
+ code = template.substitute(usercode=usercode)
+
+ f = open('result.cpp', 'wb')
+ f.write(code)
+ f.close()
+
+ msg = ""
+ img = ""
+ try:
+ logging.info("compiling")
+ msg = subprocess.check_output('ninja -C ../../out/Debug webtry'.split())
+ try:
+ logging.info("running")
+ msg = subprocess.check_output('../../out/Debug/webtry'.split())
+ f = open('foo.png', 'rb')
+ img = base64.b64encode(f.read())
+ f.close()
+ except subprocess.CalledProcessError as e:
+ logging.info(e)
+ msg = e.output
+ except subprocess.CalledProcessError as e:
+ logging.info(e)
+ msg = e.output
+
+ retval = {
+ 'message': msg
+ }
+ if img:
+ retval['img'] = img
+ return retval
+
+class MyHandler(BaseHTTPServer.BaseHTTPRequestHandler):
+ def do_POST(self):
+ logging.info("POST")
+ body = ""
+ l = self.rfile.readline()
+ while l.strip() != "EOF":
+ body += l
+ l = self.rfile.readline()
+ self.send_response(200)
+ self.send_header("Content-type", "application/json")
+ self.end_headers()
+ resp = runCode(body)
+ self.wfile.write(json.dumps(resp))
+ self.end_headers()
+
+ def do_GET(self):
+ """Respond to a GET request."""
+ self.send_response(200)
+ self.send_header("Content-type", "text/html")
+ self.end_headers()
+ f = open('index.html', 'rb')
+ self.wfile.write(f.read())
+ f.close()
+
+if __name__ == '__main__':
+ server_class = BaseHTTPServer.HTTPServer
+ httpd = server_class((HOST_NAME, PORT_NUMBER), MyHandler)
+ logging.info("Server Start: %s:%s" % (HOST_NAME, PORT_NUMBER))
+ try:
+ httpd.serve_forever()
+ except KeyboardInterrupt:
+ pass
+ httpd.server_close()
« no previous file with comments | « experimental/webtry/index.html ('k') | experimental/webtry/template.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698