+ if verbose():
+ print
+ print " --- registered objects tree in Naming Service ---"
+ clt.showNS()
+ pass
+
+ if not args['gui'] or not args['session_gui']:
+ if args['shutdown_servers']:
+ class __utils__(object):
+ def __init__(self, port):
+ self.port = port
+ import killSalomeWithPort
+ self.killSalomeWithPort = killSalomeWithPort
+ return
+ def __del__(self):
+ self.killSalomeWithPort.killMyPort(self.port)
+ return
+ pass
+ args['shutdown_servers'] = __utils__(args['port'])
+ pass
+ pass
+
+ # run python scripts, passed via --execute option
+ toimport = []
+ if args.has_key('pyscript'):
+ if args.has_key('gui') and args.has_key('session_gui'):
+ if not args['gui'] or not args['session_gui']:
+ toimport = args['pyscript']
+
+ for srcname in toimport :
+ if srcname == 'killall':
+ clt.showNS()
+ killAllPorts()
+ sys.exit(0)
+ else:
+ if os.path.isabs(srcname):
+ if os.path.exists(srcname):
+ execScript(srcname)
+ elif os.path.exists(srcname+".py"):
+ execScript(srcname+".py")
+ else:
+ print "Can't execute file %s" % srcname
+ pass
+ else:
+ found = False
+ for path in [os.getcwd()] + sys.path:
+ if os.path.exists(os.path.join(path,srcname)):
+ execScript(os.path.join(path,srcname))
+ found = True
+ break
+ elif os.path.exists(os.path.join(path,srcname+".py")):
+ execScript(os.path.join(path,srcname+".py"))
+ found = True
+ break
+ pass
+ if not found:
+ print "Can't execute file %s" % srcname
+ pass
+ pass
+ pass
+ pass
+ pass
+ return clt
+
+def execScript(script_path):
+ print 'executing', script_path
+ sys.path.insert(0, os.path.dirname(script_path))
+ execfile(script_path,globals())
+ del sys.path[0]
+
+# -----------------------------------------------------------------------------
+
+def registerEnv(args, modules_list, modules_root_dir):
+ """
+ Register args, modules_list, modules_root_dir in a file
+ for further use, when SALOME is launched embedded in an other application.
+ """
+ if sys.platform == "win32":
+ fileEnv = os.getenv('TEMP')
+ else:
+ fileEnv = '/tmp/'
+
+ fileEnv += os.getenv('USER') + "_" + str(args['port']) \
+ + '_' + args['appname'].upper() + '_env'
+ fenv=open(fileEnv,'w')
+ pickle.dump((args, modules_list, modules_root_dir),fenv)
+ fenv.close()
+ os.environ["SALOME_LAUNCH_CONFIG"] = fileEnv
+
+# -----------------------------------------------------------------------------
+
+def no_main():
+ """Salome Launch, when embedded in other application"""
+ fileEnv = os.environ["SALOME_LAUNCH_CONFIG"]
+ fenv=open(fileEnv,'r')
+ args, modules_list, modules_root_dir = pickle.load(fenv)
+ fenv.close()
+ kill_salome(args)
+ from searchFreePort import searchFreePort
+ searchFreePort(args, 0)
+ clt = useSalome(args, modules_list, modules_root_dir)
+ return clt
+
+# -----------------------------------------------------------------------------
+
+def main():
+ """Salome launch as a main application"""
+ from salome_utils import getHostName
+ print "runSalome running on %s" % getHostName()
+ args, modules_list, modules_root_dir = setenv.get_config()
+
+ kill_salome(args)
+ save_config = True
+ if args.has_key('save_config'):
+ save_config = args['save_config']
+ # --
+ test = True
+ if args['wake_up_session']:
+ test = False
+ pass
+ if test:
+ from searchFreePort import searchFreePort
+ searchFreePort(args, save_config, args.get('useport'))
+ pass
+ # --
+ #setenv.main()
+ setenv.set_env(args, modules_list, modules_root_dir)
+ clt = useSalome(args, modules_list, modules_root_dir)
+ return clt,args
+
+# -----------------------------------------------------------------------------
+
+def foreGround(clt, args):
+ # --
+ if "session_object" not in args:
+ return
+ session = args["session_object"]
+ # --
+ # Wait until gui is arrived
+ # tmax = nbtot * dt
+ # --
+ gui_detected = False
+ dt = 0.1
+ nbtot = 100
+ nb = 0
+ while 1:
+ try:
+ status = session.GetStatSession()
+ gui_detected = status.activeGUI
+ except:
+ pass
+ if gui_detected:
+ break
+ from time import sleep
+ sleep(dt)
+ nb += 1
+ if nb == nbtot:
+ break
+ pass
+ # --
+ if not gui_detected:
+ return
+ # --
+ from salome_utils import getPortNumber
+ port = getPortNumber()
+ # --
+ server = Server({})
+ if sys.platform == "win32":
+ server.CMD = [os.getenv("PYTHONBIN"), "-m", "killSalomeWithPort", "--spy", "%s"%(os.getpid()), "%s"%(port)]
+ else:
+ server.CMD = ["killSalomeWithPort.py", "--spy", "%s"%(os.getpid()), "%s"%(port)]
+ server.run()
+ # os.system("killSalomeWithPort.py --spy %s %s &"%(os.getpid(), port))
+ # --
+ dt = 1.0
+ try:
+ while 1:
+ try:
+ status = session.GetStatSession()
+ assert status.activeGUI
+ except:
+ break
+ from time import sleep
+ sleep(dt)
+ pass
+ pass
+ except KeyboardInterrupt:
+ from killSalomeWithPort import killMyPort
+ killMyPort(port)
+ pass
+ return
+#
+
+def runSalome():
+ import user
+ clt,args = main()
+ # --
+ test = args['gui'] and args['session_gui']
+ test = test or args['wake_up_session']
+ # --
+ # The next test covers the --pinter option or var PYTHONINSPECT setted
+ # --
+ test = test and not os.environ.get('PYTHONINSPECT')
+ # --
+ # The next test covers the python -i $KERNEL_ROOT_DIR/bin/salome/runSalome.py case
+ # --
+ try:
+ from ctypes import POINTER, c_int, cast, pythonapi
+ iflag_ptr = cast(pythonapi.Py_InteractiveFlag, POINTER(c_int))
+ test = test and not iflag_ptr.contents.value
+ except:
+ pass
+ # --
+ test = test and os.getenv("SALOME_TEST_MODE", "0") != "1"
+ test = test and args['foreground']
+ # --
+ if test:
+ foreGround(clt, args)
+ pass
+ # --
+ pass
+#
+
+# -----------------------------------------------------------------------------
+
+if __name__ == "__main__":
+
+ ### TEMP ###
+ homePath = os.path.realpath(os.path.expanduser('~'))
+ #defaultOmniorbUserPath = os.path.join(homePath, ".salomeConfig/USERS")
+ appli = os.getenv("APPLI")
+ defaultOmniorbUserPath = homePath
+ if appli:
+ defaultOmniorbUserPath = os.path.join( homePath, appli, "USERS" )
+ os.environ["OMNIORB_USER_PATH"] = defaultOmniorbUserPath
+ ############
+
+ runSalome()
+#