Skip to content

Commit 203a11c

Browse files
authored
Merge pull request #134 from ja5087/skip-error
economode: Skip over transient network/host errors
2 parents 19bc8a4 + b796e81 commit 203a11c

1 file changed

Lines changed: 15 additions & 7 deletions

File tree

staff/lab/economode

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import urllib3
1010
from ocflib.misc.shell import green
1111
from ocflib.misc.shell import red
1212
from ocflib.printing.printers import PRINTERS
13+
from urllib3.exceptions import TimeoutError
1314

1415

1516
class Printer:
@@ -100,14 +101,21 @@ def main():
100101
end=' ')
101102
sys.stdout.flush()
102103
with Printer(printer_name) as printer:
103-
if not printer.log_in(password):
104-
print(red('Error:'), 'the password is not correct. Try again.')
105-
return 1
106-
if printer.change_economode(args.setting.title()):
107-
print(green('OK'))
108-
else:
104+
try:
105+
printer.log_in(password)
106+
if not printer.logged_in:
107+
print(red('Error:'), 'the password is not correct. Try again.')
108+
return 1
109+
if printer.change_economode(args.setting.title()):
110+
print(green('OK'))
111+
else:
112+
print(red('Failure'))
113+
return 1
114+
except (OSError, TimeoutError) as e:
115+
# If no route to host (e.g. out of rotation) or timeout, we still
116+
# want to set economode on other printers
109117
print(red('Failure'))
110-
return 1
118+
print(e)
111119

112120

113121
if __name__ == '__main__':

0 commit comments

Comments
 (0)