]> git.apps.os.sepia.ceph.com Git - ceph-build.git/commitdiff
shellcheck_job.py: Tweak output
authorZack Cerza <zack@cerza.org>
Wed, 10 Sep 2025 21:09:59 +0000 (15:09 -0600)
committerZack Cerza <zack@cerza.org>
Thu, 11 Sep 2025 21:25:24 +0000 (15:25 -0600)
Signed-off-by: Zack Cerza <zack@cerza.org>
scripts/shellcheck_job.py

index 3b32b1abf2c413577381c5ee3904e9b9fab92ce2..81255567769d00d20819b0a7b63041b9fdc8254b 100755 (executable)
@@ -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: