Improve error handling
This commit is contained in:
parent
745ea43397
commit
e070665f3d
3 changed files with 24 additions and 9 deletions
|
@ -35,7 +35,11 @@ if __name__ == "__main__":
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
try:
|
||||||
handler = parse_url(args.url)
|
handler = parse_url(args.url)
|
||||||
image = handler(args.url, args.rotation or [0,0,0], args.resolution or [3840, 1920])
|
image = handler(args.url, args.rotation or [0,0,0], args.resolution or [3840, 1920])
|
||||||
|
|
||||||
image.save(args.output + "/" + args.title + ".png")
|
image.save(args.output + "/" + args.title + ".png")
|
||||||
|
except Exception as e:
|
||||||
|
with open(args.output + "/" + args.title + ".err", "w") as errorfile:
|
||||||
|
errorfile.write("")
|
||||||
|
|
|
@ -6,6 +6,8 @@ import uuid
|
||||||
import configparser
|
import configparser
|
||||||
import os
|
import os
|
||||||
import glob
|
import glob
|
||||||
|
import hashlib
|
||||||
|
import time
|
||||||
|
|
||||||
HTTP200 = "200 OK"
|
HTTP200 = "200 OK"
|
||||||
HTTP202 = "202 Accepted"
|
HTTP202 = "202 Accepted"
|
||||||
|
@ -90,12 +92,22 @@ def getjob(req):
|
||||||
jobid = req.path[-1]
|
jobid = req.path[-1]
|
||||||
content_disposition = None
|
content_disposition = None
|
||||||
|
|
||||||
if glob.glob("/tmp/panosteal/%s---*" % jobid):
|
found = glob.glob("/tmp/panosteal/%s---*" % jobid)
|
||||||
content = open(glob.glob("/tmp/panosteal/%s---*" % jobid)[0], "rb").read()
|
|
||||||
|
if found:
|
||||||
|
md5 = "Not happening."
|
||||||
|
while True:
|
||||||
|
content = open(found[0], "rb").read()
|
||||||
|
newmd5 = hashlib.md5(content).hexdigest()
|
||||||
|
if newmd5 == md5:
|
||||||
|
break
|
||||||
|
md5 = newmd5
|
||||||
|
time.sleep(0.5)
|
||||||
|
|
||||||
code = HTTP200
|
code = HTTP200
|
||||||
ctype = mimetypes.guess_type("any.png")[0]
|
ctype = mimetypes.guess_type("any.png")[0]
|
||||||
content_disposition = glob.glob("/tmp/panosteal/%s---*" % jobid)[0].split("---")[-1]
|
content_disposition = found[0].split("---")[-1]
|
||||||
elif os.path.isfile("/tmp/panosteal/%s.err" % jobid):
|
elif glob.glob("/tmp/panosteal/%s*err" % jobid):
|
||||||
content = "<h1>500 Internal Server Error</h1>".encode()
|
content = "<h1>500 Internal Server Error</h1>".encode()
|
||||||
code = HTTP500
|
code = HTTP500
|
||||||
ctype = HTML
|
ctype = HTML
|
||||||
|
@ -106,7 +118,7 @@ def getjob(req):
|
||||||
else:
|
else:
|
||||||
content = "".encode()
|
content = "".encode()
|
||||||
code = HTTP202
|
code = HTTP202
|
||||||
ctype = HTML
|
ctype = TEXT
|
||||||
|
|
||||||
res = Response(code, ctype, content)
|
res = Response(code, ctype, content)
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,6 @@ class createHandler(pyinotify.ProcessEvent):
|
||||||
try:
|
try:
|
||||||
handleIncoming(event.pathname)
|
handleIncoming(event.pathname)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise
|
|
||||||
with open(event.pathname + ".err", "w") as errorfile:
|
with open(event.pathname + ".err", "w") as errorfile:
|
||||||
errorfile.write("")
|
errorfile.write("")
|
||||||
print(e)
|
print(e)
|
||||||
|
|
Loading…
Reference in a new issue