error msg if no points (or incomplete data) is sent to upload

pull/3/merge
Michael Aschauer 2014-12-15 18:37:28 +01:00
rodzic b7a44b44f8
commit 58e3c9bd23
1 zmienionych plików z 35 dodań i 27 usunięć

Wyświetl plik

@ -9,40 +9,48 @@ import hashlib
pixels_per_millimeter = 10
def main():
emb = stitchcode.Embroidery()
data = cgi.FieldStorage();
xarr = data.getlist("x[]")
yarr = data.getlist("y[]")
jarr = data.getlist("j[]")
lx = -99999999
ly = -99999999
jarr = data.getlist("j[]")
fid = str(int(time.time() * 1000))
#sys.stderr.write(hashlib.sha1(str(time.time())).hexdigest())
if len(xarr) == len(yarr) == len(jarr) and len(xarr) > 1:
emb = stitchcode.Embroidery()
lx = -99999999
ly = -99999999
for i in range(0, len(xarr)):
x = float(xarr[i])
y = float(yarr[i])*-1;
if jarr[i] == "true":
j = True
else:
j = False
fid = str(int(time.time() * 1000))
#sys.stderr.write(hashlib.sha1(str(time.time())).hexdigest())
if not(x == lx and y == ly):
emb.addStitch(stitchcode.Point(x,y,j))
lx = x
ly = y
for i in range(0, len(xarr)):
x = float(xarr[i])
y = float(yarr[i])*-1;
if jarr[i] == "true":
j = True
else:
j = False
if not(x == lx and y == ly):
emb.addStitch(stitchcode.Point(x,y,j))
lx = x
ly = y
emb.translate_to_origin()
emb.flatten()
emb.scale(27.80/pixels_per_millimeter)
emb.add_endstitches_to_jumps(10)
#emb.to_triple_stitches()
emb.save_as_png("files/%s.png" % fid)
emb.save_as_exp("files/%s.exp" % fid)
emb.translate_to_origin()
emb.flatten()
emb.scale(27.80/pixels_per_millimeter)
emb.add_endstitches_to_jumps(10)
#emb.to_triple_stitches()
emb.save_as_png("files/%s.png" % fid)
emb.save_as_exp("files/%s.exp" % fid)
print "Content-Disposition: attachment; filename=%s.exp" % fid
print "Content-Type: application/octet-stream\n"
print emb.export_melco()
print "Content-Disposition: attachment; filename=%s.exp" % fid
print "Content-Type: application/octet-stream\n"
print emb.export_melco()
else:
print "Content-Type: text/html\n"
print "Error: no points or incomplete data request"
main()