[FL-1862] Scripts, ob.py: improved return of error codes #720

This commit is contained in:
SG 2021-09-23 06:57:34 +10:00 committed by GitHub
parent b3becb9d63
commit 0ff677b174
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -44,7 +44,13 @@ class Main:
self.logger.addHandler(self.handler) self.logger.addHandler(self.handler)
# execute requested function # execute requested function
self.loadOB() self.loadOB()
self.args.func()
return_code = self.args.func()
if isinstance(return_code, int):
return return_code
else:
self.logger.error(f"Forgotten return code")
return 255
def loadOB(self): def loadOB(self):
self.logger.info(f"Loading Option Bytes data") self.logger.info(f"Loading Option Bytes data")
@ -70,13 +76,11 @@ class Main:
except subprocess.CalledProcessError as e: except subprocess.CalledProcessError as e:
self.logger.error(e.output.decode()) self.logger.error(e.output.decode())
self.logger.error(f"Failed to call STM32_Programmer_CLI") self.logger.error(f"Failed to call STM32_Programmer_CLI")
exit(127) return 127
return
except Exception as e: except Exception as e:
self.logger.error(f"Failed to call STM32_Programmer_CLI") self.logger.error(f"Failed to call STM32_Programmer_CLI")
self.logger.exception(e) self.logger.exception(e)
exit(126) return 126
return
ob_correct = True ob_correct = True
for line in output.decode().split("\n"): for line in output.decode().split("\n"):
line = line.strip() line = line.strip()
@ -100,10 +104,10 @@ class Main:
ob_correct = False ob_correct = False
if ob_correct: if ob_correct:
self.logger.info(f"OB Check OK") self.logger.info(f"OB Check OK")
exit(0) return 0
else: else:
self.logger.error(f"OB Check FAIL") self.logger.error(f"OB Check FAIL")
exit(255) return 255
def set(self): def set(self):
self.logger.info(f"Setting Option Bytes") self.logger.info(f"Setting Option Bytes")
@ -127,15 +131,14 @@ class Main:
except subprocess.CalledProcessError as e: except subprocess.CalledProcessError as e:
self.logger.error(e.output.decode()) self.logger.error(e.output.decode())
self.logger.error(f"Failed to call STM32_Programmer_CLI") self.logger.error(f"Failed to call STM32_Programmer_CLI")
exit(125) return 125
return
except Exception as e: except Exception as e:
self.logger.error(f"Failed to call STM32_Programmer_CLI") self.logger.error(f"Failed to call STM32_Programmer_CLI")
self.logger.exception(e) self.logger.exception(e)
exit(124) return 124
return return 0
if __name__ == "__main__": if __name__ == "__main__":
Main()() return_code = Main()()
exit(0) exit(return_code)