def run(self,pretend=False,envup=None,env=None,strace=None,stdout=None,pfileschroot=True,quiet=False): log(bcolors.render("{YEL} work dir to "+self.cwd+"{/}")) owd=get_cwd() os.chdir(self.cwd) log(bcolors.render("{YEL}"+str([self.toolname]+self.pars.mkargs())+"{/}")) log(bcolors.render("{YEL}"+" ".join([self.toolname]+self.pars.mkargs(quote=True))+"{/}")) if pretend: log("not actually running it") return if env is None: env=self.environ if envup is not None: env.update(envup) if strace is not None: tr=["strace"] else: tr=[] env['HEADASPROMPT']="/dev/null" if pfileschroot: log("requested to create temporary user pfiles directory") pfiles_user_temp=tempfile.mkdtemp(os.path.basename(self.pars.pfile)) pf_env=dict(PFILES=pfiles_user_temp+";"+os.path.dirname(self.pars.pfile)) else: pf_env=dict(PFILES=os.path.dirname(self.pars.pfile)) # how did this even work?.. log("setting PFILES to",pf_env['PFILES']) pr=subprocess.Popen(tr+[self.toolname]+self.pars.mkargs(),env=dict(env.items()+pf_env.items()),stdout=subprocess.PIPE,stderr=subprocess.STDOUT, bufsize=0 ) # separate?.. all_output="" if not quiet: while True: line = pr.stdout.readline() if not line: break log(line.strip(),logtype="info") all_output+=line self.output=all_output pr.wait() if pfileschroot: for tupfile in glob.glob(pfiles_user_temp+"/*.par"): os.remove(tupfile) os.rmdir(pfiles_user_temp) os.chdir(owd) if pr.returncode!=0: raise HEAToolException(self.toolname,pr.returncode) return
def converttime(inpf, inp, outpf, rbp): print((bcolors.render("{RED}converttime{/} using {BLUE}" + str(rbp) + "{/}"))) env = os.environ.copy() env['REP_BASE_PROD'] = rbp env['PFILES'] = env['HOME'] + "/pfiles;" + env['ISDC_ENV'] + "/pfiles" inps = "%.30lg" % inp if isinstance(inp, float) else str(inp) c = ["converttime", inpf, inps, outpf, "accflag=10"] print(("command:", " ".join(c))) try: pr = subprocess.check_output(c, env=env).decode() except subprocess.CalledProcessError as e: if re.search("DAL3GEN_INVALID_.*?_TIME", e.output.decode()): print(("failed bad time:", e)) raise BadTimeFormat("bad time content: " + repr(inp) + " as " + repr(inpf)) print(("called process failed, raising:", e)) raise e except Exception as e: print(("failed:", e)) raise e print(pr) r = re.search("Output Time\(%s\):(.*)" % outpf, pr) outt = r.groups(0)[0].strip() if outpf == "SCWID" and outt == "000000000000.000": raise Exception("conversion failed") return outt
def __repr__(self): return bcolors.render("{BLUE}%s{/} == {YEL}%s{/} (%s)" % (self.name, repr(self.value), self.prompt))
def __repr__(self): return bcolors.render("{GREEN}%s{/}:\n"%self.toolname)+repr(self.pars)
def test_upper(self): import bcolors print bcolors.render("{RED}RED!{/}")