def logHasError(self,job,fdir='.'): # NOTE: Make sure to check that the job exists before calling this fcn if not self.isJob(job): return False fn = os.path.join(fdir,job + '.log') rgx = 'Error when reading.*' ret = run_process(['grep','-l','-e',rgx,fn],verbose=False) return bool(ret)
def checkProgress(self,lines=5): for fn in sorted(self.intg_full,key=self.getIntegrateTime): log_file = os.path.join(self.fdir,"%s.log" % (fn)) if not os.path.exists(log_file): continue t = self.getLastModifiedTime("%s_scanpoints.txt" % (fn)) h,m,s = self.formatTime(t) tot_tstr = "[%s:%s:%s]" % (h.rjust(2,"0"),m.rjust(2,"0"),s.rjust(2,"0")) t = self.getIntegrateTime(fn) h,m,s = self.formatTime(t) int_tstr = "[%s:%s:%s]" % (h.rjust(2,"0"),m.rjust(2,"0"),s.rjust(2,"0")) t = self.getLastModifiedTime(log_file) h,m,s = self.formatTime(t) mod_tstr = "[%s:%s:%s]" % (h.rjust(2,"0"),m.rjust(2,"0"),s.rjust(2,"0")) #print "\nChecking: %s - %s - %s" % (fn,int_tstr,mod_tstr) #print "\nChecking: %s - Total %s - Intg %s - LogMod %s" % (fn,tot_tstr,int_tstr,mod_tstr) print "\nChecking: %s - %s - %s - %s" % (fn,tot_tstr,int_tstr,mod_tstr) run_process(['tail','-n%d' % (lines),log_file])
def failedCodegen(self,job,fdir='.'): if not self.isJob(job): return False fn = os.path.join(fdir,job + '.log') if not os.path.exists(fn): return False rgx = '^Process output directory %s not found\.' % (job) ret = run_process(['grep','-l','-e',rgx,fn],verbose=False) return bool(ret)
def save(self, dst, force=False): self.copy(dst, force=force) for k in self.list(): v = self.getOption(k) old = self.__line_map[k] repl = " {0:>{w1}} = {1:<{w2}} {eol}".format(v, k, w1=self.val_width, w2=self.key_width, eol=self.EOL_COMMENT) pat = r".*=\s*%s\s*[!#]?" % (k) new = re.sub(pat, repl, old) # Need to escape any special chars otherwise sed won't match the line old = old.replace('\\', '\\\\').replace('*', '\\*') new = new.replace('\\', '\\\\').replace('*', '\\*') #print "{old:<{w}} --> {new}".format(old=old,new=new,w=self.line_width) sed_cmd = "s|{old}|{new}|g".format(old=old, new=new) run_process(['sed', '-i', '-e', sed_cmd, dst])
def logHasXsec(self,job,fdir='.'): # NOTE: Make sure to check that the job exists before calling this fcn fn = os.path.join(fdir,job + '.log') rgx = 'Cross-section : ' ret = run_process(['grep','-l','-e',rgx,fn],verbose=False) return bool(ret)