#! /usr/bin/env python3
###############################################################################
# (c) Roger Whittaker 2015-2023
# roger@disruptive.org.uk
# Free software licenced under the GPL
###############################################################################

import cgi
from subprocess import Popen, PIPE

from config import base

f = cgi.FieldStorage()
k = list(f.keys())

it = f["iterations"].value.strip()
sc = f["scale"].value.strip()
p = f["params"].value
pars = ""
for bit in p.split():
    pars = pars + " " + bit

pp = pars.strip().replace(" ", "_")

fn = "pen" + "_" + it + "_" + sc + "-" + pp

print("Content-Type: application/postscript")
print("Content-Disposition: attachment; filename=" + fn + ".ps")
print()

c1 = base + "/gppg -t ps " + it + " " + sc + " " + pars

p1 = Popen(c1.split(), stdout=PIPE)
ps = p1.communicate()[0].decode()

print(ps)
