From a1e451b93427f2b52ec22f1d09f4c219c6a193c8 Mon Sep 17 00:00:00 2001 From: Zack Cerza Date: Wed, 10 Sep 2025 15:09:59 -0600 Subject: [PATCH] shellcheck_job.py: Tweak output Signed-off-by: Zack Cerza --- scripts/shellcheck_job.py | 53 ++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 23 deletions(-) diff --git a/scripts/shellcheck_job.py b/scripts/shellcheck_job.py index 3b32b1ab..81255567 100755 --- a/scripts/shellcheck_job.py +++ b/scripts/shellcheck_job.py @@ -15,6 +15,13 @@ def parse_args(args: list[str]) -> argparse.Namespace: nargs="*", help="The job XML file(s) to process", ) + parser.add_argument( + "-v", + "--verbose", + action="store_true", + default=False, + help="Be more verbose", + ) return parser.parse_args(args) @@ -24,32 +31,32 @@ def main(): for job_xml in args.job_xml: path = pathlib.Path(job_xml) assert path.exists - print("#" * 79) - print(f"## Processing job {job_xml}") + if args.verbose: + print(f"JOB: {job_xml}") job_obj = xmltodict.parse(path.read_text()) - print("#" * 79) - success = success and process_job(job_obj) + for item in find(job_obj, "command"): + try: + if args.verbose: + print(f" shellcheck {item[0]}") + process_item(item) + except Exception: + print(f"Failed to verify job {job_xml} item {item[0]}") + success = False + if args.verbose: + print() return 0 if success else 1 - -def process_job(job_obj: dict) -> bool: - success = True - for item in find(job_obj, "command"): - print("#" + "-" * 78) - print(f"# Running shellcheck on {item[0]}") - print("#" + "-" * 78) - script = item[1] - if not script.startswith("#!"): - script = "#!/bin/bash\n" + script - proc = subprocess.Popen( - ["shellcheck", "--severity", "error", "-"], - stdin=subprocess.PIPE, - encoding="utf-8", - ) - proc.communicate(input=script) - success = proc.returncode == 0 and success - return success - +def process_item(item): + script = item[1] + if not script.startswith("#!"): + script = "#!/bin/bash\n" + script + proc = subprocess.Popen( + ["shellcheck", "--severity", "error", "-"], + stdin=subprocess.PIPE, + encoding="utf-8", + ) + proc.communicate(input=script) + assert proc.returncode == 0 def find(obj: dict, key: str, result=None, path="") -> list[tuple]: if result is None: -- 2.39.5