scripts: Simplify code with sys.exit(<string>)
Promote a handy and often-overlooked sys.exit() feature: Passing it a string (or any other non-int object) prints it to stderr and exits with status 1. See the documentation at https://docs.python.org/3/library/sys.html#sys.exit. This indirectly prints some errors to stderr that previously went to stdout. Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
This commit is contained in:
parent
c898c156c9
commit
50b9b1249b
11 changed files with 32 additions and 51 deletions
|
@ -36,8 +36,7 @@ from elftools.elf.elffile import ELFFile
|
|||
from elftools.elf.sections import SymbolTableSection
|
||||
|
||||
if LooseVersion(elftools.__version__) < LooseVersion('0.24'):
|
||||
sys.stderr.write("pyelftools is out of date, need version 0.24 or later\n")
|
||||
sys.exit(1)
|
||||
sys.exit("pyelftools is out of date, need version 0.24 or later")
|
||||
|
||||
|
||||
def debug(text):
|
||||
|
@ -47,8 +46,7 @@ def debug(text):
|
|||
|
||||
|
||||
def error(text):
|
||||
sys.stderr.write(os.path.basename(sys.argv[0]) + ": " + text + "\n")
|
||||
sys.exit(1)
|
||||
sys.exit(os.path.basename(sys.argv[0]) + ": " + text)
|
||||
|
||||
|
||||
gdt_pd_fmt = "<HIH"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue