def write(self,p,name,txt) : if self.show : show(txt) self.p =p self.name = name self.txt = txt if isinstance(p,str) and exist(self.p) : ## if self.verbose : print ('path = %s'%self.p) tp = os.path.join(self.p,self.name) if exist(tp) : if not self.write_files : return False if self.backup_on_write and exist(tp) : if self.verbose : print("backing up %s" %name) i = 1; while True : tpi = tp+'.'+str(i)+'.bak' if not(exist(tpi)) : break i += 1 if self.verbose : print("to %s"% tpi) shutil.copy(tp,tpi) elif not self.write_files : print "%s is not written"%tp return False if self.verbose : print "writing to %s"%tp if write(tp,self.txt,self.check_on_write) : print "%s is written"%tp return True; elif self.verbose and isinstance(p,str) : print("%s directory\n does not exist " %os.path.split(p)[0]) else : print("no path found") return False
def show_new_fctor(self) : new = self.compose_new_fctor_txt() if type(new) is str : print "%s %s" % (self.fcti.get_fct_name(),new) else : print "showing %s" % self.fcti.get_fct_path() show(new)
if __name__ == "__main__": from display_utils import show inner_text = [ "", "SET( SOURCES", "# List of files for toolbox %s"% "gmp", " )", "", "##****************************************************************************", "# For each filename", "##****************************************************************************", "FOREACH( EXAMPLE ${SOURCES})", " ##**************************************************************************", " ## Build the executable filename from the example source filename", " ##**************************************************************************", ' STRING(REGEX REPLACE ".cpp" ".%s.scalar.bench" EXECUTABLE "${EXAMPLE}")'%("gmp",), ' STRING(REGEX REPLACE ".cpp" "-%s.scalar.bench" TEST "${EXAMPLE}")'%("gmp",), "", " ##**************************************************************************", " ## Add as a target", " ##**************************************************************************", " ADD_EXECUTABLE(${EXECUTABLE} ${EXAMPLE})", " TARGET_LINK_LIBRARIES(${EXECUTABLE} nt2)", " ADD_TEST(${TEST} ${CMAKE_CURRENT_BINARY_DIR}/${EXECUTABLE})", "ENDFOREACH()", ] l=sub_if_match_list(" *##", "\*", "#", inner_text) show(l)
else : shutil.move(self.fcti.get_fct_path(),re.sub('.hpp','.bak',self.fcti.get_fct_path())) write(self.fcti.get_fct_path(),new,True) print "done" def revert_to_old_fctor(self) : if self.fcti.is_already_revised() : if self.fcti.no_restore() : print "no restore allowed for %s" % self.fcti.get_fct_path() return bak = re.sub('.hpp','.bak',self.fcti.get_fct_path()) if exist(bak) : print "reverting %s" % self.fcti.get_fct_path() shutil.move(bak,self.fcti.get_fct_path()) else : print "no bak file for reverting %s" % self.fcti.get_fct_path() else : print "file %s is not already revised" % self.fcti.get_fct_path() if __name__ == "__main__" : print __doc__ from nt2_tb_functors_infos import Fctor_infos fi = Fctor_infos("arithmetic","abs","simd/sse","ssse3") mf = Mk_fctor(fi) print"old=================" show(fi.get_old_fctor_txt()) print"new=================" show(mf.compose_new_fctor_txt()) # mf.save_new_fctor()
def write_unit(tb_name,fct_name,mode,s,check=False) : nfp = Nt2_fct_props(tb_name,fct_name,mode) p = nfp.get_fct_unit_path(mode) print "write to %s"%p show(s) write(p,s,check)
def show_unit_txt(self) : show(self.create_unit_txt())
if __name__ == "__main__": from display_utils import show inner_text = [ "", "SET( SOURCES", "# List of files for toolbox %s" % "gmp", " )", "", "##****************************************************************************", "# For each filename", "##****************************************************************************", "FOREACH( EXAMPLE ${SOURCES})", " ##**************************************************************************", " ## Build the executable filename from the example source filename", " ##**************************************************************************", ' STRING(REGEX REPLACE ".cpp" ".%s.scalar.bench" EXECUTABLE "${EXAMPLE}")' % ("gmp", ), ' STRING(REGEX REPLACE ".cpp" "-%s.scalar.bench" TEST "${EXAMPLE}")' % ("gmp", ), "", " ##**************************************************************************", " ## Add as a target", " ##**************************************************************************", " ADD_EXECUTABLE(${EXECUTABLE} ${EXAMPLE})", " TARGET_LINK_LIBRARIES(${EXECUTABLE} nt2)", " ADD_TEST(${TEST} ${CMAKE_CURRENT_BINARY_DIR}/${EXECUTABLE})", "ENDFOREACH()", ] l = sub_if_match_list(" *##", "\*", "#", inner_text) show(l)
def write_unit(tb_name, fct_name, mode, s, check=False): nfp = Nt2_fct_props(tb_name, fct_name, mode) p = nfp.get_fct_unit_path(mode) print "write to %s" % p show(s) write(p, s, check)