def write_file(self,p,txt, show=True, wr=False, check=True, backup=True) : txt = txt.split('\n') just ="Just" if wr : just = "Also" if backup and exist(p) : i = 1; while True : pi = p+'.'+str(i)+'.bak' if not(exist(pi)) : break i += 1 print("backing to %s"% pi) shutil.copy(p,pi) print "writing to %s"%p write(p,txt,check) if p[-4:]=='.cpp' : p1 = os.path.join(os.path.split(p)[0],'CMakeLists.txt') addline=Add_line(p1,self.name) addline.update_file("SET\( *SOURCES") if show : print("%s showing text of %s for %s-test"% (just,os.path.split(p)[1],self.mode)) print("<"+"="*40) PrettyPrinter().pprint(txt) print("="*40+">")
def write_unit(self, fct_name, mode, part, s) : def test_immutable(p) : s= '\n'.join(read(p)) return s.find('//COMMENTED') != -1 nfp = Nt2_fct_props(self.tb_name,fct_name,mode) p = nfp.get_fct_unit_path(mode,part) if exist(os.path.split(p)[0]) : if self.verbose : print ('path = %s'%p) print("---%s"%exist(p)) if exist(p) and test_immutable(p) : print("%s has been marked as immutable"%p ) return if self.backup_on_write and exist(p) : if self.verbose : print("backing up %s" %fct_name) i = 1; while True : pi = p+'.'+str(i)+'.bak' if not(exist(pi)) : break i += 1 if self.verbose : print("to %s"% pi) shutil.copy(p,pi) elif self.verbose : print "writing to %s"%p write(p,s,self.check_on_write) p1 = os.path.join(os.path.split(p)[0],'CMakeLists.txt') addline=Add_line(p1,fct_name) addline.update_file("SET\( *SOURCES") elif self.verbose : print("%s directory\n does not exist " %os.path.split(p)[0])
def write_unit(self, fct_name, mode, part, s): def test_immutable(p): s = '\n'.join(read(p)) return s.find('//COMMENTED') != -1 nfp = Nt2_fct_props(self.tb_name, fct_name, mode) p = nfp.get_fct_unit_path(mode, part) if exist(os.path.split(p)[0]): if self.verbose: print('path = %s' % p) print("---%s" % exist(p)) if exist(p) and test_immutable(p): print("%s has been marked as immutable" % p) return if self.backup_on_write and exist(p): if self.verbose: print("backing up %s" % fct_name) i = 1 while True: pi = p + '.' + str(i) + '.bak' if not (exist(pi)): break i += 1 if self.verbose: print("to %s" % pi) shutil.copy(p, pi) elif self.verbose: print "writing to %s" % p write(p, s, self.check_on_write) p1 = os.path.join(os.path.split(p)[0], 'CMakeLists.txt') addline = Add_line(p1, fct_name) addline.update_file("SET\( *SOURCES") elif self.verbose: print("%s directory\n does not exist " % os.path.split(p)[0])
def write_file(self, p, txt, show=True, wr=False, check=True, backup=True): txt = txt.split('\n') just = "Just" if wr: just = "Also" if backup and exist(p): i = 1 while True: pi = p + '.' + str(i) + '.bak' if not (exist(pi)): break i += 1 print("backing to %s" % pi) shutil.copy(p, pi) print "writing to %s" % p write(p, txt, check) if p[-4:] == '.cpp': p1 = os.path.join(os.path.split(p)[0], 'CMakeLists.txt') addline = Add_line(p1, self.name) addline.update_file("SET\( *SOURCES") if show: print("%s showing text of %s for %s-test" % (just, os.path.split(p)[1], self.mode)) print("<" + "=" * 40) PrettyPrinter().pprint(txt) print("=" * 40 + ">")
def write_exhaustive(tb_name,fct_name,mode,s,check=False,backup=True) : nfp = Nt2_fct_props(tb_name,fct_name,mode) print("mode %s"%mode) p = nfp.get_fct_exhaustive_path(mode) print ('p = %s'%p) if backup and exist(p) : ## print("p=%s" %p) i = 1; while True : pi = p+'.'+str(i)+'.bak' if not(exist(pi)) : break i += 1 print("backing to %s"% pi) shutil.copy(p,pi) print "writing to %s"%p write(p,s,check) p1 = os.path.join(os.path.split(p)[0],'CMakeLists.txt') addline=Add_line(p1,fct_name) addline.update_file("SET\( *SOURCES")
def write_unit(self, fct_name, mode, part, s) : nfp = Nt2_fct_props(self.tb_name,fct_name,mode) p = nfp.get_fct_unit_path(mode,part) if self.verbose : print ('path = %s'%p) if self.backup_on_write and exist(p) : if self.verbose : print("backing up %s" %fct_name) i = 1; while True : pi = p+'.'+str(i)+'.bak' if not(exist(pi)) : break i += 1 if self.verbose : print("to %s"% pi) shutil.copy(p,pi) elif self.verbose : print "writing to %s"%p write(p,s,self.check_on_write) p1 = os.path.join(os.path.split(p)[0],'CMakeLists.txt') addline=Add_line(p1,fct_name) addline.update_file("SET\( SOURCES")