ManagerConfig.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # -*- coding: euc-jp -*-
3 
4 
16 
17 
18 import sys
19 import os
20 import re
21 import getopt
22 import platform
23 
24 import OpenRTM_aist
25 
26 
27 
83  """
84  """
85 
86 
92  config_file_path = ["./rtc.conf",
93  "/etc/rtc.conf",
94  "/etc/rtc/rtc.conf",
95  "/usr/local/etc/rtc.conf",
96  "/usr/local/etc/rtc/rtc.conf",
97  None]
98 
99 
100 
108  config_file_env = "RTC_MANAGER_CONFIG"
109 
110 
111 
131  def __init__(self, argv=None):
132 
133  self._configFile = ""
135  self._isMaster = False
136  if argv:
137  self.init(argv)
138 
139 
140 
169  def init(self, argv):
170  self.parseArgs(argv)
171  return
172 
173 
188  def configure(self, prop):
189  prop.setDefaults(OpenRTM_aist.default_config)
190  if self.findConfigFile():
191  try:
192  fd = file(self._configFile,"r")
193  prop.load(fd)
194  fd.close()
195  except:
196  print OpenRTM_aist.Logger.print_exception()
197 
198  self.setSystemInformation(prop)
199  if self._isMaster:
200  prop.setProperty("manager.is_master","YES")
201 
202  # Properties from arguments are marged finally
203  prop.mergeProperties(self._argprop)
204  return prop
205 
206 
207 
229 
230 
231 
254  def parseArgs(self, argv):
255  try:
256  opts, args = getopt.getopt(argv[1:], "adlf:o:p:")
257  except getopt.GetoptError:
258  print OpenRTM_aist.Logger.print_exception()
259  return
260 
261  for opt, arg in opts:
262  if opt == "-a":
263  self._argprop.setProperty("manager.corba_servant","NO")
264 
265  if opt == "-f":
266  self._configFile = arg
267 
268  if opt == "-l":
269  pass
270 
271  if opt == "-o":
272  pos = arg.find(":")
273  if pos > 0:
274  self._argprop.setProperty(arg[:pos],arg[pos+1:])
275 
276  if opt == "-p":
277  num = [-1]
278  ret = OpenRTM_aist.stringTo(num, arg)
279  if ret:
280  arg_ = ":" + arg
281  self._argprop.setProperty("corba.endpoints",arg_)
282 
283  if opt == "-d":
284  self._isMaster = True
285  pass
286 
287  return
288 
289 
290 
326  def findConfigFile(self):
327  if self._configFile != "":
328  if not self.fileExist(self._configFile):
329  print OpenRTM_aist.Logger.print_exception()
330  return False
331  return True
332 
333  env = os.getenv(self.config_file_env)
334  if env:
335  if self.fileExist(env):
336  self._configFile = env
337  return True
338 
339  i = 0
340  while (self.config_file_path[i]):
341  if self.fileExist(self.config_file_path[i]):
342  self._configFile = self.config_file_path[i]
343  return True
344  i += 1
345 
346  return False
347 
348 
349 
378  def setSystemInformation(self, prop):
379  if sys.platform == 'win32':
380  sysinfo = platform.uname()
381  else:
382  sysinfo = os.uname()
383 
384  prop.setProperty("manager.os.name", sysinfo[0])
385  prop.setProperty("manager.os.hostname", sysinfo[1])
386  prop.setProperty("manager.os.release", sysinfo[2])
387  prop.setProperty("manager.os.version", sysinfo[3])
388  prop.setProperty("manager.os.arch", sysinfo[4])
389  prop.setProperty("manager.pid", os.getpid())
390 
391  return prop
392 
393 
394 
415  def fileExist(self, filename):
416  try:
417  fp = open(filename)
418  except:
419  return False
420  else:
421  fp.close()
422  return True
423 
424  return False
425 
426 
def findConfigFile(self)
Find the configuration file.
def __init__(self, argv=None)
ManagerConfig constructor.
Manager configuration class.
The Properties class represents a persistent set of properties.
Definition: Properties.py:83
list config_file_path
The default configuration file path for manager.
string config_file_env
The environment variable to distinguish the default configuration file path.
def setSystemInformation(self, prop)
Set system information.
def configure(self, prop)
Specify the configuration information to the Property.
def parseArgs(self, argv)
Get configuration value.
def init(self, argv)
Initialization.
def fileExist(self, filename)
Check the file existence.


openrtm_aist_python
Author(s): Shinji Kurihara
autogenerated on Mon Feb 28 2022 23:01:06