Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 default_orb="omniORB"
00018 orb=default_orb
00019 default_port="2809"
00020
00021
00022 import sys,os,platform
00023
00024
00025 def get_hostname():
00026 sysinfo = platform.uname()
00027 hostname = sysinfo[1]
00028 return str(hostname)
00029
00030
00031 def get_tempdir():
00032 temp_dir = os.environ.get('TEMP', "")
00033 if temp_dir != "":
00034 return temp_dir
00035
00036 temp_dir = os.environ.get('TMP', "")
00037 if temp_dir != "":
00038 return temp_dir
00039
00040 return os.getcwd()
00041
00042
00043 def find_nscmd(ns_cmd, ns_env = ""):
00044 if sys.platform == "win32":
00045 ns_path = os.path.join(sys.exec_prefix,ns_cmd)
00046 else:
00047 ns_path = os.path.join(sys.exec_prefix,'bin',ns_cmd)
00048
00049 if os.path.exists(ns_path):
00050 return ns_path
00051
00052 if ns_env != "":
00053 ns_path = os.environ.get(ns_env) + ns_cmd
00054 if os.path.exists(ns_path):
00055 return ns_path
00056
00057 sys_paths = os.environ.get('PATH').split(";")
00058 for sys_path in sys_paths:
00059 ns_path = sys_path + ns_cmd
00060 if os.path.exists(ns_path):
00061 return ns_path
00062 return None
00063
00064
00065 def del_file(file_path):
00066 if sys.platform == "win32":
00067 delcmd = "del /F "
00068 else:
00069 delcmd = "rm -f "
00070 delcmd += file_path
00071 return os.system(delcmd)
00072
00073
00074 def usage():
00075 print "Usage: python rtm-naming.py port_number"
00076
00077
00078 def omninames(port = "", endpoint = ""):
00079 hostname = get_hostname()
00080 log_path = get_tempdir()
00081
00082 log_fname = "omninames-" + hostname + ".log"
00083 log_file = os.path.join(log_path, log_fname)
00084
00085 if os.path.exists(log_file):
00086 del_file(log_file)
00087
00088 bak_fname = "omninames-" + hostname + ".bak"
00089 bak_file = os.path.join(log_path, bak_fname)
00090
00091 if os.path.exists(bak_file):
00092 del_file(bak_file)
00093
00094 if port == "":
00095 port = default_port
00096
00097 print "Starting omniORB omniNames: ", hostname, ":", port
00098
00099 if sys.platform == "win32":
00100 omniNames = find_nscmd("omniNames.exe", "OMNI_ROOT")
00101 else:
00102 omniNames = find_nscmd("omniNames")
00103
00104 if not omniNames:
00105 print "Not found omniNames."
00106 sys.exit()
00107
00108 cmd = omniNames
00109 cmd += " -start " + str(port)
00110 cmd += " -logdir \"" + str(log_path) + "\""
00111 print cmd
00112 os.system(cmd)
00113
00114
00115 if __name__ == "__main__":
00116 try:
00117 if len(sys.argv) == 2:
00118 port = int(sys.argv[1])
00119
00120 if sys.argv[1] == "-u" or sys.argv[1] == "-h" or sys.argv[1] == "--help":
00121 usage()
00122 except:
00123 usage()
00124 sys.exit(1)
00125
00126 if orb == "omniORB":
00127 omninames()