Skip to content

Commit

Permalink
log even more (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
adrpo committed Mar 25, 2024
1 parent 5d65dc5 commit d306bd3
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions test.py
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -407,28 +420,28 @@ 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()
# add orgin to the git-ref tag
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:
Expand Down Expand Up @@ -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"]
Expand Down

0 comments on commit d306bd3

Please sign in to comment.