rtcprof.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # -*- Python -*-
3 
4 
17 
18 import sys
19 import os
20 
21 import OpenRTM_aist
22 
23 def main():
24 
25  if len(sys.argv) != 2:
26  print "usage: "
27  print sys.argv[0], " *.py "
28  return
29 
30  # file name with full path
31  fullname = sys.argv[1]
32  # directory name
33  dirname = os.path.dirname(sys.argv[1])
34  tmp_path = sys.path
35  sys.path.append(dirname)
36 
37  # basename
38  basename = os.path.basename(sys.argv[1])
39  # classname
40  classname = basename.split(".")[0].lower()
41 
42  opts =[]
43  opts.append("dummy")
44  opts.append("-o")
45  opts.append("manager.modules.load_path: " + dirname)
46  opts.append("-o")
47  opts.append("logger.enable:NO")
48  opts.append("-o")
49  opts.append("manager.corba_servant:NO")
50 
51  # Manager initialization
52  OpenRTM_aist.Manager.init(opts)
53  mgr = OpenRTM_aist.Manager.instance()
54 
55  # loaded profile = old profiles - new profiles
56  # for old
57  oldp = mgr.getFactoryProfiles()
58 
59  # for new
60  comp_spec_name = classname+"_spec"
61 
62  try:
63  imp_file = __import__(basename.split(".")[0])
64  except:
65  sys.path = tmp_path
66  return
67 
68  comp_spec = getattr(imp_file,comp_spec_name,None)
69  if not comp_spec:
70  sys.path = tmp_path
71  return
72 
73  newp = OpenRTM_aist.Properties(defaults_str=comp_spec)
74 
75  profs = []
76 
77  exists = False
78  for i in range(len(oldp)):
79  if oldp[i].getProperty("implementation_id") == newp.getProperty("implementation_id") and \
80  oldp[i].getProperty("type_name") == newp.getProperty("type_name") and \
81  oldp[i].getProperty("description") == newp.getProperty("description") and \
82  oldp[i].getProperty("version") == newp.getProperty("version"):
83  exists = True
84  if not exists:
85  profs.append(newp)
86 
87 
88  # loaded component profile have to be one
89  if len(profs) == 0:
90  print "Load failed. file name: ", fname
91  sys.path = tmp_path
93 
94  if len(profs) > 1:
95  print "One or more modules loaded."
96  sys.path = tmp_path
98 
99  keys = profs[0].propertyNames()
100  for key in keys:
101  print "%s:%s"%(key,profs[0].getProperty(key))
102 
103  sys.path = tmp_path
104  return
105 
106 if __name__ == "__main__":
107  main()
The Properties class represents a persistent set of properties.
Definition: Properties.py:83


openrtm_aist_python
Author(s): Shinji Kurihara
autogenerated on Thu Jun 6 2019 19:11:34