]> git.cworth.org Git - zombocom-ai/blobdiff - run-turtle.py
Hook the code panel up to actually execute something
[zombocom-ai] / run-turtle.py
old mode 100755 (executable)
new mode 100644 (file)
index fb74b02..bb117fd
@@ -1,32 +1,35 @@
 #!/usr/bin/env python3
 
-from svg_turtle import SvgTurtle
+import cairo
 import tempfile
 import os
+import sys
 
 OUTPUT_DIR_PREFIX='/srv/cworth.org/zombocom'
 OUTPUT_DIR="{}/busart".format(OUTPUT_DIR_PREFIX)
 
-t = SvgTurtle(512,512);
+input = sys.stdin.read()
 
-t.pencolor('red');
-
-t.penup();
-t.right(180);
-t.forward(200);
-t.right(180);
-t.pendown();
-
-for i in range(50):
-    t.forward(100);
-    t.left(123);
+# Do at least a modicum of a safety check
+if "import" in input:
+    sys.stderr.write("Error: Cowardly refusing to interpret script with 'import'")
+    sys.exit(1)
 
 (fd, filename) = tempfile.mkstemp(suffix=".svg", prefix="busart", dir=OUTPUT_DIR);
 os.close(fd)
-
-t.save_as(filename);
 os.chmod(filename, 0o644);
 
+# Also delete our import for some more safety
+del tempfile
+del os
+del sys
+
+with cairo.SVGSurface(filename, 512, 512) as surface:
+    cr = cairo.Context(surface);
+    del cairo
+    cr.set_line_width(6);
+    exec(input);
+
 web_file = filename.removeprefix(OUTPUT_DIR_PREFIX);
 
 print(web_file);