Fixed retry

This commit is contained in:
Balthasar Reuter
2015-07-01 00:50:05 +02:00
parent 9df942423d
commit 604b7898e4

View File

@@ -303,7 +303,10 @@ class Photobooth:
filenames = [i for i in range(4)] filenames = [i for i in range(4)]
for x in range(4): for x in range(4):
# Try each picture up to 3 times # Try each picture up to 3 times
for attempt in range(3): remaining_attempts = 3
while remaining_attempts > 0:
remaining_attempts = remaining_attempts - 1
self.display.clear() self.display.clear()
self.display.show_message("S M I L E !!!\n\n" + str(x+1) + " of 4") self.display.show_message("S M I L E !!!\n\n" + str(x+1) + " of 4")
self.display.apply() self.display.apply()
@@ -312,19 +315,20 @@ class Photobooth:
try: try:
filenames[x] = self.camera.take_picture("/tmp/photobooth_%02d.jpg" % x) filenames[x] = self.camera.take_picture("/tmp/photobooth_%02d.jpg" % x)
break remaining_attempts = 0
except CameraException as e: except CameraException as e:
# On recoverable errors: display message and retry # On recoverable errors: display message and retry
if e.recoverable: #if e.recoverable:
if attempt < 3: print remaining_attempts
if remaining_attempts > 0:
self.display.clear() self.display.clear()
self.display.show_message(e.message) self.display.show_message(e.message)
self.display.apply() self.display.apply()
sleep(5) sleep(5)
else: else:
raise CameraException("Giving up! Please start again!", False) raise CameraException("Giving up! Please start over!", False)
else: #else:
raise e # raise e
# Sleep for a little bit if necessary # Sleep for a little bit if necessary
toc = clock() - tic toc = clock() - tic