Skip to content

Commit

Permalink
error refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
bleucitron committed Oct 16, 2014
1 parent fe572be commit 082eb76
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
24 changes: 14 additions & 10 deletions check.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,11 @@
images = glob.glob("/home/pi/nodescan/*.jpg") + glob.glob("/home/pi/nodescan/*.JPG")
# if image then process
if len(images) > 0:
returncode = check_call(["python", scandir + "scan.py", "--image", images[0]])
if returncode == 0:
# send back the ok message with the file attached
cmd = "mutt -s 'Voila ton scan !' -i /home/pi/nodescan/ok_msg.txt " + sender + " -a /home/pi/*.pdf < /dev/null"
os.system(cmd)
else:
# the image was not correctly processed
# send back the "file not processed" error message
cmd = "mutt -s 'Elle est moche ta photo' -i /home/pi/nodescan/error_process_msg.txt " + sender + " < /dev/null"
os.system(cmd)
check_call(["python", scandir + "scan.py", "--image", images[0]])
# send back the ok message with the file attached
cmd = "mutt -s 'Voila ton scan !' -i /home/pi/nodescan/ok_msg.txt " + sender + " -a /home/pi/*.pdf < /dev/null"
os.system(cmd)

else:
# there is no image to process
# send back the "no image attached" error message
Expand All @@ -54,3 +49,12 @@
fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
print(exc_type, fname, exc_tb.tb_lineno)
print "pb with %s" % mail

# the image was not correctly processed
# send back the "file not processed" error message
cmd = "mutt -s 'Elle est moche ta photo' -i /home/pi/nodescan/error_process_msg.txt " + sender + " < /dev/null"
os.system(cmd)
# clean
os.remove(mail)
os.system("rm -f /home/pi/nodescan/*.JPG /home/pi/nodescan/*.jpg /home/pi/nodescan/*.desc /home/pi/nodescan/*.pdf")
os.system("rm -f /home/pi/scanMail/sent/cur/*")
2 changes: 1 addition & 1 deletion scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
# find the contours in the edged image, keeping only the
# largest ones, and initialize the screen contour
(cnts, _) = cv2.findContours(edged.copy(), cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)
cnts = sorted(cnts, key = cv2.contourArea, reverse = True)[:5]
cnts = sorted(cnts, key = cv2.contourArea, reverse = True)[:1]

# loop over the contours
for c in cnts:
Expand Down

0 comments on commit 082eb76

Please sign in to comment.