From ca13c4f59f1f85e152786f341a58dc07443c034e Mon Sep 17 00:00:00 2001 From: David Horstmann Date: Thu, 8 Dec 2022 14:33:52 +0000 Subject: [PATCH] Use helper function for error printing Signed-off-by: David Horstmann --- scripts/code_style.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/scripts/code_style.py b/scripts/code_style.py index 7de223a16..068298aec 100755 --- a/scripts/code_style.py +++ b/scripts/code_style.py @@ -28,6 +28,9 @@ UNCRUSTIFY_ARGS = ["-c", CONFIG_FILE] STDOUT_UTF8 = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8') STDERR_UTF8 = io.TextIOWrapper(sys.stderr.buffer, encoding='utf-8') +def print_err(*args): + print("Error: ", *args, file=STDERR_UTF8) + def get_src_files() -> List[str]: """ Use git ls-files to get a list of the source files @@ -41,8 +44,7 @@ def get_src_files() -> List[str]: stderr=STDERR_UTF8, check=False) if result.returncode != 0: - print("Error: git ls-files returned: "+str(result.returncode), \ - file=STDERR_UTF8) + print_err("git ls-files returned: "+str(result.returncode)) return [] else: src_files = str(result.stdout, "utf-8").split() @@ -59,8 +61,7 @@ def get_uncrustify_version() -> str: result = subprocess.run([UNCRUSTIFY_EXE, "--version"], \ stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=False) if result.returncode != 0: - print("Error getting version: "+str(result.stderr, "utf-8"), \ - file=STDERR_UTF8) + print_err("Could not get Uncrustify version:", str(result.stderr, "utf-8")) return "" else: return str(result.stdout, "utf-8") @@ -115,8 +116,7 @@ def fix_style(src_file_list: List[str]) -> int: # Guard against future changes that cause the codebase to require # more passes. if not check_style_is_correct(src_file_list): - print("Error: Code style still incorrect after second run of Uncrustify.", \ - file=STDERR_UTF8) + print("Code style still incorrect after second run of Uncrustify.") return 1 else: return 0