rtc-template.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # -*- python -*-
3 #
4 # @file rtc-template
5 # @brief rtc-template RTComponent source code generator tool
6 # @date $Date: 2007-10-09 07:19:15 $
7 # @author Noriaki Ando <n-ando@aist.go.jp>
8 #
9 # Copyright (C) 2004-2008
10 # Task-intelligence Research Group,
11 # Intelligent Systems Research Institute,
12 # National Institute of
13 # Advanced Industrial Science and Technology (AIST), Japan
14 # All rights reserved.
15 #
16 # $Id: rtc-template 1815 2010-01-27 20:26:57Z n-ando $
17 #
18 
19 import getopt, sys
20 import time
21 import re
22 import os
23 import yaml
24 import copy
25 
26 default_profile="""
27 rtcProfile:
28  version: "1.0"
29  id: # RTC:SampleVendor.SampleCategory.SampleComponent:1.0.0
30  basicInfo:
31  name: ""
32  description: ""
33  version: 1.0.0
34  vendor: SampleVendor
35  category: ""
36  componentType: STATIC
37  activityType: PERIODIC
38  componentKind: DataFlowComponent
39  maxInstances: 1
40  abstract: ""
41  executionRate: 1000.0
42  executionType: PeriodicExecutionContext
43  creationDate:
44  day: ""
45  hour: ""
46  minute: ""
47  month: ""
48  second: ""
49  year: ""
50  updateDate:
51  day: 17
52  hour: 14
53  minute: 0
54  month: 4
55  second: 0
56  year: 2008
57  "rtcDoc::doc":
58  algorithm: ""
59  creator: ""
60  description: ""
61  inout: ""
62  license: ""
63  reference: ""
64  "rtcExt::versionUpLog":
65  - "2008/04/18 14:00:00:Ver1.0"
66  - "2008/04/18 17:00:00:Ver1.1"
67  language:
68  java:
69  library:
70  - library1
71  actions:
72  onAborting:
73  "rtcDoc::doc":
74  description: on_aborting description
75  postCondition: on_aborting Post_condition
76  preCondition: on_aborting Pre_condition
77  implemented: true
78  onActivated:
79  "rtcDoc::doc":
80  description: on_activated description
81  postCondition: on_activated Post_condition
82  preCondition: on_activated Pre_condition
83  implemented: true
84  onDeactivated:
85  "rtcDoc::doc":
86  description: on_deactivated description
87  postCondition: on_deactivated Post_condition
88  preCondition: on_deactivated Pre_condition
89  onError:
90  "rtcDoc::doc":
91  description: on_error description
92  postCondition: on_error Post_condition
93  preCondition: on_error Pre_condition
94  onExecute:
95  "rtcDoc::doc":
96  description: on_execute description
97  postCondition: on_execute Post_condition
98  preCondition: on_execute Pre_condition
99  onFinalize:
100  "rtcDoc::doc":
101  description: on_finalize description
102  postCondition: on_finalize Post_condition
103  preCondition: on_finalize Pre_condition
104  onInitialize:
105  "rtcDoc::doc":
106  description: on_initialize description
107  postCondition: on_initialize Post_condition
108  preCondition: on_initialize Pre_condition
109  implemented: true
110  onRateChanged:
111  "rtcDoc::doc":
112  description: on_rate_changed description
113  postCondition: on_rate_changed Post_condition
114  preCondition: on_rate_changed Pre_condition
115  onReset:
116  "rtcDoc::doc":
117  description: on_reset description
118  postCondition: on_reset Post_condition
119  preCondition: on_reset Pre_condition
120  onShutdown:
121  "rtcDoc::doc":
122  description: on_shutdown description
123  postCondition: on_shutdown Post_condition
124  preCondition: on_shutdown Pre_condition
125  implemented: true
126  onStartup:
127  "rtcDoc::doc":
128  description: on_startup description
129  postCondition: on_startup Post_condition
130  preCondition: on_startup Pre_condition
131  onStateUpdate:
132  "rtcDoc::doc":
133  description: on_state_update description
134  postCondition: on_state_update Post_condition
135  preCondition: on_state_update Pre_condition
136  dataPorts:
137  -
138  name: inport1
139  portType: DataInPort
140  type: "RTC::TimedLong"
141  interfaceType: CorbaPort
142  dataflowType: "Push,Pull"
143  subscriprionType: "Periodic,New,Flush"
144  idlFile: DataPort1.idl
145  "rtcDoc::doc":
146  type: In1Type
147  description: In1Description
148  number: In1Number
149  occerrence: In1Occerrence
150  operation: In1Operation
151  semantics: In1Semantics
152  unit: In1Unit
153  "rtcExt::position": LEFT
154  "rtcExt::varname": In1Var
155  servicePorts:
156  -
157  name: SrvPort1
158  "rtcDoc::doc":
159  description: ServicePort1 description
160  ifdescription: ServicePort1 I/F description
161  "rtcExt::position": LEFT
162  serviceInterface:
163  -
164  direction: Provided
165  "rtcDoc::doc":
166  description: if1 Description
167  docArgument: if1 Argument
168  docException: if1 Exception
169  docPostCondition: if1 PostCond
170  docPreCondition: if1 PreCond
171  docReturn: if1 Return
172  idlFile: IF1Idlfile.idl
173  instanceName: IF1Instance
174  name: S1IF1
175  path: IF1SearchPath
176  type: IF1Type
177  varname: IF1VarName
178  configurationSet:
179  configuration:
180  -
181  name: config1
182  type: int
183  varname: var1
184  defaultValue: ""
185  "rtcDoc::doc":
186  constraint: config_constraint1
187  dataname: dataname1
188  defaultValue: default1
189  description: config_Desc1
190  range: config_range1
191  unit: config_unit1
192  parameters:
193  -
194  defaultValue: param_def1
195  name: param1
196  -
197  defaultValue: param_def2
198  name: param2
199 
200 """
201 
202 
203 class Struct:
204  def __init__(self):
205  return
206 
207 libdir_path = os.popen("rtm-config --libdir", "r").read().split("\n")
208 if libdir_path[0] != '':
209  pyhelper_path = libdir_path[0] + "/py_helper"
210  sys.path.append(pyhelper_path)
211 else:
212  pyhelper_path = os.environ['OPENHRP_SDK_ROOT'] + "/utils/rtc-template"
213  sys.path.append(pyhelper_path)
214 
215 # Option format
216 opt_args_fmt = ["help",
217  "module-name=",
218  "module-type=",
219  "module-desc=",
220  "module-version=",
221  "module-vendor=",
222  "module-category=",
223  "module-comp-type=",
224  "module-act-type=",
225  "module-max-inst=",
226  "module-lang=",
227  "config=",
228  "inport=",
229  "outport=",
230  "service=",
231  "service-idl=",
232  "consumer=",
233  "consumer-idl=",
234  "idl-include=",
235  "backend="]
236 
237 
238 def usage_short():
239  """
240  Help message
241  """
242  print """
243 Usage: rtc-template [OPTIONS]
244 
245 Options:
246 
247  [-h] Print short help.
248  [--help] Print details help.
249  [--backend[=backend] or -b] Specify template code generator.
250  [--module-name[=name]] Your module name.
251  [--module-desc[=description]] Module description.
252  [--module-version[=version]] Module version.
253  [--module-vendor[=vendor]] Module vendor.
254  [--module-category[=category]] Module category.
255  [--module-comp-type[=component_type]] Component type.
256  [--module-act-type[=activity_type]] Component's activity type.
257  [--module-max-inst[=max_instance]] Number of maximum instance.
258  [--module-lang[=language]] Language.
259  [--config[=ParamName:Type:Default]] Configuration variable.
260  [--inport[=PortName:Type]] InPort's name and type.
261  [--outport[=PortName:Type]] OutPort's name and type
262  [--service[=PortName:Name:Type]] Service Provider Port
263  [--service-idl[=IDL_file]] IDL file name for service
264  [--consumer[=PortName:Name:Type]] Service Consumer Port
265  [--consumer-idl[=IDL_file]] IDL file name for consumer
266  [--idl-include=[path]] Search path for IDL compile
267 
268 """
269 def usage_long():
270  """
271  Help message
272  """
273  print """
274  --output[=output_file]:
275  Specify base name of output file. If 'XXX' is specified,
276  C++ source codes XXX.cpp, XXX.h, XXXComp.cpp Makefile.XXX is generated.
277 
278  --module-name[=name]:
279  Your component's base name. This string is used as module's
280  name and component's base name. A generated new component
281  class name is also names as this RTC_MODULE_NAME.
282  Only alphabetical and numerical characters are acceptable.
283 
284  --module-desc[=description]:
285  Short description. If space characters are included, string should be
286  quoted.
287 
288  --module-version[=version]:
289  Your module version. ex. 1.0.0
290 
291  --module-vendor[=vendor]:
292  Vendor's name of this component.
293 
294  --module-category[=category]:
295  This component module's category. ex. Manipulator MobileRobot, etc...
296 
297  --module-comp-type[=component_type]:
298  Specify component type.
299  'STATIC', 'UNIQUE', 'COMMUTATIVE' are acceptable.
300 
301  --module-act-type[=activity_type]:
302  Specify component activity's type.
303  'PERIODIC', 'SPORADIC', 'EVENT_DRIVEN' ace acceptable.
304 
305  --module-max-inst[=max_instance]:
306  Specify maximum number of component instance.
307 
308  --config=[ParamName:Type:Default]:
309  Specify configuration value. The 'ParamName' is used as the
310  configuration value identifier. This character string is also used as
311  variable name in the source code. The 'Type' is type of configuration
312  value. The type that can be converted to character string is allowed.
313  In C++ language, the type should have operators '<<' and '>>' that
314  are defined as
315  'istream& operator<<(Type)'
316  and
317  'ostream& operator>>(Type)'.
318 
319  --inport=[PortName:Type]:
320  Specify InPort's name and type. 'PortName' is used as this InPort's
321  name. This string is also used as variable name in soruce code.
322  'Type' is InPort's variable type. The acceptable types are,
323  Timed[ Short | Long | UShort | ULong | Float | Double | Char | Boolean
324  | Octet | String ] and its sequence types.
325 
326  --outport=[PortName:Type]:
327  Specify OutPort's name and type. 'PortName' is used as this OutPort's
328  name. This string is also used as variable name in soruce code.
329  'Type' is OutPort's variable type. The acceptable types are,
330  Timed[ Short | Long | UShort | ULong | Float | Double | Char | Boolean
331  | Octet | String ] and its sequence types.
332 
333  --service=[PortName:Name:Type]:
334  Specify service name, type and port name.
335  PortName: The name of Port to which the interface belongs.
336  This name is used as CorbaPort's name.
337  Name: The name of the service interface. This name is used as
338  the name of the interface, instance name and variable name.
339  Type: The type of the serivce interface.
340  This name is used as type name of the service.
341 
342  --service-idl=[IDL filename]:
343  Specify IDL file of service interface.
344  For simplicity, please define one interface in one IDL file, although
345  this IDL file can include two or more interface definition,
346 
347  --consumer=[PortName:Name:Type]:
348  Specify consumer name, type and port name.
349  PortName: The name of Port to which the consumer belongs.
350  This name is used as CorbaPort's name.
351  Name: The name of the consumer. This name is used as
352  the name of the consumer, instance name and variable name.
353  Type: The serivce interface type that is required by the consumer.
354  This name is used as type name of the consumer.
355 
356  --consumer-idl=[IDL filename]:
357  Specify IDL file of service consumer.
358  For simplicity, please define one interface in one IDL file, although
359  this IDL file can include two or more interface definition,
360 
361 
362 Example:
363  rtc-template -bcxx \\
364  --module-name=Sample --module-desc='Sample component' \\
365  --module-version=0.1 --module-vendor=AIST --module-category=Generic \\
366  --module-comp-type=DataFlowComponent --module-act-type=SPORADIC \\
367  --module-max-inst=10 \\
368  --config=int_param0:int:0 --config=int_param1:int:1 \\
369  --config=double_param0:double:3.14 --config=double_param1:double:9.99 \\
370  --config="str_param0:std::string:hoge" \\
371  --config="str_param1:std::string:foo" \\
372  --inport=Ref:TimedFloat --inport=Sens:TimedFloat \\
373  --outport=Ctrl:TimedDouble --outport=Monitor:TimedShort \\
374  --service=MySvcPort:myservice0:MyService \\
375  --consumer=YourSvcPort:yourservice0:YourService \\
376  --service-idl=MyService.idl --consumer-idl=YourService.idl
377 
378 """
379  return
380 
381 def usage():
382  usage_short()
383  usage_long()
384  return
385 
386 
387 def CreateBasicInfo(opts):
388  """
389  MakeModuleProfile
390 
391  Create ModuleProfile list from command options
392  """
393  mapping = {
394  'name': 'name',
395  'desc': 'description',
396  'version': 'version',
397  'vendor': 'vendor',
398  'category': 'category',
399  'comp-type': 'componentType',
400  'act-type': 'activityType',
401  'type': 'componentKind',
402  'max-inst': 'maxInstances'
403  }
404  # default "basicInfo"
405  prof = {
406  "name": "",
407  "description": "",
408  "version": "1.0.0",
409  "vendor": "",
410  "category": "",
411  "componentType": "STATIC",
412  "activityType": "PERIODIC",
413  "componentKind": "DataFlowComponent",
414  "maxInstances": "1",
415  "abstract": "",
416  "executionRate": "1000.0",
417  "executionType": "PeriodicExecutionContext",
418  "creationDate":
419  {
420  "day": "",
421  "hour": "",
422  "minute": "",
423  "month": "",
424  "second": "",
425  "year": ""
426  },
427  "updateDate":
428  {
429  "year": "",
430  "month": "",
431  "day": "",
432  "hour": "",
433  "minute": "",
434  "second": "",
435  },
436  "rtcDoc::doc":
437  {
438  "algorithm": "",
439  "creator": "",
440  "description": "",
441  "inout": "",
442  "license": "",
443  "reference": ""
444  },
445  "rtcExt::versionUpLog": []
446  }
447 
448  # obtain --module-xxx options' values
449  for opt, arg in opts:
450  if opt.find("--module-") == 0:
451  var = opt.replace("--module-","")
452  if prof.has_key(mapping[var]):
453  prof[mapping[var]] = arg
454  # set creationDate
455  cDate = time.localtime()
456  i = 0
457  cDateKey = ['year', 'month', 'day', 'hour', 'minute', 'second']
458  for key in cDateKey:
459  prof["creationDate"][key] = cDate[i]
460  i += 1
461  # check empty values
462  empty = []
463  for key in prof.keys():
464  if prof[key] == "":
465  empty.append(key)
466 
467  return prof
468 
469 def CreateActions(opts):
470  actnames = [
471  "onInitialize",
472  "onFinalize",
473  "onActivated",
474  "onDeactivated",
475  "onAborting",
476  "onError",
477  "onReset",
478  "onExecute",
479  "onStateUpdate",
480  "onShutdown",
481  "onStartup",
482  "onRateChanged",
483  ]
484 
485  actions = {}
486  for a in actnames:
487  actions[a] = {
488  "rtcDoc::doc": {
489  "description": a + " description",
490  "postCondition": a + " Post_condition",
491  "preCondition": a + " Pre_condition"
492  },
493  "implemented": True
494  }
495  return actions
496 
497 def CreateConfigurationSet(opts):
498  """
499  MakeConfigurationParameters
500 
501  Create Configuration list from command options
502  """
503  prof_list = []
504  prof = {
505  "name": "",
506  "type": "",
507  "varname": "",
508  "defaultValue": "",
509  "rtcDoc::doc":
510  {
511  "type": "type", # type
512  "constraint": "constraint",
513  "dataname": "dataname",
514  "defaultValue": "default",
515  "description": "description",
516  "range": "range",
517  "unit": "unit"
518  }
519  }
520  for opt, arg in opts:
521  if opt == ("--config"):
522  try:
523  # For C++ scope resolution operator
524  arg = re.sub("::", "@@", arg)
525  name, type, default = arg.split(":")
526  name = re.sub("@@", "::", name)
527  type = re.sub("@@", "::", type)
528  default = re.sub("@@", "::", default)
529  except:
530  sys.stderr.write("Invalid option: " \
531  + opt \
532  + "=" \
533  + arg)
534  tmp = copy.deepcopy(prof)
535  tmp["name"] = name
536  tmp["varname"] = name
537  tmp["l_name"] = name.lower()
538  tmp["u_name"] = name.upper()
539  tmp["type"] = type
540  tmp["defaultValue"] = default
541  tmp["rtcDoc::doc"]["defaultValue"] = default
542  prof_list.append(tmp)
543  return {'configuration': prof_list}
544 
545 
546 def CreateDataPorts(opts):
547  """
548  MakePortProfile
549 
550  Create PortProfile list from command options
551  """
552  prof_list = []
553  prof = {
554  "name": "",
555  "portType": "",
556  "type": "",
557  "interfaceType": "CorbaPort",
558  "dataflowType": "Push,Pull",
559  "subscriptionType": "Periodic,New,Flush",
560  "idlFile": "",
561  "rtcDoc::doc":
562  {
563  "type": "",
564  "description": "",
565  "number": "",
566  "occerrence": "",
567  "operation": "",
568  "semantics": "",
569  "unit": ""
570  },
571  "rtcExt::position": "",
572  "rtcExt::varname": ""
573  }
574  cnt = 0
575  portType = {"--inport": "DataInPort", "--outport": "DataOutPort"}
576  position = {"--inport": "LEFT", "--outport": "RIGHT"}
577  for opt, arg in opts:
578  if opt == "--inport" or opt == "--outport":
579  try:
580  arg = re.sub("::", "@@", arg)
581  name, type = arg.split(":")
582  name = re.sub("@@", "::", name)
583  type = re.sub("@@", "::", type)
584  except:
585  sys.stderr.write("Invalid option: " \
586  + opt \
587  + "=" \
588  + arg)
589  tmp = copy.deepcopy(prof)
590  tmp["name"] = name
591  tmp["portType"] = portType[opt]
592  tmp["type"] = type
593  tmp["num"] = cnt
594  tmp["rtcDoc::doc"]["type"] = type
595  tmp["rtcDoc::doc"]["number"] = cnt
596  tmp["rtcExt::varname"] = name
597  tmp["rtcExt::position"] = position[opt]
598  prof_list.append(tmp)
599  cnt += 1
600  return prof_list
601 
602 
603 def CreateServicePorts(opts):
604  """
605  MakePortInterface
606 
607  Create Port interface profile list from command options
608  """
609  prof_list = []
610 
611  prof = {
612  "name": "",
613  "rtcDoc::doc":
614  {
615  "description": "",
616  "ifdescription": "",
617  },
618  "rtcExt::position": "LEFT",
619  "serviceInterface": []
620  }
621  ifprof = {
622  "name": "",
623  "type": "",
624  "direction": "",
625  "varname": "",
626  "instanceName": "",
627  "idlFile": "",
628  "path": "",
629  "rtcDoc::doc":
630  {
631  "description": "",
632  "docArgument": "",
633  "docException": "",
634  "docPostCondition": "",
635  "docPreCondition": "",
636  "docReturn": ""
637  }
638  }
639 
640  def findport(prof_list, port_name):
641  for p in prof_list:
642  if p["name"] == port_name:
643  return p
644  return None
645  def lr(port):
646  cnt = {"Provided": 0, "Required": 0}
647  for ifprof in port["serviceInterface"]:
648  cnt[ifprof["direction"]] += 1
649  if cnt["Provided"] < cnt["Required"]:
650  return "LEFT"
651  else:
652  return "RIGHT"
653  cnt = 0
654  ifType = {"--service": "Provided", "--consumer": "Required"}
655  for opt, arg in opts:
656  if opt == "--service" or opt == "--consumer":
657  try:
658  arg = re.sub("::", "@@", arg)
659  portname, name, type = arg.split(":")
660  portname = re.sub("@@", "::", portname)
661  name = re.sub("@@", "::", name)
662  type = re.sub("@@", "::", type)
663  except:
664  sys.stderr.write("Invalid option: " \
665  + opt \
666  + "=" \
667  + arg)
668  port = findport(prof_list, portname)
669  if port == None:
670  port = copy.deepcopy(prof)
671  port["name"] = portname
672  prof_list.append(port)
673 
674  tmp = copy.deepcopy(ifprof)
675  tmp["name"] = name
676  tmp["type"] = type
677  tmp["direction"] = ifType[opt]
678  tmp["varname"] = name
679  tmp["instanceName"] = name
680  idlfname = FindIdlFile(opts, type)
681  if idlfname == None:
682  print "Error:"
683  print "IDL file not found for a interface: ", type
684  sys.exit(1)
685  tmp["idlFile"] = idlfname
686  port["serviceInterface"].append(tmp)
687  port["rtcExt::position"] = lr(port)
688  cnt += 1
689  return prof_list
690 
691 
692 def FindIdlFile(opts, ifname):
693  _re_text = "interface\s+" + ifname
694  for opt, arg in opts:
695  if opt == "--service-idl" or opt == "--consumer-idl":
696  fname = arg
697  fd = open(fname, "r")
698  if fd == None:
699  print "IDL file not found: ", arg
700  sys.exit(1)
701  t = fd.read()
702  if None != re.compile(_re_text).search(t):
703  fd.close()
704  return fname
705  fd.close()
706  return None
707 
708 def PickupIDLFiles(dict):
709  svcidls = {}
710  cnsidls = {}
711  for svc in dict["servicePorts"]:
712  for sif in svc["serviceInterface"]:
713  if sif["direction"] == "Provided":
714  svcidls[sif["idlFile"]] = ""
715  elif sif["direction"] == "Required":
716  if not svcidls.has_key(sif["idlFile"]):
717  cnsidls[sif["idlFile"]] = ""
718  dict["service_idl"] = []
719  dict["consumer_idl"] = []
720  for f in svcidls.keys():
721  idl = {}
722  idl["idl_fname"] = f
723  idl["idl_basename"] = f.split(".")[0]
724  dict["service_idl"].append(idl)
725  for f in cnsidls.keys():
726  idl = {}
727  idl["idl_fname"] = f
728  idl["idl_basename"] = f.split(".")[0]
729  dict["consumer_idl"].append(idl)
730  return
731 
732 def CreateId(dict):
733  dict["id"] = "RTC:" + \
734  dict["basicInfo"]["vendor"] + "." + \
735  dict["basicInfo"]["category"] + "." + \
736  dict["basicInfo"]["name"] + ":" + \
737  dict["basicInfo"]["version"]
738 
739 def find_opt(opts, value, default):
740  for opt, arg in opts:
741  if opt.find(value) == 0:
742  return arg
743 
744  return default
745 
746 
747 def find_opt_list(opts, value, default):
748  list = []
749  if len(default) > 0:
750  list += default
751  for opt, arg in opts:
752  if opt == ("--" + value):
753  list.append(arg)
754  return list
755 
756 
757 class Backend:
758  def __init__(self, mod_name, mod):
759  self.mod = mod
760  self.obj = getattr(mod, mod_name)
761  self.mod_name = mod_name
762 
763 
764 class BackendLoader:
765  def __init__(self):
766  self.backends = {}
767  self.opts = []
768  self.available()
769  return
770 
771 
772  def available(self):
773  path_list = [pyhelper_path, "."]
774  for path in path_list:
775  for f in os.listdir(path):
776  if re.compile("_gen.py$").search(f):
777  mod_name = f.replace(".py", "")
778  opt_name = f.replace("_gen.py", "")
779  mod = __import__(mod_name, globals(), locals(), [])
780  try:
781  mod.usage()
782  be = Backend(mod_name, mod)
783  self.backends[opt_name] = be
784  except:
785  pass
786 
787  return self.backends
788 
789 
790  def check_args(self, args):
791  for opt in args:
792  if opt.find('-b') == 0:
793  backend_name = opt.replace("-b", "")
794  if self.backends.has_key(backend_name):
795  self.opts.append(backend_name)
796  else:
797  print "No such backend: ", backend_name
798  sys.exit(-1)
799  elif opt.find('--backend=') == 0:
800  backend_name = opt.replace("--backend=", "")
801  if self.backends.has_key(backend_name):
802  self.opts.append(backend_name)
803  else:
804  print "No such backend: ", backend_name
805  sys.exit(-1)
806  return self.opts
807 
808 
809  def get_opt_fmts(self):
810  fmts = []
811  for be in self.opts:
812  fmts += self.backends[be].mod.get_opt_fmt()
813  return fmts
814 
815 
816  def usage_available(self):
817  print "The following backends are available."
818  space = 10
819  for key in self.backends:
820  desc = self.backends[key].mod.description()
821  print " -b" + key + ("." * (space - len(key))) + desc
822  print """
823 Backend [xxx] specific help can be available by the following options.
824  -bxxx --help|-h or --backend=xxx --help|-h
825  """
826  return
827 
828 
829  def usage(self):
830  for be in self.opts:
831  print self.backends[be].mod.usage()
832  print ""
833  return
834 
835  def usage_short(self):
836  for be in self.opts:
837  print self.backends[be].mod.usage_short()
838  print ""
839  return
840 
841 
842  def generate_code(self, data, opts):
843  for be in self.opts:
844  self.backends[be].obj(data, opts).print_all()
845  return
846 
847 
848 def fmtd_args(width, args):
849  arg_fmt = [""]
850  w = 0
851  line = 0
852  for a in args:
853  w += len(a) + 1
854  if w > width:
855  w = len(a) + 1
856  line += 1
857  arg_fmt.append("")
858  arg_fmt[line] += a + " "
859  return arg_fmt
860 
861 
862 
863 def main():
864  global opt_args_fmt
865 
866  backends = BackendLoader()
867  backends.check_args(sys.argv[1:])
868  opt_args_fmt += backends.get_opt_fmts()
869 
870  try:
871  opts, args = getopt.getopt(sys.argv[1:], "b:ho:v", opt_args_fmt)
872  except getopt.GetoptError:
873  print "Error: Invalid option.", getopt.GetoptError
874  usage_short()
875  backends.usage_available()
876  sys.exit(-1)
877 
878  if not opts:
879  usage_short()
880  backends.usage_available()
881  sys.exit(-1)
882 
883  output = None
884  verbose = False
885  output_cxx = False
886  output_python = False
887 
888  for o, a in opts:
889  if o == "-v":
890  verbose = True
891  if o in ("-h"):
892  usage_short()
893  backends.usage_available()
894  backends.usage_short()
895  sys.exit(0)
896  if o in ("--help"):
897  usage()
898  backends.usage_available()
899  backends.usage()
900  sys.exit(0)
901  if o in ("-o", "--output"):
902  output = a
903  # ...
904 
905  prefix = os.popen("rtm-config --prefix", "r").read().split("\n")
906  idl_inc = []
907  if prefix[0] != '':
908  idl_inc.append(prefix[0] + "/include/rtm/idl")
909  idl_inc.append(prefix[0] + "/include/rtm")
910  idl_inc.append(".")
911 
912  # Create dictionary for ezt
913  data = {'basicInfo': CreateBasicInfo(opts),
914  'actions': CreateActions(opts),
915  'configurationSet': CreateConfigurationSet(opts),
916  'dataPorts': CreateDataPorts(opts),
917  'servicePorts': CreateServicePorts(opts),
918  'args': sys.argv,
919  'fmtd_args': fmtd_args(70, sys.argv),
920  'idl_include': idl_inc
921  }
922  CreateId(data)
923  PickupIDLFiles(data)
924 
925  if not data.has_key('fname'):
926  data['fname'] = data['basicInfo']['name']
927  backends.generate_code(data, opts)
928 
929  import README_gen
930  readme = README_gen.README_gen(data)
931  readme.print_all()
932  import profile_gen
933  profile = profile_gen.profile_gen(data)
934  profile.print_all()
935  return
936 
937 
938 if __name__ == "__main__":
939  main()
def fmtd_args(width, args)
def CreateDataPorts(opts)
def find_opt(opts, value, default)
def FindIdlFile(opts, ifname)
def __init__(self, mod_name, mod)
def CreateBasicInfo(opts)
def CreateServicePorts(opts)
def generate_code(self, data, opts)
def find_opt_list(opts, value, default)
def CreateActions(opts)
def CreateConfigurationSet(opts)
def PickupIDLFiles(dict)


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Sat Apr 13 2019 02:14:25