test-template.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # -*- python -*-
00003 #
00004 #  @file cxx_gen.py
00005 #  @brief rtc-template test case generator
00006 #  @date $Date$
00007 #  @author Noriaki Ando <n-ando@aist.go.jp>
00008 # 
00009 #  Copyright (C) 2008
00010 #      Task-intelligence Research Group,
00011 #      Intelligent Systems Research Institute,
00012 #      National Institute of
00013 #          Advanced Industrial Science and Technology (AIST), Japan
00014 #      All rights reserved.
00015 # 
00016 #  $Id$
00017 # 
00018 
00019 import yat
00020 import random
00021 import os
00022 
00023 myservice_idl = """
00024 typedef sequence<string> EchoList;
00025 typedef sequence<float> ValueList;
00026 interface MyService
00027 {
00028   string echo(in string msg);
00029   EchoList get_echo_history();
00030   void set_value(in float value);
00031   float get_value();
00032   ValueList get_value_history();
00033 };
00034 """
00035 
00036 myservice_impl_h = """
00037 #include "MyServiceSkel.h"
00038 
00039 #ifndef MYSERVICESVC_IMPL_H
00040 #define MYSERVICESVC_IMPL_H
00041  
00042 /*
00043  * Example class implementing IDL interface MyService
00044  */
00045 class MyServiceSVC_impl
00046  : public virtual POA_MyService,
00047    public virtual PortableServer::RefCountServantBase
00048 {
00049  private:
00050    // Make sure all instances are built on the heap by making the
00051    // destructor non-public
00052    //virtual ~MyServiceSVC_impl();
00053 
00054  public:
00055    // standard constructor
00056    MyServiceSVC_impl();
00057    virtual ~MyServiceSVC_impl();
00058 
00059    // attributes and operations
00060    char* echo(const char* msg)
00061      throw (CORBA::SystemException);
00062    EchoList* get_echo_history()
00063      throw (CORBA::SystemException);
00064    void set_value(CORBA::Float value)
00065      throw (CORBA::SystemException);
00066    CORBA::Float get_value()
00067      throw (CORBA::SystemException);
00068    ValueList* get_value_history()
00069      throw (CORBA::SystemException);
00070 
00071 private:
00072   CORBA::Float m_value;
00073   EchoList m_echoList;
00074   ValueList m_valueList;
00075 };
00076 
00077 
00078 
00079 #endif // MYSERVICESVC_IMPL_H
00080 """
00081 
00082 myservice_impl_cpp = """\
00083 #include "MyServiceSVC_impl.h"
00084 #include <rtm/CORBA_SeqUtil.h>
00085 #include <iostream>
00086 
00087 template <class T>
00088 struct seq_print
00089 {
00090   seq_print() : m_cnt(0) {};
00091   void operator()(T val)
00092   {
00093     std::cout << m_cnt << ": " << val << std::endl;
00094     ++m_cnt;
00095   }
00096   int m_cnt;
00097 };
00098 
00099 /*
00100  * Example implementational code for IDL interface MyService
00101  */
00102 MyServiceSVC_impl::MyServiceSVC_impl()
00103 {
00104   // Please add extra constructor code here.
00105 }
00106 
00107 
00108 MyServiceSVC_impl::~MyServiceSVC_impl()
00109 {
00110   // Please add extra destructor code here.
00111 }
00112 
00113 
00114 /*
00115  * Methods corresponding to IDL attributes and operations
00116  */
00117 char* MyServiceSVC_impl::echo(const char* msg)
00118   throw (CORBA::SystemException)
00119 {
00120   CORBA_SeqUtil::push_back(m_echoList, msg);
00121   std::cout << "MyService::echo() was called." << std::endl;
00122   std::cout << "Message: " << msg << std::endl;
00123   return CORBA::string_dup(msg);
00124 }
00125 
00126 EchoList* MyServiceSVC_impl::get_echo_history()
00127   throw (CORBA::SystemException)
00128 {
00129   std::cout << "MyService::get_echo_history() was called." << std::endl;
00130   CORBA_SeqUtil::for_each(m_echoList, seq_print<const char*>());
00131   
00132   EchoList_var el;
00133   el = new EchoList(m_echoList);
00134   return el._retn();
00135 }
00136 
00137 void MyServiceSVC_impl::set_value(CORBA::Float value)
00138   throw (CORBA::SystemException)
00139 {
00140   CORBA_SeqUtil::push_back(m_valueList, value);
00141   m_value = value;
00142 
00143   std::cout << "MyService::set_value() was called." << std::endl;
00144   std::cout << "Current value: " << m_value << std::endl;
00145 
00146   return;
00147 }
00148 
00149 CORBA::Float MyServiceSVC_impl::get_value()
00150   throw (CORBA::SystemException)
00151 {
00152   std::cout << "MyService::get_value() was called." << std::endl;
00153   std::cout << "Current value: " << m_value << std::endl;
00154 
00155   return m_value;
00156 }
00157 
00158 ValueList* MyServiceSVC_impl::get_value_history()
00159   throw (CORBA::SystemException)
00160 {
00161   std::cout << "MyService::get_value_history() was called." << std::endl;
00162   CORBA_SeqUtil::for_each(m_valueList, seq_print<CORBA::Float>());
00163 
00164   ValueList_var vl;
00165   vl = new ValueList(m_valueList);
00166   return vl._retn();
00167 }
00168 """
00169 
00170 
00171 yourservice_idl = """
00172 interface YourService {
00173   void func0();
00174 
00175   void func1(in short val);
00176   void func2(inout short val);
00177   void func3(out short val);
00178 
00179   void func4(in long val);
00180   void func5(inout long val);
00181   void func6(out long val);
00182 
00183   void func7(in float val);
00184   void func8(inout float val);
00185   void func9(out float val);
00186 
00187   void func10(in double val);
00188   void func11(inout double val);
00189   void func12(out double val);
00190 
00191 };
00192 """
00193 
00194 vector_convert_h = """\
00195 // -*- C++ -*-
00196 
00197 #include <istream>
00198 #include <ostream>
00199 #include <vector>
00200 #include <string>
00201 #include <coil/stringutil.h>
00202 
00203 template<typename T>
00204 std::istream& operator>>(std::istream& is, std::vector<T>& v)
00205 {
00206   std::string s;
00207   coil::vstring sv;
00208   is >> s;
00209   sv = coil::split(s ,",");
00210   v.resize(sv.size());
00211   for (int i(0), len(sv.size()); i < len; ++i)
00212     {
00213       T tv;
00214       if (coil::stringTo(tv, sv[i].c_str()))
00215         {
00216           v[i] = tv;
00217         }
00218     }
00219   return is;
00220 }
00221 """
00222 
00223 gen_main = """\
00224 rtc-template -bcxx
00225     --module-name=[name] --module-desc="Test RTC for rtc-template"
00226     --module-version=1.0.0 --module-vendor=AIST --module-category=Test
00227     --module-comp-type=DataFlowComponent --module-act-type=SPORADIC
00228     --module-max-inst=10
00229 [for ip in inports]
00230     --inport="[ip.name]:[ip.type]"
00231 [endfor]
00232 
00233 [for op in outports]
00234     --outport="[op.name]:[op.type]"
00235 [endfor]
00236 
00237 [for sp in svcports]
00238     --[sp.direction]="[sp.port_name]:[sp.inst_name]:[sp.type]"
00239     --[sp.direction]-idl="[sp.idl_file]"
00240 [endfor]
00241 
00242 [for cf in configs]
00243     --config="[cf.name]:[cf.type]:[cf.default]"
00244 [endfor]
00245 """
00246 
00247 rtm_config = """\
00248 #!/bin/sh
00249 #
00250 # this is for only Linux!!
00251 #
00252 rtm_prefix="/usr/local"
00253 rtm_exec_prefix="/usr/local"
00254 rtm_cxx="g++"
00255 rtm_cflags="-Wall -fPIC -O2 -I../../../../src/lib -I../../../../src/lib/rtm/idl -I../../../../src/lib/coil/include"
00256 rtm_libs="-export-dynamic -luuid -ldl -L../../../../src/lib/rtm/.libs -L../../../../src/lib/coil/lib/.libs -lpthread -lomniORB4 -lomnithread -lomniDynamic4 -lRTC -lcoil"
00257 rtm_libdir=""
00258 rtm_version="1.0.0"
00259 rtm_orb="omniORB"
00260 rtm_idlc="omniidl"
00261 rtm_idlflags="-bcxx -Wba -nf"
00262 
00263 usage()
00264 {
00265         cat <<EOF
00266 Usage: rtm-config [OPTIONS]
00267 Options:
00268         [--prefix[=DIR]]
00269         [--exec-prefix[=DIR]]
00270         [--version]
00271         [--cxx]
00272         [--cflags]
00273         [--libs]
00274         [--libdir]
00275         [--orb]
00276         [--idlc]
00277         [--idlflags]
00278 EOF
00279         exit $1
00280 }
00281 
00282 if test $# -eq 0; then
00283         usage 1 1>&2
00284 fi
00285 
00286 
00287 while test $# -gt 0; do
00288   case "$1" in
00289   -*=*) optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
00290   *) optarg= ;;
00291   esac
00292 
00293   case $1 in
00294     --prefix=*)
00295       prefix=$optarg
00296       if test $exec_prefix_set = no ; then
00297         exec_prefix=$optarg
00298       fi
00299       ;;
00300     --prefix)
00301       echo_prefix=yes
00302       ;;
00303     --exec-prefix=*)
00304       rtm_exec_prefix=$optarg
00305       exec_prefix_set=yes
00306       ;;
00307     --exec-prefix)
00308       echo_exec_prefix=yes
00309       ;;
00310     --version)
00311       echo $rtm_version
00312       ;;
00313     --cxx)
00314       echo_cxx=yes
00315       ;;
00316     --cflags)
00317       echo_cflags=yes
00318       ;;
00319     --libs)
00320       echo_libs=yes
00321       ;;
00322     --libdir)
00323       echo_libdir=yes
00324           ;;
00325     --orb)
00326       echo_orb=yes
00327       ;;
00328     --idlc)
00329       echo_idlc=yes
00330       ;;
00331     --idlflags)
00332       echo_idlflags=yes
00333       ;;
00334     *)
00335       usage 1 1>&2
00336       ;;
00337   esac
00338   shift
00339 done
00340 
00341 if test "$echo_prefix" = "yes"; then
00342         echo $rtm_prefix
00343 fi
00344 
00345 if test "$echo_exec_prefix" = "yes"; then
00346         echo $rtm_exec_prefix
00347 fi
00348 
00349 if test "$echo_cxx" = "yes"; then
00350       echo $rtm_cxx
00351 fi
00352 
00353 if test "$echo_cflags" = "yes"; then
00354       echo $rtm_cflags
00355 fi
00356 
00357 if test "$echo_libs" = "yes"; then
00358       echo $rtm_libs
00359 fi      
00360 
00361 if test "$echo_libdir" = "yes"; then
00362       echo $rtm_libdir
00363 fi      
00364 
00365 if test "$echo_orb" = "yes"; then
00366       echo $rtm_orb
00367 fi      
00368 
00369 if test "$echo_idlc" = "yes"; then
00370       echo $rtm_idlc
00371 fi      
00372 
00373 if test "$echo_idlflags" = "yes"; then
00374       echo $rtm_idlflags
00375 fi      
00376 
00377 """
00378 
00379 bat_header = """\
00380 @set PATH="%RTM_ROOT%\\utils\\rtc-template";%PATH%
00381 @set PYTHONPATH="%RTM_ROOT%\\utils\\rtc-template"
00382 
00383 del /F /Q *.cpp *.h *.hh *.cc *.sln *.vcproj *.vsprops *.yaml
00384 del /F /Q copyprops.bat Makefile.* README.* 
00385 
00386 rmdir /Q /S [name]
00387 
00388 rmdir /Q /S [name]Comp
00389 
00390 """
00391 
00392 sh_header = """\
00393 #!/bin/sh
00394 export PYTHONPATH=../../:../../py_helper
00395 export RTM_ROOT=../../../../
00396 export PATH=./:../../:../../../rtm-skelwrapper:$PATH
00397 
00398 rm -rf *.cpp *.h *.hh *.cc *.sln *.vcproj *.vsprops *.yaml
00399 rm -rf copyprops.bat Makefile.* README.*
00400 rm -rf [name] [name]Comp
00401 
00402 """
00403 
00404 bat_footer = """
00405 
00406 call copyprops.bat
00407 for %%x in (*.tmp) do copy /y %%x %%~nx
00408 
00409 echo #include "VectorConvert.h" >> [name].h
00410 
00411 """
00412 
00413 sh_footer = """
00414 
00415 for tmpname in *.tmp
00416 do
00417     fname=`basename $tmpname .tmp`
00418     cp -f $tmpname $fname
00419 done
00420 
00421 echo '#include "VectorConvert.h"' >> [name].h
00422 
00423 make -f Makefile.*
00424 """
00425 
00426 build_vc8_bat = """\
00427 @set PATH="C:\\Program Files\\Microsoft Visual Studio 8\\VC\\vcpackages";%PATH%
00428 
00429 [for proj in projects]
00430 cd [proj] 
00431 call gen.bat
00432 vcbuild [proj]_vc8.sln
00433 cd ..
00434 [endfor]
00435 """
00436 
00437 build_vc9_bat = """\
00438 @set PATH="C:\\Program Files\\Microsoft Visual Studio 9.0\\VC\\vcpackages";%PATH%
00439 
00440 [for proj in projects]
00441 cd [proj] 
00442 call gen.bat
00443 vcbuild [proj]_vc9.sln
00444 cd ..
00445 [endfor]
00446 """
00447 
00448 build_sh = """\
00449 #!/bin/sh
00450 
00451 [for proj in projects]
00452 cd [proj] 
00453 sh gen.sh
00454 #make -f Makefile.[proj] 
00455 if test -f [proj]Comp; then
00456   echo [proj]: OK >> ../build_status
00457 else
00458   echo [proj]: NG >> ../build_status
00459 fi
00460 cd ..
00461 [endfor]
00462 """
00463 
00464 inports = [
00465     {"name": "in00", "type": "TimedShort"},
00466     {"name": "in01", "type": "TimedLong"},
00467     {"name": "in02", "type": "TimedUShort"},
00468     {"name": "in03", "type": "TimedULong"},
00469     {"name": "in04", "type": "TimedFloat"},
00470     {"name": "in05", "type": "TimedDouble"},
00471     {"name": "in06", "type": "TimedChar"},
00472     {"name": "in07", "type": "TimedBoolean"},
00473     {"name": "in08", "type": "TimedOctet"},
00474     {"name": "in09", "type": "TimedString"},
00475     {"name": "in10", "type": "TimedShortSeq"},
00476     {"name": "in11", "type": "TimedLongSeq"},
00477     {"name": "in12", "type": "TimedUShortSeq"},
00478     {"name": "in13", "type": "TimedULongSeq"},
00479     {"name": "in14", "type": "TimedFloatSeq"},
00480     {"name": "in15", "type": "TimedDoubleSeq"},
00481     {"name": "in16", "type": "TimedCharSeq"},
00482     {"name": "in17", "type": "TimedBooleanSeq"},
00483     {"name": "in18", "type": "TimedOctetSeq"},
00484     {"name": "in19", "type": "TimedStringSeq"}
00485     ]
00486 
00487 outports = [
00488     {"name": "out00", "type": "TimedShort"},
00489     {"name": "out01", "type": "TimedLong"},
00490     {"name": "out02", "type": "TimedUShort"},
00491     {"name": "out03", "type": "TimedULong"},
00492     {"name": "out04", "type": "TimedFloat"},
00493     {"name": "out05", "type": "TimedDouble"},
00494     {"name": "out06", "type": "TimedChar"},
00495     {"name": "out07", "type": "TimedBoolean"},
00496     {"name": "out08", "type": "TimedOctet"},
00497     {"name": "out09", "type": "TimedString"},
00498     {"name": "out10", "type": "TimedShortSeq"},
00499     {"name": "out11", "type": "TimedLongSeq"},
00500     {"name": "out12", "type": "TimedUShortSeq"},
00501     {"name": "out13", "type": "TimedULongSeq"},
00502     {"name": "out14", "type": "TimedFloatSeq"},
00503     {"name": "out15", "type": "TimedDoubleSeq"},
00504     {"name": "out16", "type": "TimedCharSeq"},
00505     {"name": "out17", "type": "TimedBooleanSeq"},
00506     {"name": "out18", "type": "TimedOctetSeq"},
00507     {"name": "out19", "type": "TimedStringSeq"}
00508     ]
00509 
00510 configs = [
00511     {"name": "conf_short", "type": "short",
00512      "default": "12"},
00513     {"name": "conf_int", "type": "int",
00514      "default": "1234"},
00515     {"name": "conf_long", "type": "long",
00516      "default": "-12345"},
00517     {"name": "conf_ushort", "type": "unsigned short",
00518      "default": "987"},
00519     {"name": "conf_uint", "type": "unsigned int",
00520      "default": "9876"},
00521     {"name": "conf_ulong", "type": "unsigned long",
00522      "default": "98765"},
00523     {"name": "conf_float", "type": "float",
00524      "default": "3.14159265"},
00525     {"name": "conf_double", "type": "double",
00526      "default": "0.0000000001"},
00527     {"name": "conf_string", "type": "std::string",
00528      "default": "OpenRTM-aist"},
00529     {"name": "conf_vshort", "type": "std::vector<short>",
00530      "default": "0,1,2,3,4,5,6,7,8,9"},
00531     {"name": "conf_vint", "type": "std::vector<int>",
00532      "default": "9,8,7,6,5,4,3,2,1,0"},
00533     {"name": "conf_vlong", "type": "std::vector<long>",
00534      "default": "0,10,20,30,40,50,60,70,80,90"},
00535     {"name": "conf_vushort", "type": "std::vector<unsigned short>",
00536      "default": "1,2"},
00537     {"name": "conf_vuint", "type": "std::vector<unsigned int>",
00538      "default": "0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20"},
00539     {"name": "conf_vulong", "type": "std::vector<unsigned long>",
00540      "default": "0,10000,20000,30000,40000,50000,60000,70000,80000,90000"},
00541     {"name": "conf_vfloat", "type": "std::vector<float>",
00542      "default": "0.1,0.01,0.001,0.0001,0.00001,0.000001,0.0000001,0.00000001"},
00543     {"name": "conf_vdouble", "type": "std::vector<double>",
00544      "default": "1.1,1.01,1.001,1.0001,1.00001,1.000001,1.0000001,1.00000001"}
00545 ]
00546 
00547 svcports = [
00548     {"type": "MyService", "direction": "service",
00549      "port_name": "sp0", "inst_name": "my0",
00550      "idl_file": "MyService.idl", "idl_data": myservice_idl,
00551      "impl_h": myservice_impl_h, "impl_cpp": myservice_impl_cpp},
00552     {"type": "MyService", "direction": "consumer",
00553      "port_name": "sp0", "inst_name": "my1",
00554      "idl_file": "MyService.idl", "idl_data": myservice_idl,
00555      "impl_h": myservice_impl_h, "impl_cpp": myservice_impl_cpp},
00556     {"type": "MyService", "direction": "service",
00557      "port_name": "sp1", "inst_name": "my2",
00558      "idl_file": "MyService.idl", "idl_data": myservice_idl,
00559      "impl_h": myservice_impl_h, "impl_cpp": myservice_impl_cpp},
00560     {"type": "MyService", "direction": "consumer",
00561      "port_name": "sp1", "inst_name": "my3",
00562      "idl_file": "MyService.idl", "idl_data": myservice_idl,
00563      "impl_h": myservice_impl_h, "impl_cpp": myservice_impl_cpp},
00564     {"type": "MyService", "direction": "service",
00565      "port_name": "sp2", "inst_name": "my4",
00566      "idl_file": "MyService.idl", "idl_data": myservice_idl,
00567      "impl_h": myservice_impl_h, "impl_cpp": myservice_impl_cpp},
00568     {"type": "MyService", "direction": "consumer",
00569      "port_name": "sp2", "inst_name": "my5",
00570      "idl_file": "MyService.idl", "idl_data": myservice_idl,
00571      "impl_h": myservice_impl_h, "impl_cpp": myservice_impl_cpp},
00572     {"type": "YourService", "direction": "service",
00573      "port_name": "sp0", "inst_name": "your0",
00574      "idl_file": "YourService.idl", "idl_data": yourservice_idl,
00575      "impl_h": None, "impl_cpp": None},
00576     {"type": "YourService", "direction": "consumer",
00577      "port_name": "sp0", "inst_name": "your1",
00578      "idl_file": "YourService.idl", "idl_data": yourservice_idl,
00579      "impl_h": None, "impl_cpp": None},
00580     {"type": "YourService", "direction": "service",
00581      "port_name": "sp1", "inst_name": "your2",
00582      "idl_file": "YourService.idl", "idl_data": yourservice_idl,
00583      "impl_h": None, "impl_cpp": None},
00584     {"type": "YourService", "direction": "consumer",
00585      "port_name": "sp1", "inst_name": "your3",
00586      "idl_file": "YourService.idl", "idl_data": yourservice_idl,
00587      "impl_h": None, "impl_cpp": None},
00588     {"type": "YourService", "direction": "service",
00589      "port_name": "sp2", "inst_name": "your4",
00590      "idl_file": "YourService.idl", "idl_data": yourservice_idl,
00591      "impl_h": None, "impl_cpp": None},
00592     {"type": "YourService", "direction": "consumer",
00593      "port_name": "sp2", "inst_name": "your5",
00594      "idl_file": "YourService.idl", "idl_data": yourservice_idl,
00595      "impl_h": None, "impl_cpp": None}
00596     ]
00597     
00598 
00599 nums = [0, 1, 2, 10]
00600 
00601 params = {
00602     "inports": inports,
00603     "outports": outports,
00604     "svcports": svcports,
00605     "configs": configs
00606     }
00607 
00608 def _mkdir(newdir):
00609     """works the way a good mkdir should :)
00610     - already exists, silently complete
00611     - regular file in the way, raise an exception
00612     - parent directory(ies) does not exist, make them as well
00613     """
00614     if os.path.isdir(newdir):
00615         pass
00616     elif os.path.isfile(newdir):
00617         raise OSError("a file with the same name as the desired " \
00618                           "dir, '%s', already exists." % newdir)
00619     else:
00620         head, tail = os.path.split(newdir)
00621         if head and not os.path.isdir(head):
00622             _mkdir(head)
00623         #print "_mkdir %s" % repr(newdir)
00624         if tail:
00625             os.mkdir(newdir)
00626 
00627 class TestGen:
00628     def __init__(self, ip_num, op_num, sp_num, cf_num):
00629         self.ip_num = ip_num
00630         self.op_num = op_num
00631         self.sp_num = sp_num
00632         self.cf_num = cf_num
00633         for key in params.keys():
00634             random.shuffle(params[key])
00635         self.params = params
00636         self.pjnames = []
00637 
00638     def generate(self):
00639         self.gen()
00640         self.craete_build_sh()
00641 
00642     def craete_build_sh(self):
00643         dict = {}
00644         dict["projects"] = self.pjnames
00645         builds = {"build.sh": build_sh,
00646                   "build_vc8.bat": build_vc8_bat,
00647                   "build_vc9.bat": build_vc9_bat
00648                   }
00649         for key in builds.keys():
00650             fd = open(key, "w")
00651             fd.write(yat.Template(builds[key]).generate(dict))
00652             fd.close()
00653             os.chmod(key, 0755)
00654 
00655         
00656     def mkdir(self, dirname):
00657         _mkdir(dirname)
00658 
00659     def dict(self, ip, op, sp, cf):
00660         name = "Sample_%d_%d_%d_%d" % (ip, op, sp, cf)
00661         dict = {"name": name}
00662         p = ["inports", "outports", "svcports", "configs"]
00663         n = [ip, op, sp, cf]
00664         for i in range(len(n)):
00665             dict[p[i]] = self.params[p[i]][0:n[i]]
00666         return dict
00667 
00668     def create_gen_sh(self, dict):
00669         fname = dict["name"] + "/gen.sh"
00670         fd = open(fname, "w")
00671         head = yat.Template(sh_header).generate(dict)
00672         body = yat.Template(gen_main).generate(dict)
00673         body = self.add_cmark(body, "\\")
00674         foot = yat.Template(sh_footer).generate(dict)
00675 
00676         sh_all = head + body + foot
00677         fd.write(sh_all)
00678         fd.close()
00679         os.chmod(fname, 0755)
00680         
00681     def create_gen_bat(self, dict):
00682         fname = dict["name"] + "/gen.bat"
00683         fd = open(fname, "w")
00684         head = yat.Template(bat_header).generate(dict)
00685         body = yat.Template(gen_main).generate(dict)
00686         body = body.replace("rtc-template", "rtc-template.py")
00687         body = self.add_cmark(body, "^")
00688         foot = yat.Template(bat_footer).generate(dict)
00689 
00690         bat_all = head + body + foot
00691         bat_all.replace("\r\n", "\n").replace("\n", "\r\n")
00692         fd.write(bat_all)
00693         fd.close()
00694         os.chmod(fname, 0755)
00695 
00696     def add_cmark(self, text, mark):
00697         lines = [t for t in text.split("\n") if t != ""]
00698         return (mark + "\n").join(lines)
00699 
00700     def create_idl(self, dict):
00701         idls = []
00702         for svc in dict["svcports"]:
00703             if not svc["idl_file"] in idls:
00704                 fname = dict["name"] + "/" + svc["idl_file"]
00705                 fd = open(fname, "w")
00706                 fd.write(svc["idl_data"])
00707                 fd.close()
00708                 idls.append(svc["idl_file"])
00709 
00710                 if svc["impl_h"] != None:
00711                     cpp_fname = dict["name"] + "/" + \
00712                         svc["idl_file"].replace(".idl","SVC_impl.cpp.tmp")
00713                     fd = open(cpp_fname, "w")
00714                     fd.write(svc["impl_cpp"])
00715                     fd.close
00716 
00717                     h_fname = dict["name"] + "/" + \
00718                         svc["idl_file"].replace(".idl","SVC_impl.h.tmp")
00719                     fd = open(h_fname, "w")
00720                     fd.write(svc["impl_h"])
00721                     fd.close
00722 
00723     def create_vecconv(self, dict):
00724         fname = dict["name"] + "/" + "VectorConvert.h.tmp"
00725         fd = open(fname, "w")
00726         fd.write(vector_convert_h)
00727         fd.close()
00728 
00729     def create_rtmconfig(self, dict):
00730         fname = dict["name"] + "/rtm-config"
00731         fd = open(fname, "w")
00732         fd.write(rtm_config)
00733         fd.close()
00734         os.chmod(fname, 0755)
00735 
00736     def create_gen(self, dict):
00737         self.create_gen_sh(dict)
00738         self.create_gen_bat(dict)
00739         self.create_idl(dict)
00740         self.create_vecconv(dict)
00741         self.create_rtmconfig(dict)
00742 
00743     def gen(self):
00744         for ip in self.ip_num:
00745             for op in self.op_num:
00746                 for sp in self.sp_num:
00747                     for cf in self.cf_num:
00748                         dict = self.dict(ip, op, sp, cf)
00749                         self.mkdir(dict["name"])
00750                         self.create_gen(dict)
00751                         self.pjnames.append(dict["name"])
00752 
00753 
00754 if __name__ == "__main__":
00755     t = TestGen([0,1,5],[0,1,5],[0,1,5],[0,1,5])
00756 #    t = TestGen([5],[5],[5],[5])
00757     t.generate()


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Sun Mar 26 2017 03:37:17