26   return "Python component code generator"    30   Python generator specific usage    33 ----------------------------------    34   Help for Python code generator    35 ----------------------------------    36 Python code generator generates the following files.    37     [Component name].py............Component class and executable    38     README.[Component name]........Specification template of the component    40 No additional options are available for Python code generator.    48 [for sidl in service_idl]    49 from [sidl.idl_basename]_idl_example import *    53 import _GlobalIDL, _GlobalIDL__POA    58 [l_name]_spec = ["implementation_id", "[basicInfo.name]",     59                  "type_name",         "[basicInfo.name]",     60                  "description",       "[basicInfo.description]",     61                  "version",           "[basicInfo.version]",     62                  "vendor",            "[basicInfo.vendor]",     63                  "category",          "[basicInfo.category]",     64                  "activity_type",     "[basicInfo.componentType]",     65                  "max_instance",      "[basicInfo.maxInstances]",     67                  "lang_type",         "SCRIPT",    68 [if-any configurationSet.configuration]    69 [for config in configurationSet.configuration]    70                  "conf.default.[config.name]", "[config.defaultValue]",    76 [for dport in dataPorts]    77     self._d_[dport.name] = RTC.[dport.type]([dport.data_type_args])    78 [if dport.portType is DataInPort]    79     self._[dport.name]In = OpenRTM_aist.InPort("[dport.name]", self._d_[dport.name])    80     self.addInPort("[dport.name]",self._[dport.name]In)    82 [elif dport.portType is DataOutPort]    83     self._[dport.name]Out = OpenRTM_aist.OutPort("[dport.name]", self._d_[dport.name])    84     self.addOutPort("[dport.name]",self._[dport.name]Out)    91 [for sport in servicePorts]    92     self._[sport.name]Port = OpenRTM_aist.CorbaPort("[sport.name]")    93 [for sif in sport.serviceInterface]    94 [if sif.direction is Provided]    95     self._[sif.name] = [sif.type]_i()    96     self._[sport.name]Port.registerProvider("[sif.name]", "[sif.type]", self._[sif.name])    97 [elif sif.direction is Required]    98     self._[sif.name] = OpenRTM_aist.CorbaConsumer(interfaceType=_GlobalIDL.[sif.type])    99     self._[sport.name]Port.registerConsumer("[sif.name]", "[sif.type]", self._[sif.name])   101     self.addPort(self._[sport.name]Port)   107 configurations = 
"""\   108 [for config in configurationSet.configuration]   109     self._[config.name] = [config.defaultData]   115 [for conf in configurationSet.configuration]   116     self.bindParameter("[conf.name]", self._[conf.name], "[conf.defaultValue]")   123 py_source = 
"""#!/usr/bin/env python   133 # Import Service implementation class   134 # <rtc-template block="service_impl">   137 # Import Service stub modules   138 # <rtc-template block="global_idl">   142 # This module's spesification   143 # <rtc-template block="module_spec">   146 class [basicInfo.name](OpenRTM_aist.DataFlowComponentBase):   147   def __init__(self, manager):   148     OpenRTM_aist.DataFlowComponentBase.__init__(self, manager)   150     # initialize of configuration-data.   151     # <rtc-template block="configurations">   155   def onInitialize(self):   156     # DataPorts initialization   157     # <rtc-template block="data_ports">   160     # ServicePorts initialization   161     # <rtc-template block="service_ports">   164     # Bind variables and configuration variable   165     # <rtc-template block="bind_config">   170 [for act in activity]   171   #def [act.name](self[if-any act.args], [act.args][else][endif]):   177 def [basicInfo.name]Init(manager):   178   profile = OpenRTM_aist.Properties(defaults_str=[l_name]_spec)   179   manager.registerFactory(profile,   184 def MyModuleInit(manager):   185   [basicInfo.name]Init(manager)   188   comp = manager.createComponent("[basicInfo.name]")   193   mgr = OpenRTM_aist.Manager.init(sys.argv)   194   mgr.setModuleInitProc(MyModuleInit)   195   mgr.activateManager()   198 if __name__ == "__main__":   208   Python component source code generation class   212     self.
data[
'fname'] = self.
data[
'basicInfo'][
'name']
   213     self.
data[
'fname_py'] = self.
data[
'fname'] + 
".py"   214     self.
data[
"u_name"] = self.
data[
"fname"].upper()
   215     self.
data[
"l_name"] = self.
data[
"fname"].lower()
   222     self.
tags[
"service_impl"]    = service_impl
   223     if len(self.
data[
"service_idl"]) > 0 
or \
   224           len(self.
data[
"consumer_idl"]) > 0:
   225       self.
tags[
"global_idl"] = global_idl
   227       self.
tags[
"global_idl"] = no_global_idl
   228     self.
tags[
"module_spec"]     = module_spec
   229     self.
tags[
"data_ports"]      = data_ports
   230     self.
tags[
"service_ports"]   = service_ports
   231     self.
tags[
"configurations"]  = configurations
   232     self.
tags[
"bind_config"]     = bind_config
   238     acts = ((
"onFinalize",    
None), \
   239               (
"onStartup",     
"ec_id"), \
   240               (
"onShutdown",    
"ec_id"), \
   241               (
"onActivated",   
"ec_id"), \
   242               (
"onDeactivated", 
"ec_id"), \
   243               (
"onExecute",     
"ec_id"), \
   244               (
"onAborting",    
"ec_id"), \
   245               (
"onError",       
"ec_id"), \
   246               (
"onReset",       
"ec_id"), \
   247               (
"onStateUpdate", 
"ec_id"), \
   248               (
"onRateChanged", 
"ec_id"))
   250     for name, args 
in acts:
   256     dict[
"activity"] = actlist
   260     if dict[
"service_idl"]:
   261       for svc 
in dict[
"service_idl"]:
   262         svc[
"impl_py"] = svc[
"idl_basename"] + \
   265     if dict[
"consumer_idl"]:
   266       for cons 
in dict[
"consumer_idl"]:
   268           cons[
"modulename"] = 
"_GlobalIDL"   269           f = open(cons[
"idl_fname"], 
'a+')
   274             mod_idx = _str.find(
"module", 0)
   277             _str = _str[mod_idx + 6:]
   278             idx = _str.find(
"{", 0)
   282             cons[
"modulename"] = \
   287           print "Can't find file:", file
   291     if dict[
"dataPorts"] == 
None:
   293     for dport 
in dict[
"dataPorts"]:
   295         dport[
"data_type_args"] = 
"RTC.Time(0,0),[]"   297         dport[
"data_type_args"] = 
"RTC.Time(0,0),0"   301     config = dict[
"configurationSet"][
"configuration"]
   303       for i, conf 
in enumerate(config):
   304         split_data = conf[
"defaultValue"].
split(
",")
   305         if len(split_data) > 1:
   309             _data.append(_type(d))
   310           conf[
"defaultData"] = str([_data])
   313           conf[
"defaultData"] = \
   314               str([_type(conf[
"defaultValue"])])
   318     if str(_type) 
in [
"TimedShortSeq", 
"TimedLongSeq",
   319                       "TimedUShortSeq", 
"TimedULongSeq",
   320                       "TimedFloatSeq", 
"TimedDoubleSeq",
   321                       "TimedCharSeq",
"TimedBooleanSeq",
   322                       "TimedOctetSeq", 
"TimedStringSeq"]:
   329     if str(_type) == 
"int":
   331     elif str(_type) == 
"long":
   333     elif str(_type) == 
"float":
   335     elif str(_type) == 
"double":
   337     elif str(_type) == 
"string":
   345     for sidl 
in self.
data[
"service_idl"]:
   346       if not os.access(sidl[
"idl_fname"], os.F_OK):
   347         sys.stderr.write(
"Error: IDL file \"" \
   348                            + sidl[
"idl_fname"] \
   353         cmd = 
"omniidl -bpython -Wbexample " + \
   357         sys.stderr.write(
"Generate error: " \
   358                            + sidl[
"impl_py"] + 
"\n")
   362           + 
"\" was generated."   364     for cons 
in self.
data[
"consumer_idl"]:
   366       for svc 
in self.
data[
"service_idl"]:
   367         if cons[
"idl_fname"] == svc[
"idl_fname"]:
   371         if not os.access(cons[
"idl_fname"], os.F_OK):
   372           sys.stderr.write(
"Error: IDL file \"" \
   373                              + cons[
"idl_fname"] \
   378           cmd = 
"omniidl -bpython " + \
   382           sys.stderr.write(
"Generate error: omniidl -bpython " + cons[
"idl_fname"])
   387     Generate component class script 
def CreateConfiguration(self, dict)
vstring split(const std::string &input, const std::string &delimiter, bool ignore_empty)
Split string by delimiter. 
def gen(self, fname, temp_txt, data, tags)
def check_data_type(self, _type)
def __init__(self, data, opts)
def CreateActivityFuncs(self, dict)
def CreateService(self, dict)
def get_type(self, _type)
def CreateDataPorts(self, dict)