def update(self): if(self.jobId != None): res = execCmd("qstat " + self.jobId, True) if(res.result == 0): if(len(res.stdout) < 2): raise Exception("Unexpected output from qstat: " + str(res.stdout)) jobStatus = res.stdout[-1].split() if(len(jobStatus) != 6): raise Exception("Unexpected output from qstat: " + str(res.stdout)) jobState = jobStatus[4] if(jobState == "C" or jobState == "E"): self.isWaiting = False self.isFinished = True elif(jobState == "R" or jobState == "T"): self.isWaiting = False self.isFinished = False elif(jobState == "W" or jobState == "Q"): self.isWaiting = True self.isFinished = False else: raise Exception("Invalid job state: " + jobState) elif("Unknown Job Id" in res.stderr[-1]): self.isWaiting = False self.isFinished = True else: raise Exception("Failed to execute qstat: " + str(res.stdout) + "\n" + str(res.stderr))
def __execCmds(self, preRunOrPostRun, compilation, dryRun, verbose): """Execute pre- or post-run commands' Return error result or None on success """ if preRunOrPostRun: cmds = self.preRunCmds runDir = compilation.getInstallPath() descr = "pre-run" else: cmds = self.postRunCmds runDir = self.lastOutputPath descr = "post-run" if cmds: with (cd(runDir if not dryRun else ".")): cprint( "Executing " + descr + " commands for " + self.name + "...", "yellow") envSetupCmd = self.getSetupCmd(compilation, dryRun) if verbose: print("Environment: " + envSetupCmd) for cmd in cmds: if dryRun or verbose: print(cmd) if not dryRun: result = execCmd(envSetupCmd + cmd) if (result.result != 0): return result.result return None
def __submit(self, compilation, outputDir, dryRun=False, verbose=False): """Submit test to tbg""" if (os.path.isdir(outputDir)): shutil.rmtree(outputDir) tbgCmd = "tbg -t -s" if (self.profileFile): tbgCmd += " -o 'TBG_profile_file='" + self.profileFile + "'" tbgCmd += " -c submit/" + self.cfgFile + " " + outputDir cprint( "Submitting " + self.getConfig()[0] + "/" + self.name + " to queue", "yellow") if dryRun or verbose: tbgVars = "TBG_SUBMIT=" + os.environ.get( "TBG_SUBMIT") + " TBG_TPLFILE=" + os.environ.get("TBG_TPLFILE") print(tbgVars + " " + tbgCmd) if dryRun: self.monitor = None else: res = execCmd(self.getSetupCmd(compilation, dryRun) + tbgCmd) if (res.result != 0): cprint("Submit or execution failed!", "red") return res.result self.monitor = statusMonitors.GetMonitor(os.environ['TBG_SUBMIT'], res.stdout, res.stderr) return 0
def compile(self, dryRun, verbose, silent): """Compile the example (after configuring) dryRun -- Only print the commands silent -- Do not print progress to stdout Return None for dryRuns or the result tuple from execCmd (result, stdout, stderr) """ setupCmd = self.getSetupCmd() cmd = 'cd "' + self.getBuildPath() + '"\n' cmd += 'make install' if dryRun or verbose: print(cmd) if dryRun: return None else: result = execCmd(setupCmd + cmd, silent) if result != None and result.result == 0: # Write used cmake flags to file with open( os.path.join(self.getInstallPath(), "cmakeFlags.txt"), 'w') as f: flags = self.example.getCMakeFlags()[self.cmakePreset] flags = flags.replace(";", "\n") flags = flags.replace(" ", "\n") f.write(flags) return result
def __queryCMakeFlags(self, addCMakeFlags): """Return a list of CMake flag strings as returned by the cmakeFlags shell script""" result = execCmd(self.folder + "/cmakeFlags -ll", True) if (result.result != 0): raise Exception("Could not get cmakeFlags: " + "\n".join(result.stderr)) else: result = [x for x in result.stdout if x.startswith('-D')] if addCMakeFlags and len(addCMakeFlags) > 0: addCMakeFlags = " ".join(addCMakeFlags) if len(result) == 0: return [addCMakeFlags] else: return [flags + " " + addCMakeFlags for flags in result] else: return result
def configure(self, pathToCMakeLists, dryRun, verbose, silent): """Configure the example via CMake pathToCMakeLists -- Folder that contains the CMakeLists.txt dryRun -- Only print the commands silent -- Do not print progress to stdout Return None for dryRuns or the result tuple from execCmd (result, stdout, stderr) """ buildPath = self.getBuildPath() setupCmd = self.getSetupCmd() cmd = 'mkdir -p "' + buildPath + '" && cd "' + buildPath + '"\n' cmd += "cmake" cmd += " " + self.example.getCMakeFlags()[self.cmakePreset].replace( ";", "\\;") cmd += ' -DPARATAXIS_EXTENSION_PATH="' + self.example.getFolder() + '"' cmd += ' -DCMAKE_INSTALL_PREFIX="' + self.getInstallPath() + '"' cmd += ' "' + pathToCMakeLists + '"' if dryRun or verbose: print(cmd) if dryRun: return None else: return execCmd(setupCmd + cmd, silent)
def update(self): if(self.jobId != None): res = execCmd("squeue -o \"JobState=%T\" -j " + self.jobId, True) if(res.result == 0): self.timeoutCt = 0 if(len(res.stdout) != 2): if len(res.stdout) == 1 and res.stdout[0] == "JobState=STATE": self.isWaiting = False self.isFinished = True else: raise Exception("Unexpected output from squeue: " + str(res.stdout)) return jobStatRegExp = "JobState=(\w+)" jobState = re.match(jobStatRegExp, res.stdout[-1]) if not jobState: raise Exception("Unexpected output from squeue: " + str(res.stdout)) jobState = jobState.group(1) if(jobState == "CANCELLED" or jobState == "FAILED" or jobState == "COMPLETED" or jobState == "TIMEOUT" or jobState == "PREEMPTED" or jobState == "NODE_FAIL" or jobState == "SPECIAL_EXIT"): self.isWaiting = False self.isFinished = True elif(jobState == "RUNNING" or jobState == "COMPLETING"): self.isWaiting = False self.isFinished = False elif(jobState == "PENDING" or jobState == "SUSPENDED" or jobState == "CONFIGURING"): self.isWaiting = True self.isFinished = False else: raise Exception("Invalid job state: " + jobState) elif("Invalid job id specified" in res.stderr[-1]): self.isWaiting = False self.isFinished = True elif("Socket timed out" in res.stderr[-1]): self.timeoutCt += 1 if(self.timeoutCt > 50): raise Exception("Timeout for squeue: " + str(res.stdout) + "\n" + str(res.stderr)) else: raise Exception("Failed to execute squeue(" + str(res.result) + "): " + str(res.stdout) + "\n" + str(res.stderr))