#! /usr/bin/python3 # Last edited on 2026-01-12 14:48:38 by stolfi # python3 functions that check args and print error messages. # To be imported by other python scripts. import sys, os, subprocess; def run_command(command): result = subprocess.run(command, text = True, timeout = None) if result.returncode != 0: print(result.stderr) print(result.stdout) assert False, f"** {command[0]} failed - returned status = {result}" return # ...................................................................... def bash(cmd): # Execute the string {cmd} with "/bin/bash". result = subprocess.run([ cmd ], shell = True, executable = "/bin/bash") if result.returncode != 0: print(result.stderr) print(result.stdout) assert False, f"** {cmd} failed - returned status = {result}" # ...................................................................... def basic_line_loop(rd, process_line): # Loops on lines of file {rd}, like the implicit loop of {gawk}. # Parses each line using {process_line(nread, line)}. # On EOF, returns the count {nread} of lines read. nread = 0 while True: line = rd.readline() if line == "": # End of file: return nread nread += 1 process_line(nread, line) assert False # Never reaches here. # ----------------------------------------------------------------------