add error handling for argument and class creation
This commit is contained in:
parent
0cfdeda45e
commit
9894af021e
1 changed files with 14 additions and 0 deletions
|
@ -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])
|
||||
|
||||
|
|
Loading…
Reference in a new issue