72 platform = sys.platform
80 if platform ==
"win32":
81 python_path = os.environ[
'PYTHONPATH'].
split(
";")
82 pyhelper_path = python_path[0] +
"\\OpenRTM_aist\\utils\\rtc-template" 84 conf_path = os.popen(
"which rtm-config",
"r").read().split("\n")
85 if conf_path[0] !=
'':
86 libdir_path = os.popen(
"rtm-config --libdir",
"r").read().split("\n")
87 pyhelper_path = libdir_path[0] +
"/py_helper" 89 python_path = os.environ[
'PYTHONPATH'].
split(
":")
90 pyhelper_path = python_path[0] +
"/OpenRTM_aist/utils/rtc-template" 91 sys.path.append(pyhelper_path)
94 opt_args_fmt = [
"help",
121 Usage: rtc-template [OPTIONS] 125 [-h] Print short help. 126 [--help] Print details help. 127 [--backend[=backend] or -b] Specify template code generator. 128 [--module-name[=name]] Your module name. 129 [--module-desc[=description]] Module description. 130 [--module-version[=version]] Module version. 131 [--module-vendor[=vendor]] Module vendor. 132 [--module-category[=category]] Module category. 133 [--module-comp-type[=component_type]] Component type. 134 [--module-act-type[=activity_type]] Component's activity type. 135 [--module-max-inst[=max_instance]] Number of maximum instance. 136 [--module-lang[=language]] Language. 137 [--config[=ParamName:Type:Default]] Configuration variable. 138 [--inport[=PortName:Type]] InPort's name and type. 139 [--outport[=PortName:Type]] OutPort's name and type 140 [--service[=PortName:Name:Type]] Service Provider Port 141 [--service-idl[=IDL_file]] IDL file name for service 142 [--consumer[=PortName:Name:Type]] Service Consumer Port 143 [--consumer-idl[=IDL_file]] IDL file name for consumer 144 [--idl-include=[path]] Search path for IDL compile 152 --output[=output_file]: 153 Specify base name of output file. If 'XXX' is specified, 154 C++ source codes XXX.cpp, XXX.h, XXXComp.cpp Makefile.XXX is generated. 156 --module-name[=name]: 157 Your component's base name. This string is used as module's 158 name and component's base name. A generated new component 159 class name is also names as this RTC_MODULE_NAME. 160 Only alphabetical and numerical characters are acceptable. 162 --module-desc[=description]: 163 Short description. If space characters are included, string should be 166 --module-version[=version]: 167 Your module version. ex. 1.0.0 169 --module-vendor[=vendor]: 170 Vendor's name of this component. 172 --module-category[=category]: 173 This component module's category. ex. Manipulator MobileRobot, etc... 175 --module-comp-type[=component_type]: 176 Specify component type. 177 'STATIC', 'UNIQUE', 'COMMUTATIVE' are acceptable. 179 --module-act-type[=activity_type]: 180 Specify component activity's type. 181 'PERIODIC', 'SPORADIC', 'EVENT_DRIVEN' ace acceptable. 183 --module-max-inst[=max_instance]: 184 Specify maximum number of component instance. 186 --config=[ParamName:Type:Default]: 187 Specify configuration value. The 'ParamName' is used as the 188 configuration value identifier. This character string is also used as 189 variable name in the source code. The 'Type' is type of configuration 190 value. The type that can be converted to character string is allowed. 191 In C++ language, the type should have operators '<<' and '>>' that 193 'istream& operator<<(Type)' 195 'ostream& operator>>(Type)'. 197 --inport=[PortName:Type]: 198 Specify InPort's name and type. 'PortName' is used as this InPort's 199 name. This string is also used as variable name in soruce code. 200 'Type' is InPort's variable type. The acceptable types are, 201 Timed[ Short | Long | UShort | ULong | Float | Double | Char | Boolean 202 | Octet | String ] and its sequence types. 204 --outport=[PortName:Type]: 205 Specify OutPort's name and type. 'PortName' is used as this OutPort's 206 name. This string is also used as variable name in soruce code. 207 'Type' is OutPort's variable type. The acceptable types are, 208 Timed[ Short | Long | UShort | ULong | Float | Double | Char | Boolean 209 | Octet | String ] and its sequence types. 211 --service=[PortName:Name:Type]: 212 Specify service name, type and port name. 213 PortName: The name of Port to which the interface belongs. 214 This name is used as CorbaPort's name. 215 Name: The name of the service interface. This name is used as 216 the name of the interface, instance name and variable name. 217 Type: The type of the serivce interface. 218 This name is used as type name of the service. 220 --service-idl=[IDL filename]: 221 Specify IDL file of service interface. 222 For simplicity, please define one interface in one IDL file, although 223 this IDL file can include two or more interface definition, 225 --consumer=[PortName:Name:Type]: 226 Specify consumer name, type and port name. 227 PortName: The name of Port to which the consumer belongs. 228 This name is used as CorbaPort's name. 229 Name: The name of the consumer. This name is used as 230 the name of the consumer, instance name and variable name. 231 Type: The serivce interface type that is required by the consumer. 232 This name is used as type name of the consumer. 234 --consumer-idl=[IDL filename]: 235 Specify IDL file of service consumer. 236 For simplicity, please define one interface in one IDL file, although 237 this IDL file can include two or more interface definition, 241 rtc-template -bcxx \\ 242 --module-name=Sample --module-desc='Sample component' \\ 243 --module-version=0.1 --module-vendor=AIST --module-category=Generic \\ 244 --module-comp-type=DataFlowComponent --module-act-type=SPORADIC \\ 245 --module-max-inst=10 \\ 246 --config=int_param0:int:0 --config=int_param1:int:1 \\ 247 --config=double_param0:double:3.14 --config=double_param1:double:9.99 \\ 248 --config="str_param0:std::string:hoge" \\ 249 --config="str_param1:std::string:foo" \\ 250 --inport=Ref:TimedFloat --inport=Sens:TimedFloat \\ 251 --outport=Ctrl:TimedDouble --outport=Monitor:TimedShort \\ 252 --service=MySvcPort:myservice0:MyService \\ 253 --consumer=YourSvcPort:yourservice0:YourService \\ 254 --service-idl=MyService.idl --consumer-idl=YourService.idl 268 This class create RTM module profile for ezt. 271 def __init__(self, name="", desc="", type="", version="", vendor="",
272 category="", comp_type="", act_type="",
273 max_inst="", lang=""):
289 member = member.replace(
"-",
"_")
290 if hasattr(self, member):
291 setattr(self, member, value)
293 print "Invalid option: --module-" + member +
" " + value
329 print "----- Module Profile -----" 330 print "Name ", self.
name 331 print "Description ", self.
desc 333 print "Vendor ", self.
vendor 336 print "Activity Type ", self.
act_type 337 print "Max Instancese ", self.
max_inst 338 print "Language ", self.
lang 347 Create ModuleProfile list from command options 350 for opt, arg
in opts:
351 if opt.find(
"--module-") == 0:
352 var = opt.replace(
"--module-",
"")
353 prof.setValue(var, arg)
359 MakeConfigurationParameters 361 Create Configuration list from command options 365 for opt, arg
in opts:
366 if opt == (
"--config"):
369 arg = re.sub(
"::",
"@@", arg)
370 name, type, default = arg.split(
":")
371 name = re.sub(
"@@",
"::", name)
372 type = re.sub(
"@@",
"::", type)
373 default = re.sub(
"@@",
"::", default)
375 sys.stderr(
"Invalid option: " \
381 prof.l_name = name.lower()
382 prof.u_name = name.upper()
384 prof.default = default
385 prof_list.append(prof)
394 Create PortProfile list from command options 398 for opt, arg
in opts:
399 if opt == (
"--" + port_type):
401 name, type = arg.split(
":")
403 sys.stderr(
"Invalid option: " \
411 prof_list.append(prof)
420 Create Port interface profile list from command options 424 for opt, arg
in opts:
425 if opt ==
"--" + port_type:
427 port, name, type = arg.split(
":")
429 sys.stderr.write(
"Invalid option: " \
438 prof_list.append(prof)
446 Create Corba Port profile list from command options 450 for opt, arg
in opts:
451 if opt == (
"--" +
"service")
or opt == (
"--" +
"consumer"):
453 port, name, type = arg.split(
":")
455 sys.stderr.write(
"Invalid option: " \
467 prof_list.append(prof)
477 Create ServiceIDL list from command options 481 for opt, arg
in opts:
482 if opt.find(
"--service-idl") == 0:
484 svc_idl.idl_fname = arg
485 svc_idl.idl_basename, dummy = arg.split(
".")
486 idl_list.append(svc_idl)
492 for opt, arg
in opts:
493 if opt ==
"--consumer-idl":
495 svc_idl.idl_fname = arg
496 svc_idl.idl_basename, dummy = arg.split(
".")
497 idl_list.append(svc_idl)
503 for opt, arg
in opts:
504 if opt.find(value) == 0:
514 for opt, arg
in opts:
515 if opt == (
"--" + value):
523 self.
obj = getattr(mod, mod_name)
536 path_list = [pyhelper_path,
"."]
537 for path
in path_list:
538 for f
in os.listdir(path):
539 if re.compile(
"_gen.py$").search(f):
540 mod_name = f.replace(
".py",
"")
541 opt_name = f.replace(
"_gen.py",
"")
542 mod = __import__(mod_name, globals(), locals(), [])
548 print "Invalid backend: ", f
556 if opt.find(
'-b') == 0:
557 backend_name = opt.replace(
"-b",
"")
558 if self.
backends.has_key(backend_name):
561 print "No such backend: ", backend_name
563 elif opt.find(
'--backend=') == 0:
564 backend_name = opt.replace(
"--backend=",
"")
565 if self.
backends.has_key(backend_name):
568 print "No such backend: ", backend_name
576 fmts += self.
backends[be].mod.get_opt_fmt()
581 print "The following backends are available." 584 desc = self.
backends[key].mod.description()
585 print " -b" + key + (
"." * (space - len(key))) + desc
587 Backend [xxx] specific help can be available by the following options. 588 -bxxx --help|-h or --backend=xxx --help|-h 601 print self.
backends[be].mod.usage_short()
608 self.
backends[be].obj(data, opts).print_all()
622 arg_fmt[line] += a +
" " 632 backends.check_args(sys.argv[1:])
633 opt_args_fmt += backends.get_opt_fmts()
636 opts, args = getopt.getopt(sys.argv[1:],
"b:ho:v", opt_args_fmt)
637 except getopt.GetoptError:
638 print "Error: Invalid option.", getopt.GetoptError
640 backends.usage_available()
645 backends.usage_available()
651 output_python =
False 658 backends.usage_available()
659 backends.usage_short()
663 backends.usage_available()
666 if o
in (
"-o",
"--output"):
671 if conf_path[0] !=
'':
672 prefix = os.popen(
"rtm-config --prefix",
"r").read().split("\n")
675 idl_inc.append(prefix[0] +
"/include/rtm/idl")
676 idl_inc.append(prefix[0] +
"/include/rtm")
690 'idl_include':
find_opt_list(opts,
"--idl-include", idl_inc),
696 if data[
'fname'] ==
None:
697 data[
'fname'] = data[
'module'].name
699 backends.generate_code(data, opts)
703 readme_src.print_all()
707 if __name__ ==
"__main__":
def usage_available(self)
def __init__(self, name="", desc="", type="", version="", vendor="", category="", comp_type="", act_type="", max_inst="", lang="")
def find_opt(opts, value, default)
def generate_code(self, data, opts)
def split(input, delimiter)
Split string by delimiter.
def MakeConsumerIDL(opts)
def fmtd_args(width, args)
def setActType(self, act)
def find_opt_list(opts, value, default)
def setVersion(self, version)
def __init__(self, mod_name, mod)
def setCategory(self, vategory)
def setCompType(self, comp_type)
def MakeModuleProfile(opts)
def MakeDataPort(opts, port_type)
def setValue(self, member, value)
def setVendor(self, vendor)
def setMaxInst(self, max_inst)
def MakePortInterface(opts, port_type)
def check_args(self, args)