From 0ff677b1743705c59c2ccd8405ff91273ea7d8fd Mon Sep 17 00:00:00 2001 From: SG Date: Thu, 23 Sep 2021 06:57:34 +1000 Subject: [PATCH] [FL-1862] Scripts, ob.py: improved return of error codes #720 --- scripts/ob.py | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/scripts/ob.py b/scripts/ob.py index fa859e89..be15a983 100755 --- a/scripts/ob.py +++ b/scripts/ob.py @@ -44,7 +44,13 @@ class Main: self.logger.addHandler(self.handler) # execute requested function 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): self.logger.info(f"Loading Option Bytes data") @@ -70,13 +76,11 @@ class Main: except subprocess.CalledProcessError as e: self.logger.error(e.output.decode()) self.logger.error(f"Failed to call STM32_Programmer_CLI") - exit(127) - return + return 127 except Exception as e: self.logger.error(f"Failed to call STM32_Programmer_CLI") self.logger.exception(e) - exit(126) - return + return 126 ob_correct = True for line in output.decode().split("\n"): line = line.strip() @@ -100,10 +104,10 @@ class Main: ob_correct = False if ob_correct: self.logger.info(f"OB Check OK") - exit(0) + return 0 else: self.logger.error(f"OB Check FAIL") - exit(255) + return 255 def set(self): self.logger.info(f"Setting Option Bytes") @@ -127,15 +131,14 @@ class Main: except subprocess.CalledProcessError as e: self.logger.error(e.output.decode()) self.logger.error(f"Failed to call STM32_Programmer_CLI") - exit(125) - return + return 125 except Exception as e: self.logger.error(f"Failed to call STM32_Programmer_CLI") self.logger.exception(e) - exit(124) - return + return 124 + return 0 if __name__ == "__main__": - Main()() - exit(0) + return_code = Main()() + exit(return_code)