46 Check file exist or not. 48 msg =
" already exists. Overwrite or merge? (y/n/m)" 49 if (os.access(fname, os.F_OK)):
50 ans = raw_input(
"\"" + fname +
"\"" + msg)
51 if (ans ==
"y" or ans ==
"Y"):
52 return file(fname,
"w"),
None 53 elif (ans ==
"m" or ans ==
"M"):
56 for l
in f.readlines():
57 lines.append(l.rstrip())
59 oldfname = fname +
".old." + time.strftime(
"%y%m%d%H%M%S")
60 os.rename(fname, oldfname)
61 return file(fname,
"w"), lines
65 return file(fname,
"w"),
None 74 m = re.search(
"<rtc-template block=\"(.*?)\">", l)
81 m = re.search(
"</rtc-template>", l)
84 if data.has_key(tag_name):
85 ret_lines += data[tag_name] +
"\n" 97 for key
in tags.keys():
98 s = StringIO.StringIO()
101 t.generate(s, self.data)
102 tags[key] = s.getvalue()
105 def gen(self, fname, temp_txt, data, tags):
111 s = StringIO.StringIO()
115 taged_txt = s.getvalue().splitlines()
123 print " File \"" + fname +
"\"" " was generated." 128 if __name__ ==
"__main__":
131 // <rtc-template block="inport_declar"> 134 // <rtc-template block="outport_declar"> 137 data = {
"inport_declar":
" hoge;\n dara;\n munya;",
138 "outport_declar":
" 1;\n 2;\n 3;"}
140 print g.replace_tags(hoge.splitlines(), data)
def gen(self, fname, temp_txt, data, tags)
def check_overwrite(self, fname)
def replace_tags(self, lines, data)