[openrtm-commit:00110] r2139 - in branches/RELENG_1_1/OpenRTM-aist: build utils/rtm-skelwrapper

openrtm @ openrtm.org openrtm @ openrtm.org
2011年 5月 26日 (木) 22:52:33 JST


Author: n-ando
Date: 2011-05-26 22:52:32 +0900 (Thu, 26 May 2011)
New Revision: 2139

Modified:
   branches/RELENG_1_1/OpenRTM-aist/build/makewrapper.py
   branches/RELENG_1_1/OpenRTM-aist/utils/rtm-skelwrapper/skel_wrapper.py
Log:
Now makewrapper and rtm-skelwrapper check existing files and its contents
to avoid same file regeneration.


Modified: branches/RELENG_1_1/OpenRTM-aist/build/makewrapper.py
===================================================================
--- branches/RELENG_1_1/OpenRTM-aist/build/makewrapper.py	2011-05-24 05:31:54 UTC (rev 2138)
+++ branches/RELENG_1_1/OpenRTM-aist/build/makewrapper.py	2011-05-26 13:52:32 UTC (rev 2139)
@@ -4,9 +4,8 @@
 # @date $Date: 2008-02-29 04:50:39 $
 # @author Norkai Ando <n-ando at aist.go.jp>
 #
-# Copyright (C) 2005-2006
+# Copyright (C) 2005-2011
 #     Noriaki Ando
-#     Task-intelligence Research Group,
 #     Intelligent Systems Research Institute,
 #     National Institute of
 #         Advanced Industrial Science and Technology (AIST), Japan
@@ -251,12 +250,26 @@
         self.data = data
 
     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")
-        #		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."

Modified: branches/RELENG_1_1/OpenRTM-aist/utils/rtm-skelwrapper/skel_wrapper.py
===================================================================
--- branches/RELENG_1_1/OpenRTM-aist/utils/rtm-skelwrapper/skel_wrapper.py	2011-05-24 05:31:54 UTC (rev 2138)
+++ branches/RELENG_1_1/OpenRTM-aist/utils/rtm-skelwrapper/skel_wrapper.py	2011-05-26 13:52:32 UTC (rev 2139)
@@ -6,8 +6,7 @@
 #  @date $Date: 2008-03-06 06:51:10 $
 #  @author Noriaki Ando <n-ando at aist.go.jp>
 # 
-#  Copyright (C) 2004-2007
-#      Task-intelligence Research Group,
+#  Copyright (C) 2004-2011
 #      Intelligent Systems Research Institute,
 #      National Institute of
 #          Advanced Industrial Science and Technology (AIST), Japan
@@ -247,43 +246,53 @@
 			self.data["include_openrtm_idl_decls"] = ""
 		else:
 			self.data["include_openrtm_idl_decls"] = "#  include \"OpenRTM-aist-decls.h\"\n"
-		
 		return
 
-	def print_skel_h(self):
-		f = file(self.data["output_dir"] + self.data["skel_h"], "w")
-		t = yat.Template(skel_h)
-		text=t.generate(self.data)
+	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 self.data["skel_h"], " was generated."
+		print "\"" + fname + "\"" " was generated."
 		return
 
+	def print_skel_h(self):
+		fname = self.data["output_dir"] + self.data["skel_h"]
+		self.gen(fname, skel_h)
+		return
+
 	def print_skel_cpp(self):
-		f = file(self.data["output_dir"] + self.data["skel_cpp"], "w")
-		t = yat.Template(skel_cpp)
-		text=t.generate(self.data)
-                f.write(text)
-                f.close()
-		print self.data["skel_cpp"], " was generated."
+		fname = self.data["output_dir"] + self.data["skel_cpp"]
+		self.gen(fname, skel_cpp)
 		return
 
 	def print_stub_h(self):
-		f = file(self.data["output_dir"] + self.data["stub_h"], "w")
-		t = yat.Template(stub_h)
-		text=t.generate(self.data)
-                f.write(text)
-                f.close()
-		print self.data["stub_h"], " was generated."
+		fname = self.data["output_dir"] + self.data["stub_h"]
+		self.gen(fname, stub_h)
 		return
 
 	def print_stub_cpp(self):
-		f = file(self.data["output_dir"] + self.data["stub_cpp"], "w")
-		t = yat.Template(stub_cpp)
-		text=t.generate(self.data)
-                f.write(text)
-                f.close()
-		print self.data["stub_cpp"], " was generated."
+		fname = self.data["output_dir"] + self.data["stub_cpp"]
+		self.gen(fname, stub_cpp)
 		return
 
 	def print_all(self):



openrtm-commit メーリングリストの案内