add error handling for argument and class creation

This commit is contained in:
example 2021-10-10 23:34:24 +02:00
parent 0cfdeda45e
commit 9894af021e

View file

@ -60,6 +60,11 @@ class SetStatus:
"""
return: boolean
"""
try:
self.status = int(self.status)
except Exception as e:
self.log.error('Status argument does not represent a integer')
return False
if self.status in (0, 1):
self.log.debug('Set value to {}'.format(self.status))
self.status = bytes([self.status])
@ -233,3 +238,12 @@ class SetStatus:
self.log.error('Error: {}'.format(e))
exit(7)
if __name__ == '__main__':
s = SetStatus()
if len(argv) < 2:
log.error('Usage: setstatus.py <0|1>')
exit(255)
else:
s.run(argv[1])