rtm-naming.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # -*- Python -*-
3 #
4 # @file rtm-naming.py
5 # @brief OpenRTM-aist name server launcher
6 # @date $Date: 2007/10/25 $
7 # @author Noriaki Ando <n-ando@aist.go.jp> and Shinji Kurihara
8 #
9 # Copyright (C) 2003-2009
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 
17 default_orb="omniORB"
18 orb=default_orb
19 default_port="2809"
20 
21 
22 import sys,os,platform
23 
24 
26  sysinfo = platform.uname()
27  hostname = sysinfo[1]
28  return str(hostname)
29 
30 
32  temp_dir = os.environ.get('TEMP', "")
33  if temp_dir != "":
34  return temp_dir
35 
36  temp_dir = os.environ.get('TMP', "")
37  if temp_dir != "":
38  return temp_dir
39 
40  return os.getcwd()
41 
42 
43 def find_nscmd(ns_cmd, ns_env = ""):
44  if sys.platform == "win32":
45  ns_path = os.path.join(sys.exec_prefix,ns_cmd)
46  else:
47  ns_path = os.path.join(sys.exec_prefix,'bin',ns_cmd)
48 
49  if os.path.exists(ns_path):
50  return ns_path
51 
52  if ns_env != "":
53  ns_path = os.environ.get(ns_env) + ns_cmd
54  if os.path.exists(ns_path):
55  return ns_path
56 
57  sys_paths = os.environ.get('PATH').split(";")
58  for sys_path in sys_paths:
59  ns_path = sys_path + ns_cmd
60  if os.path.exists(ns_path):
61  return ns_path
62  return None
63 
64 
65 def del_file(file_path):
66  if sys.platform == "win32":
67  delcmd = "del /F "
68  else:
69  delcmd = "rm -f "
70  delcmd += file_path
71  return os.system(delcmd)
72 
73 
74 def usage():
75  print "Usage: python rtm-naming.py port_number"
76 
77 
78 def omninames(port = "", endpoint = ""):
79  hostname = get_hostname()
80  log_path = get_tempdir()
81 
82  log_fname = "omninames-" + hostname + ".log"
83  log_file = os.path.join(log_path, log_fname)
84 
85  if os.path.exists(log_file):
86  del_file(log_file)
87 
88  bak_fname = "omninames-" + hostname + ".bak"
89  bak_file = os.path.join(log_path, bak_fname)
90 
91  if os.path.exists(bak_file):
92  del_file(bak_file)
93 
94  if port == "":
95  port = default_port
96 
97  print "Starting omniORB omniNames: ", hostname, ":", port
98 
99  if sys.platform == "win32":
100  omniNames = find_nscmd("omniNames.exe", "OMNI_ROOT")
101  else:
102  omniNames = find_nscmd("omniNames")
103 
104  if not omniNames:
105  print "Not found omniNames."
106  sys.exit()
107 
108  cmd = omniNames
109  cmd += " -start " + str(port)
110  cmd += " -logdir \"" + str(log_path) + "\""
111  print cmd
112  os.system(cmd)
113 
114 
115 if __name__ == "__main__":
116  try:
117  if len(sys.argv) == 2:
118  port = int(sys.argv[1])
119 
120  if sys.argv[1] == "-u" or sys.argv[1] == "-h" or sys.argv[1] == "--help":
121  usage()
122  except:
123  usage()
124  sys.exit(1)
125 
126  if orb == "omniORB":
127  omninames()
def split(input, delimiter)
Split string by delimiter.
Definition: StringUtil.py:323
def find_nscmd(ns_cmd, ns_env="")
Definition: rtm-naming.py:43
def omninames(port="", endpoint="")
Definition: rtm-naming.py:78


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