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:
Ulf Magnusson 2019-09-07 14:41:01 +02:00 committed by Carles Cufí
commit 50b9b1249b
11 changed files with 32 additions and 51 deletions

View file

@ -16,8 +16,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 subsystem_to_enum(subsys):
@ -396,8 +395,7 @@ class ElfHelper:
def find_kobjects(self, syms):
if not self.elf.has_dwarf_info():
sys.stderr.write("ELF file has no DWARF information\n")
sys.exit(1)
sys.exit("ELF file has no DWARF information")
app_smem_start = syms["_app_smem_start"]
app_smem_end = syms["_app_smem_end"]
@ -569,8 +567,7 @@ class ElfHelper:
sys.stdout.write(scr + ": " + text + "\n")
def error(self, text):
sys.stderr.write("%s ERROR: %s\n" % (scr, text))
sys.exit(1)
sys.exit("%s ERROR: %s\n" % (scr, text))
def debug_die(self, die, text):
fn, ln = get_filename_lineno(die)