def create_gen_sh(self, dict): fname = dict["name"] + "/gen.sh" fd = open(fname, "w") head = yat.Template(sh_header).generate(dict) body = yat.Template(gen_main).generate(dict) body = self.add_cmark(body, "\\") foot = yat.Template(sh_footer).generate(dict) sh_all = head + body + foot fd.write(sh_all) fd.close() os.chmod(fname, 0755)
def create_gen_bat(self, dict): fname = dict["name"] + "/gen.bat" fd = open(fname, "w") head = yat.Template(bat_header).generate(dict) body = yat.Template(gen_main).generate(dict) body = body.replace("rtc-template", "rtc-template.py") body = self.add_cmark(body, "^") foot = yat.Template(bat_footer).generate(dict) bat_all = head + body + foot bat_all.replace("\r\n", "\n").replace("\n", "\r\n") fd.write(bat_all) fd.close() os.chmod(fname, 0755)
def gen(self, fname, temp_txt): data = self.data t = yat.Template(temp_txt) text = t.generate(data) if os.access(fname, os.F_OK): # file exists f = file(fname, "r") oldtext = f.read() f.close() newtext = re.sub(" \@date.*?\n", "", text) oldtext2 = re.sub(" \@date.*?\n", "", oldtext) if newtext == oldtext2: print "\"" + fname + \ "\" exists and contents is same." print "No need to generate the file." return else: print "\"", fname, \ "\" already exists but contents are not same" f = file(fname, "w") f.write(text) f.close() print "\"" + fname + "\"" " was generated." return
def gen(self, fname, temp_txt, data): t = yat.Template(temp_txt) text = t.generate(data) if os.access(fname, os.F_OK): # file exists f = file(fname, "r") oldtext = f.read() f.close() newtext = re.sub(" \@date.*?\n", "", text) oldtext2 = re.sub(" \@date.*?\n", "", oldtext) if newtext == oldtext2: print "\"", fname, \ "\" already exists and it will be same as new one." print "File is not need to be generated." return else: print "\"", fname, "\" already exists but contents are not same" f = file(fname, "w") f.write(text) f.close() print "\"", fname, "\"" " was generated." return
def gen_solution(version, yaml_text): dict = yaml.load(yaml_text) t = yat.Template(sln_template % (vcversions[version]["sln"], vcversions[version]["vc"])) return t.generate(dict).replace("\r\n", "\n").replace("\n", "\r\n")
def gen(self, fname, temp_txt, data): f = file(fname, "w") t = yat.Template(temp_txt) #t.parse(temp_txt) text=t.generate(data) f.write(text) f.close() print("\"", fname, "\"" " was generated.") return
def gen(self, fname, temp_txt, data): fd = self.check_overwrite(fname) if not fd: return t = yat.Template(temp_txt) text = t.generate(data) fd.write(text) fd.close() print "\"" + fname + "\"" " was generated." return
def gen(self, fname, temp_txt, data): f = file(fname, "w") # s = StringIO.StringIO() t = yat.Template(temp_txt) text = t.generate(data) # gen_txt = s.getvalue().splitlines() # f.write(gen_txt) f.write(text) f.close() print "\"", fname, "\"" " was generated." return
def craete_build_sh(self): dict = {} dict["projects"] = self.pjnames builds = {"build.sh": build_sh, "build_vc8.bat": build_vc8_bat, "build_vc9.bat": build_vc9_bat } for key in builds.keys(): fd = open(key, "w") fd.write(yat.Template(builds[key]).generate(dict)) fd.close() os.chmod(key, 0755)
def gen(self, fname, temp_txt, data, tags): f, lines = self.check_overwrite(fname) if not f: # overwrite: No return if not lines: # overwrite: Yes t = yat.Template(temp_txt) taged_txt = t.generate(self.data) else: # overwrite: Merge mode taged_txt = lines # replace tags gen_txt = self.replace_tags(taged_txt.split("\n"), tags) f.write(gen_txt) f.close() print(" File \"" + fname + "\"" " was generated.") return
def gen_tags(self, tags): for key in tags.keys(): t = yat.Template(tags[key]) text = t.generate(self.data) tags[key] = text return
def load_template(self, template): fd = open(template, 'r') t = yat.Template(fd.read(), "{% ", " %}") fd.close() return t
def generate(self): import yat self.template = yat.Template(self.get_template(self.type)) return self.template.generate(self.dict).replace("\r\n", "\n").replace( "\n", "\r\n")
dict["omniorb_include_dirs"] = dict["omni_includes"] dict["omniorb_ldflags"] = "" dict["omniorb_library_dirs"] = dict["omni_libdir"] dict["omniorb_libraries"] = omni_libs dict["omniorb_version"] = str(dict["omni_version"]) dict["openrtm_cflags"] = rtm_cflags dict["openrtm_include_dirs"] = str(dict["rtm_includes"]) dict["openrtm_ldflags"] = "" dict["openrtm_lib_dirs"] = str("${OPENRTM_BIN_PATH};" + dict["omni_libdir"]) dict["openrtm_libs"] = str(rtm_libs) dict["coil_include_dir"] = str(dict["rtm_libdir"]) dict["openrtm_version"] = str(dict["rtm_version"]) dict["openrtm_version_major"] = str(dict["rtm_version"].split(".")[0]) dict["openrtm_version_minor"] = str(dict["rtm_version"].split(".")[1]) dict["openrtm_version_patch"] = str(dict["rtm_version"].split(".")[2]) dict["openrtm_short_version"] = str(dict["rtm_version"].replace(".", "")) dict["openrtm_orb"] = "omniORB" dict["openrtm_idl_wrapper"] = "rtm-skelwrapper.py" dict[ "openrtm_idl_wrapper_flags"] = '--include-dir="";--skel-suffix=Skel;--stub-suffix=Stub' dict["openrtm_idlc"] = "omniidl" dict[ "openrtm_idlflags"] = "-bcxx;-Wba;-nf;-Wbshortcut;-I${OPENRTM_DIR}/rtm/idl" t = yat.Template(template) f = file("OpenRTMConfig.cmake", "w") f.write(t.generate(dict)) f.close()