From d306bd34e214e609ab0c93e61fc0b92c5df5b745 Mon Sep 17 00:00:00 2001 From: Adrian Pop Date: Mon, 25 Mar 2024 19:34:16 +0100 Subject: [PATCH] log even more (#84) --- test.py | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/test.py b/test.py index c84b2b2..1bcf9d8 100755 --- a/test.py +++ b/test.py @@ -84,20 +84,30 @@ if not pythonExecutable: pythonExecutable = "python" +def fflush(): + sys.stdout.flush() + sys.stderr.flush() def check_output_log(*popenargs, **kwargs): if DEBUG: + fflush() print("run: check_output", popenargs, kwargs) print("\n") return subprocess.check_output(*popenargs, **kwargs) +def check_call_log(*popenargs, **kwargs): + if DEBUG: + fflush() + print("run: check_call", popenargs, kwargs) + print("\n") + return subprocess.check_call(*popenargs, **kwargs) def rmtree(f): try: shutil.rmtree(f) except UnicodeDecodeError: # Yes, we can get UnicodeDecodeError because shutil.rmtree is poorly implemented - subprocess.check_call(["rm", "-rf", f], stderr=subprocess.STDOUT) + check_call_log(["rm", "-rf", f], stderr=subprocess.STDOUT) def print_linenum(signum, frame): print("Currently at line", frame.f_lineno) @@ -108,6 +118,9 @@ def print_linenum(signum, frame): def runCommand(cmd, prefix, timeout): process = [None] def target(): + if DEBUG: + fflush() + print("run: Popen %s, %s, %d\n" %(cmd, prefix, timeout)) with open(os.devnull, 'w') as FNULL: if isWin: process[0] = subprocess.Popen(cmd, shell=True, stdin=FNULL, stdout=FNULL, stderr=FNULL) @@ -407,9 +420,9 @@ def testHelloWorld(cmd): if "git-directory" in c["referenceFiles"]: # Sparse clone os.makedirs(destination) - subprocess.check_call(["git", "init"], stderr=subprocess.STDOUT, cwd=destinationReal) - subprocess.check_call(["git", "remote", "add", "-f", "origin", giturl], stderr=subprocess.STDOUT, cwd=destinationReal) - subprocess.check_call(["git", "config", "core.sparseCheckout", "true"], stderr=subprocess.STDOUT, cwd=destinationReal) + check_call_log(["git", "init"], stderr=subprocess.STDOUT, cwd=destinationReal) + check_call_log(["git", "remote", "add", "-f", "origin", giturl], stderr=subprocess.STDOUT, cwd=destinationReal) + check_call_log(["git", "config", "core.sparseCheckout", "true"], stderr=subprocess.STDOUT, cwd=destinationReal) file = open(os.path.join(destinationReal,".git", "info", "sparse-checkout"), "a") file.write(c["referenceFiles"]["git-directory"].strip()) file.close() @@ -417,18 +430,18 @@ def testHelloWorld(cmd): refFilesGitTag = 'origin/%s' % refFilesGitTag else: # Clone - subprocess.check_call(["git", "clone", giturl, destination], stderr=subprocess.STDOUT) + check_call_log(["git", "clone", giturl, destination], stderr=subprocess.STDOUT) - subprocess.check_call(["git", "clean", "-fdx", "--exclude=*.hash"], stderr=subprocess.STDOUT, cwd=destinationReal) - subprocess.check_call(["git", "fetch", "origin"], stderr=subprocess.STDOUT, cwd=destination) + check_call_log(["git", "clean", "-fdx", "--exclude=*.hash"], stderr=subprocess.STDOUT, cwd=destinationReal) + check_call_log(["git", "fetch", "origin"], stderr=subprocess.STDOUT, cwd=destination) # do not fail if the branch we were given doesn't exist try: - subprocess.check_call(["git", "reset", "--hard", refFilesGitTag], stderr=subprocess.STDOUT, cwd=destinationReal) + check_call_log(["git", "reset", "--hard", refFilesGitTag], stderr=subprocess.STDOUT, cwd=destinationReal) except subprocess.CalledProcessError as e: print(e.output) - subprocess.check_call(["git", "clean", "-fdx", "--exclude=*.hash"], stderr=subprocess.STDOUT, cwd=destinationReal) + check_call_log(["git", "clean", "-fdx", "--exclude=*.hash"], stderr=subprocess.STDOUT, cwd=destinationReal) if glob.glob(destinationReal + "/*.mat.xz"): - subprocess.check_call(["find", ".", "-name", "*.mat.xz", "-exec", "xz", "--decompress", "--keep", "{}", ";"], stderr=subprocess.STDOUT, cwd=destinationReal) + check_call_log(["find", ".", "-name", "*.mat.xz", "-exec", "xz", "--decompress", "--keep", "{}", ";"], stderr=subprocess.STDOUT, cwd=destinationReal) try: githash = check_output_log(["git", "rev-parse", "--verify", "HEAD"], stderr=subprocess.STDOUT, cwd=destinationReal, encoding='utf8') except subprocess.CalledProcessError as e: @@ -591,7 +604,7 @@ def hashReferenceFiles(s): # replace the resource location in the command if present cmd = [c.replace("$resourceLocation", conf["resourceLocation"]) for c in cmd] cmd = [c.replace("$libraryLocation", conf["libraryLocation"]) for c in cmd] - subprocess.check_call(cmd, stderr=subprocess.STDOUT) + check_call_log(cmd, stderr=subprocess.STDOUT) if "customCommands" in conf: cmd = conf["customCommands"]