]> git.cworth.org Git - zombocom-ai/blob - run-turtle.py
Reword Coda's final message
[zombocom-ai] / run-turtle.py
1 #!/usr/bin/env python3
2
3 import cairo
4 import tempfile
5 import os
6 import sys
7
8 OUTPUT_DIR_PREFIX='/srv/cworth.org/zombocom'
9 OUTPUT_DIR="{}/busart".format(OUTPUT_DIR_PREFIX)
10
11 input = sys.stdin.read()
12
13 # Do at least a modicum of a safety check
14 if "import" in input:
15     sys.stderr.write("Error: Cowardly refusing to interpret script with 'import'")
16     sys.exit(1)
17
18 (fd, filename) = tempfile.mkstemp(suffix=".svg", prefix="busart", dir=OUTPUT_DIR);
19 os.close(fd)
20 os.chmod(filename, 0o644);
21
22 # Also delete our import for some more safety
23 del tempfile
24 del os
25 del sys
26
27 with cairo.SVGSurface(filename, 512, 512) as surface:
28     cr = cairo.Context(surface);
29     del cairo
30     cr.set_line_width(6);
31     exec(input);
32
33 web_file = filename.removeprefix(OUTPUT_DIR_PREFIX);
34
35 print(web_file);
36
37