def writeORBConfigFile(path, host, port, kwargs={}): from salome_utils import generateFileName omniorb_config = generateFileName(path, prefix="omniORB", extension="cfg", hidden=True, with_hostname=True, with_port=port, **kwargs) import os os.environ['OMNIORB_CONFIG'] = omniorb_config os.environ['NSPORT'] = "%s"%(port) os.environ['NSHOST'] = "%s"%(host) from omniORB import CORBA prefix = "" if CORBA.ORB_ID == "omniORB4" else "ORB" GIOP_MaxMsgSize = 2097152000 # 2 GBytes orbdata = [] orbdata.append("%sInitRef = NameService=corbaname::%s:%s"%(prefix,host,port)) orbdata.append("%sgiopMaxMsgSize = %s # 2 GBytes"%(prefix,GIOP_MaxMsgSize)) orbdata.append("%straceLevel = 0 # critical errors only"%(prefix)) orbdata.append("%smaxGIOPConnectionPerServer = 500 # to allow containers parallel launch"%(prefix)) orbdata.append("") with open(omniorb_config, "w") as f: f.write("\n".join(orbdata)) return [ omniorb_config, GIOP_MaxMsgSize ]
def writeORBConfigFile(path, host, port, kwargs={}): from salome_utils import generateFileName omniorb_config = generateFileName(path, prefix="omniORB", extension="cfg", hidden=True, with_hostname=True, with_port=port, **kwargs) import os os.environ['OMNIORB_CONFIG'] = omniorb_config os.environ['NSPORT'] = "%s" % (port) os.environ['NSHOST'] = "%s" % (host) from omniORB import CORBA prefix = "" if CORBA.ORB_ID == "omniORB4" else "ORB" GIOP_MaxMsgSize = 2097152000 # 2 GBytes orbdata = [] orbdata.append("%sInitRef = NameService=corbaname::%s:%s" % (prefix, host, port)) orbdata.append("%sgiopMaxMsgSize = %s # 2 GBytes" % (prefix, GIOP_MaxMsgSize)) orbdata.append("%straceLevel = 0 # critical errors only" % (prefix)) orbdata.append( "%smaxGIOPConnectionPerServer = 500 # to allow containers parallel launch" % (prefix)) orbdata.append("") with open(omniorb_config, "w") as f: f.write("\n".join(orbdata)) return [omniorb_config, GIOP_MaxMsgSize]
def shutdownMyPort(port, cleanup=True): """ Shutdown SALOME session running on the specified port. Parameters: - port - port number """ if not port: return # bug fix: ensure port is an integer port = int(port) try: from PortManager import releasePort releasePort(port) except ImportError: pass from salome_utils import generateFileName # set OMNIORB_CONFIG variable to the proper file omniorbUserPath = os.getenv("OMNIORB_USER_PATH") kwargs = {} if omniorbUserPath is not None: kwargs["with_username"] = True else: omniorbUserPath = os.path.realpath(os.path.expanduser('~')) omniorb_config = generateFileName(omniorbUserPath, prefix="omniORB", extension="cfg", hidden=True, with_hostname=True, with_port=port, **kwargs) os.environ['OMNIORB_CONFIG'] = omniorb_config os.environ['NSPORT'] = str(port) # give the chance to the servers to shutdown properly try: import time from omniORB import CORBA from LifeCycleCORBA import LifeCycleCORBA # shutdown all orb = CORBA.ORB_init([''], CORBA.ORB_ID) lcc = LifeCycleCORBA(orb) # see (1) print "Terminating SALOME on port %s..." % (port) lcc.shutdownServers() # give some time to shutdown to complete time.sleep(1) # shutdown omniNames if cleanup: lcc.killOmniNames() time.sleep(1) pass pass except: pass exit(0) # see (1) pass
def shutdownMyPort(port, cleanup=True): """ Shutdown SALOME session running on the specified port. Parameters: - port - port number """ if not port: return # bug fix: ensure port is an integer port = int(port) try: from PortManager import releasePort releasePort(port) except ImportError: pass from salome_utils import generateFileName # set OMNIORB_CONFIG variable to the proper file omniorbUserPath = os.getenv("OMNIORB_USER_PATH") kwargs = {} if omniorbUserPath is not None: kwargs["with_username"]=True else: omniorbUserPath = os.path.realpath(os.path.expanduser('~')) omniorb_config = generateFileName(omniorbUserPath, prefix="omniORB", extension="cfg", hidden=True, with_hostname=True, with_port=port, **kwargs) os.environ['OMNIORB_CONFIG'] = omniorb_config os.environ['NSPORT'] = str(port) # give the chance to the servers to shutdown properly try: import time from omniORB import CORBA from LifeCycleCORBA import LifeCycleCORBA # shutdown all orb = CORBA.ORB_init([''], CORBA.ORB_ID) lcc = LifeCycleCORBA(orb) # see (1) print "Terminating SALOME on port %s..."%(port) lcc.shutdownServers() # give some time to shutdown to complete time.sleep(1) # shutdown omniNames if cleanup: lcc.killOmniNames() time.sleep(1) pass pass except: pass exit(0) # see (1) pass
def getPiDict(port, appname='salome', full=True, hidden=True, hostname=None): """ Get file with list of SALOME processes. This file is located in the user's home directory and named .<user>_<host>_<port>_SALOME_pidict where <user> is user name <host> is host name <port> is port number Parameters: - port : port number - appname : application name (default is 'SALOME') - full : if True, full path to the file is returned, otherwise only file name is returned - hidden : if True, file name is prefixed with . (dot) symbol; this internal parameter is used to support compatibility with older versions of SALOME """ # bug fix: ensure port is an integer # Note: this function is also called with port='#####' !!! try: port = int(port) except: pass from salome_utils import generateFileName, getLogDir dir = "" if not hostname: hostname = os.getenv("NSHOST") if hostname: hostname = hostname.split(".")[0] pass if full: # full path to the pidict file is requested if hidden: # new-style dot-prefixed pidict files # are in the system-dependant temporary diretory dir = getLogDir() else: # old-style non-dot-prefixed pidict files # are in the user's home directory dir = os.getenv("HOME") pass pass return generateFileName(dir, suffix="pidict", hidden=hidden, with_username=True, with_hostname=hostname or True, with_port=port, with_app=appname.upper())
def getPiDict(port,appname='salome',full=True,hidden=True,hostname=None): """ Get file with list of SALOME processes. This file is located in the user's home directory and named .<user>_<host>_<port>_SALOME_pidict where <user> is user name <host> is host name <port> is port number Parameters: - port : port number - appname : application name (default is 'SALOME') - full : if True, full path to the file is returned, otherwise only file name is returned - hidden : if True, file name is prefixed with . (dot) symbol; this internal parameter is used to support compatibility with older versions of SALOME """ # bug fix: ensure port is an integer # Note: this function is also called with port='#####' !!! try: port = int(port) except: pass from salome_utils import generateFileName, getLogDir dir = "" if not hostname: hostname = os.getenv("NSHOST") if hostname: hostname = hostname.split(".")[0] pass if full: # full path to the pidict file is requested if hidden: # new-style dot-prefixed pidict files # are in the system-dependant temporary diretory dir = getLogDir() else: # old-style non-dot-prefixed pidict files # are in the user's home directory dir = os.getenv("HOME") pass pass return generateFileName(dir, suffix="pidict", hidden=hidden, with_username=True, with_hostname=hostname or True, with_port=port, with_app=appname.upper())
def _getConfigurationFilename(): omniorbUserPath = os.getenv("OMNIORB_USER_PATH") from salome_utils import generateFileName portmanager_config = generateFileName(omniorbUserPath, prefix="omniORB", suffix="PortManager", extension="cfg", hidden=True) import tempfile temp = tempfile.NamedTemporaryFile() lock_file = os.path.join(os.path.dirname(temp.name), ".omniORB_PortManager.lock") temp.close() return (portmanager_config, lock_file)
def __init__(self, args): self.args = args self.initArgs() from salome_utils import generateFileName, getLogDir logfile = generateFileName(getLogDir(), prefix="logger", extension="log", with_username=True, with_hostname=True, with_port=True) print "===========================================================" print "Logger server: put log to the file:" print logfile print "===========================================================" self.CMD = ['SALOME_Logger_Server', logfile] pass
def __init__(self,args): self.args=args self.initArgs() from salome_utils import generateFileName, getLogDir logfile = generateFileName( getLogDir(), prefix="logger", extension="log", with_username=True, with_hostname=True, with_port=True) print "===========================================================" print "Logger server: put log to the file:" print logfile print "===========================================================" self.CMD=['SALOME_Logger_Server', logfile] pass
def __setup_config(nsport, args, save_config): # from salome_utils import generateFileName, getHostName hostname = getHostName() # omniorbUserPath = os.getenv("OMNIORB_USER_PATH") kwargs={} if omniorbUserPath is not None: kwargs["with_username"]=True # from ORBConfigFile import writeORBConfigFile omniorb_config, giopsize = writeORBConfigFile(omniorbUserPath, hostname, nsport, kwargs) args['port'] = os.environ['NSPORT'] # if save_config: last_running_config = generateFileName(omniorbUserPath, prefix="omniORB", suffix="last", extension="cfg", hidden=True, **kwargs) os.environ['LAST_RUNNING_CONFIG'] = last_running_config try: if sys.platform == "win32": import shutil shutil.copyfile(omniorb_config, last_running_config) else: try: if os.access(last_running_config, os.F_OK): os.remove(last_running_config) except OSError: pass os.symlink(omniorb_config, last_running_config) pass pass except: pass
def startSalome(args, modules_list, modules_root_dir): """Launch all SALOME servers requested by args""" init_time = os.times() if verbose(): print "startSalome ", args # # Set server launch command # if args.has_key('server_launch_mode'): Server.set_server_launch_mode(args['server_launch_mode']) # # Wake up session option # if args['wake_up_session']: if "OMNIORB_CONFIG" not in os.environ: from salome_utils import generateFileName omniorbUserPath = os.getenv("OMNIORB_USER_PATH") kwargs={} if omniorbUserPath is not None: kwargs["with_username"]=True last_running_config = generateFileName(omniorbUserPath, prefix="omniORB", suffix="last", extension="cfg", hidden=True, **kwargs) os.environ['OMNIORB_CONFIG'] = last_running_config pass pass # # Initialisation ORB and Naming Service # clt=orbmodule.client(args) # # Wake up session option # if args['wake_up_session']: import Engines import SALOME import SALOMEDS import SALOME_ModuleCatalog import SALOME_Session_idl session = clt.waitNS("/Kernel/Session",SALOME.Session) status = session.GetStatSession() if status.activeGUI: from salome_utils import getPortNumber port = getPortNumber() msg = "Warning :" msg += "\n" msg += "Session GUI for port number %s is already active."%(port) msg += "\n" msg += "If you which to wake up another session," msg += "\n" msg += "please use variable OMNIORB_CONFIG" msg += "\n" msg += "to get the correct session object in naming service." sys.stdout.write(msg+"\n") sys.stdout.flush() return clt session.GetInterface() args["session_object"] = session return clt # Launch Logger Server (optional) # and wait until it is registered in naming service # if args['logger']: myServer=LoggerServer(args) myServer.run() clt.waitLogger("Logger") # Launch Session Server (to show splash ASAP) # if args["gui"]: mySessionServ = SessionServer(args,args['modules'],modules_root_dir) mySessionServ.setpath(modules_list,modules_root_dir) mySessionServ.run() # # Launch Registry Server, # and wait until it is registered in naming service # if ('registry' not in args['embedded']) | (args["gui"] == 0) : myServer=RegistryServer(args) myServer.run() if sys.platform == "win32": clt.waitNS("/Registry") else: clt.waitNSPID("/Registry",myServer.PID) # # Launch Catalog Server, # and wait until it is registered in naming service # if ('moduleCatalog' not in args['embedded']) | (args["gui"] == 0): cataServer=CatalogServer(args) cataServer.setpath(modules_list,modules_root_dir) cataServer.run() import SALOME_ModuleCatalog if sys.platform == "win32": clt.waitNS("/Kernel/ModulCatalog",SALOME_ModuleCatalog.ModuleCatalog) else: clt.waitNSPID("/Kernel/ModulCatalog",cataServer.PID,SALOME_ModuleCatalog.ModuleCatalog) # # Launch SalomeDS Server, # and wait until it is registered in naming service # #print "ARGS = ",args if ('study' not in args['embedded']) | (args["gui"] == 0): print "RunStudy" myServer=SalomeDSServer(args) myServer.run() if sys.platform == "win32": clt.waitNS("/myStudyManager") else: clt.waitNSPID("/myStudyManager",myServer.PID) # # Launch LauncherServer # myCmServer = LauncherServer(args) myCmServer.setpath(modules_list,modules_root_dir) myCmServer.run() # # Launch ConnectionManagerServer # myConnectionServer = ConnectionManagerServer(args) myConnectionServer.run() from Utils_Identity import getShortHostName if os.getenv("HOSTNAME") == None: if os.getenv("HOST") == None: os.environ["HOSTNAME"]=getShortHostName() else: os.environ["HOSTNAME"]=os.getenv("HOST") theComputer = getShortHostName() # # Launch local C++ Container (FactoryServer), # and wait until it is registered in naming service # if ('cppContainer' in args['standalone']) | (args["gui"] == 0) : myServer=ContainerCPPServer(args) myServer.run() if sys.platform == "win32": clt.waitNS("/Containers/" + theComputer + "/FactoryServer") else: clt.waitNSPID("/Containers/" + theComputer + "/FactoryServer",myServer.PID) if 'pyContainer' in args['standalone']: raise Exception('Python containers no longer supported') # # Wait until Session Server is registered in naming service # if args["gui"]: ##---------------- import Engines import SALOME import SALOMEDS import SALOME_ModuleCatalog import SALOME_Session_idl if sys.platform == "win32": session=clt.waitNS("/Kernel/Session",SALOME.Session) else: session=clt.waitNSPID("/Kernel/Session",mySessionServ.PID,SALOME.Session) args["session_object"] = session end_time = os.times() if verbose(): print print "Start SALOME, elapsed time : %5.1f seconds"% (end_time[4] - init_time[4]) # ASV start GUI without Loader #if args['gui']: # session.GetInterface() # # additionnal external python interpreters # nbaddi=0 try: if 'interp' in args: nbaddi = args['interp'] except: import traceback traceback.print_exc() print "-------------------------------------------------------------" print "-- to get an external python interpreter:runSalome --interp=1" print "-------------------------------------------------------------" if verbose(): print "additional external python interpreters: ", nbaddi if nbaddi: for i in range(nbaddi): print "i=",i anInterp=InterpServer(args) anInterp.run() # set PYTHONINSPECT variable (python interpreter in interactive mode) if args['pinter']: os.environ["PYTHONINSPECT"]="1" try: import readline except ImportError: pass return clt
def set_env(args, modules_list, modules_root_dir, silent=False): """Add to the PATH-variables modules specific paths""" import os from salome_utils import getLogDir, generateFileName, makeTmpDir, getPortNumber # create temporary directory for environment files needed by modules from the list port = getPortNumber(False) if port: tmp_dir = getLogDir() env_dir = generateFileName(tmp_dir, prefix="env", with_port=True) makeTmpDir(env_dir) pass python_version = "python%d.%d" % sys.version_info[0:2] modules_root_dir_list = [] if os.getenv('SALOME_BATCH') == None: os.putenv('SALOME_BATCH', '0') if args["gui"]: modules_list = modules_list[:] + ["GUI"] modules_list = modules_list[:] + ["KERNEL"] for module in modules_list: if modules_root_dir.has_key(module): module_root_dir = modules_root_dir[module] if module_root_dir not in modules_root_dir_list: modules_root_dir_list[:0] = [module_root_dir] if sys.platform == "win32": add_path( os.path.join(module_root_dir, get_lib_dir(), salome_subdir), "PATH") else: add_path( os.path.join(module_root_dir, get_lib_dir(), salome_subdir), "LD_LIBRARY_PATH") add_path(os.path.join(module_root_dir, "bin", salome_subdir), "PATH") if os.path.exists(module_root_dir + "/examples"): add_path(os.path.join(module_root_dir, "examples"), "PYTHONPATH") pass add_path(os.path.join(module_root_dir, "bin", salome_subdir), "PYTHONPATH") # add lib before site-packages to load script instead of dll if any (win32 platform) add_path( os.path.join(module_root_dir, get_lib_dir(), salome_subdir), "PYTHONPATH") add_path( os.path.join(module_root_dir, get_lib_dir(), python_version, "site-packages", salome_subdir), "PYTHONPATH") import platform if platform.machine() == "x86_64": add_path( os.path.join(module_root_dir, "lib64", python_version, "site-packages", salome_subdir), "PYTHONPATH") pass add_path( os.path.join(module_root_dir, get_lib_dir(), python_version, "site-packages", salome_subdir, "shared_modules"), "PYTHONPATH") # set environment by modules from the list if port: try: mod = __import__(module.lower() + "_setenv") mod.set_env(args) pass except: pass pass pass pass if sys.platform == 'win32': os.environ["SALOMEPATH"] = ";".join(modules_root_dir_list) else: os.environ["SALOMEPATH"] = ":".join(modules_root_dir_list) # set trace environment variable if not os.environ.has_key("SALOME_trace"): os.environ["SALOME_trace"] = "local" if args['file']: os.environ["SALOME_trace"] = "file:" + args['file'][0] if args['logger']: os.environ["SALOME_trace"] = "with_logger" # set resources variables if not yet set os.environ["CSF_SALOMEDS_ResourcesDefaults"] \ = os.path.join(modules_root_dir["KERNEL"],"share", salome_subdir,"resources","kernel")
def appliCleanOmniOrbConfig(port): """ Remove omniorb config files related to the port in SALOME application: - ${OMNIORB_USER_PATH}/.omniORB_${USER}_${HOSTNAME}_${NSPORT}.cfg - ${OMNIORB_USER_PATH}/.omniORB_${USER}_last.cfg the last is removed only if the link points to the first file. """ if verbose(): print "clean OmniOrb config for port %s" % port from salome_utils import generateFileName, getUserName omniorbUserPath = os.getenv("OMNIORB_USER_PATH") if omniorbUserPath is None: #Run outside application context pass else: omniorb_config = generateFileName(omniorbUserPath, prefix="omniORB", extension="cfg", hidden=True, with_username=True, with_hostname=True, with_port=port) last_running_config = generateFileName(omniorbUserPath, prefix="omniORB", with_username=True, suffix="last", extension="cfg", hidden=True) if os.access(last_running_config, os.F_OK): if not sys.platform == 'win32': pointedPath = os.readlink(last_running_config) if pointedPath[0] != '/': pointedPath = os.path.join( os.path.dirname(last_running_config), pointedPath) pass if pointedPath == omniorb_config: os.unlink(last_running_config) pass pass else: os.remove(last_running_config) pass pass if os.access(omniorb_config, os.F_OK): os.remove(omniorb_config) pass if os.path.lexists(last_running_config): return #try to relink last.cfg to an existing config file if any files = glob.glob( os.path.join(omniorbUserPath, ".omniORB_" + getUserName() + "_*.cfg")) current_config = None current = 0 for f in files: stat = os.stat(f) if stat.st_atime > current: current = stat.st_atime current_config = f if current_config: if sys.platform == "win32": import shutil shutil.copyfile(os.path.normpath(current_config), last_running_config) pass else: os.symlink(os.path.normpath(current_config), last_running_config) pass pass pass pass
def startSalome(args, modules_list, modules_root_dir): """Launch all SALOME servers requested by args""" init_time = os.times() if verbose(): print "startSalome ", args # # Set server launch command # if args.has_key('server_launch_mode'): Server.set_server_launch_mode(args['server_launch_mode']) # # Wake up session option # if args['wake_up_session']: if "OMNIORB_CONFIG" not in os.environ: from salome_utils import generateFileName omniorbUserPath = os.getenv("OMNIORB_USER_PATH") kwargs = {} if omniorbUserPath is not None: kwargs["with_username"] = True last_running_config = generateFileName(omniorbUserPath, prefix="omniORB", suffix="last", extension="cfg", hidden=True, **kwargs) os.environ['OMNIORB_CONFIG'] = last_running_config pass pass # # Initialisation ORB and Naming Service # clt = orbmodule.client(args) # # Wake up session option # if args['wake_up_session']: import Engines import SALOME import SALOMEDS import SALOME_ModuleCatalog import SALOME_Session_idl session = clt.waitNS("/Kernel/Session", SALOME.Session) status = session.GetStatSession() if status.activeGUI: from salome_utils import getPortNumber port = getPortNumber() msg = "Warning :" msg += "\n" msg += "Session GUI for port number %s is already active." % (port) msg += "\n" msg += "If you which to wake up another session," msg += "\n" msg += "please use variable OMNIORB_CONFIG" msg += "\n" msg += "to get the correct session object in naming service." sys.stdout.write(msg + "\n") sys.stdout.flush() return clt session.GetInterface() args["session_object"] = session return clt # Launch Logger Server (optional) # and wait until it is registered in naming service # if args['logger']: myServer = LoggerServer(args) myServer.run() clt.waitLogger("Logger") # Launch Session Server (to show splash ASAP) # if args["gui"]: mySessionServ = SessionServer(args, args['modules'], modules_root_dir) mySessionServ.setpath(modules_list, modules_root_dir) mySessionServ.run() # # Launch Registry Server, # and wait until it is registered in naming service # if ('registry' not in args['embedded']) | (args["gui"] == 0): myServer = RegistryServer(args) myServer.run() if sys.platform == "win32": clt.waitNS("/Registry") else: clt.waitNSPID("/Registry", myServer.PID) # # Launch Catalog Server, # and wait until it is registered in naming service # if ('moduleCatalog' not in args['embedded']) | (args["gui"] == 0): cataServer = CatalogServer(args) cataServer.setpath(modules_list, modules_root_dir) cataServer.run() import SALOME_ModuleCatalog if sys.platform == "win32": clt.waitNS("/Kernel/ModulCatalog", SALOME_ModuleCatalog.ModuleCatalog) else: clt.waitNSPID("/Kernel/ModulCatalog", cataServer.PID, SALOME_ModuleCatalog.ModuleCatalog) # # Launch SalomeDS Server, # and wait until it is registered in naming service # #print "ARGS = ",args if ('study' not in args['embedded']) | (args["gui"] == 0): print "RunStudy" myServer = SalomeDSServer(args) myServer.run() if sys.platform == "win32": clt.waitNS("/myStudyManager") else: clt.waitNSPID("/myStudyManager", myServer.PID) # # Launch LauncherServer # myCmServer = LauncherServer(args) myCmServer.setpath(modules_list, modules_root_dir) myCmServer.run() # # Launch ConnectionManagerServer # myConnectionServer = ConnectionManagerServer(args) myConnectionServer.run() from Utils_Identity import getShortHostName if os.getenv("HOSTNAME") == None: if os.getenv("HOST") == None: os.environ["HOSTNAME"] = getShortHostName() else: os.environ["HOSTNAME"] = os.getenv("HOST") theComputer = getShortHostName() # # Launch local C++ Container (FactoryServer), # and wait until it is registered in naming service # if ('cppContainer' in args['standalone']) | (args["gui"] == 0): myServer = ContainerCPPServer(args) myServer.run() if sys.platform == "win32": clt.waitNS("/Containers/" + theComputer + "/FactoryServer") else: clt.waitNSPID("/Containers/" + theComputer + "/FactoryServer", myServer.PID) if 'pyContainer' in args['standalone']: raise Exception('Python containers no longer supported') # # Wait until Session Server is registered in naming service # if args["gui"]: ##---------------- import Engines import SALOME import SALOMEDS import SALOME_ModuleCatalog import SALOME_Session_idl if sys.platform == "win32": session = clt.waitNS("/Kernel/Session", SALOME.Session) else: session = clt.waitNSPID("/Kernel/Session", mySessionServ.PID, SALOME.Session) args["session_object"] = session end_time = os.times() if verbose(): print print "Start SALOME, elapsed time : %5.1f seconds" % (end_time[4] - init_time[4]) # ASV start GUI without Loader #if args['gui']: # session.GetInterface() # # additionnal external python interpreters # nbaddi = 0 try: if 'interp' in args: nbaddi = args['interp'] except: import traceback traceback.print_exc() print "-------------------------------------------------------------" print "-- to get an external python interpreter:runSalome --interp=1" print "-------------------------------------------------------------" if verbose(): print "additional external python interpreters: ", nbaddi if nbaddi: for i in range(nbaddi): print "i=", i anInterp = InterpServer(args) anInterp.run() # set PYTHONINSPECT variable (python interpreter in interactive mode) if args['pinter']: os.environ["PYTHONINSPECT"] = "1" try: import readline except ImportError: pass return clt
def set_env( args ): """Add to the PATH-variables modules specific paths""" psep = os.pathsep python_version="python%d.%d" % sys.version_info[0:2] tmp_dir = getTmpDir() env_dir = generateFileName( tmp_dir, prefix="env", with_port=True ) res_dir = os.path.join( os.getenv( "GEOM_ROOT_DIR" ), "share", salome_subdir, "resources", "geom" ) csf_list = ["Plugin", "GEOMDS_Resources", "ShHealing"] for csf in csf_list: uniteFiles( os.path.join( res_dir, csf ), os.path.join( env_dir, csf ) ) csf_var = "CSF_%sDefaults" % csf if not os.getenv( csf_var ): os.environ[ csf_var ] = env_dir pass pass # collect plugins plugin_list = [] resource_path_list = [] # standard plugins plugin_list.append("BREPPlugin") plugin_list.append("STEPPlugin") plugin_list.append("IGESPlugin") plugin_list.append("STLPlugin") plugin_list.append("XAOPlugin") plugin_list.append("VTKPlugin") plugin_list.append("AdvancedGEOM") # find additional plugins for env_var in os.environ.keys(): value = os.environ[env_var] if env_var[-9:] == "_ROOT_DIR" and value: plugin_root = value plugin = env_var[:-9] # plugin name may have wrong case # look for NAMEOFPlugin.xml file among resource files resource_dir = os.path.join(plugin_root, "share", salome_subdir, "resources", plugin.lower()) if not os.access(resource_dir, os.F_OK): continue for resource_file in os.listdir(resource_dir): if resource_file.endswith(".xml") and \ resource_file.lower() == plugin.lower() + ".xml": # use "name" attribute of "geom-plugin" as name of plugin in a right case try: from xml.dom.minidom import parse xml_doc = parse(os.path.join(resource_dir, resource_file)) plugin_nodes = xml_doc.getElementsByTagName("geom-plugin") if not plugin_nodes or not plugin_nodes[0].hasAttribute("name"): continue plugin = plugin_nodes[0].getAttribute("name") if plugin in plugin_list: continue plugin_list.append(plugin) # add paths of plugin if not os.environ.has_key("SALOME_"+plugin+"Resources"): resource_path = os.path.join(plugin_root, "share", salome_subdir, "resources", plugin.lower()) os.environ["SALOME_"+plugin+"Resources"] = resource_path resource_path_list.append(resource_path) add_path(os.path.join(plugin_root, get_lib_dir(), python_version, "site-packages", salome_subdir), "PYTHONPATH") add_path(os.path.join(plugin_root, get_lib_dir(), salome_subdir), "PYTHONPATH") if sys.platform == "win32": add_path(os.path.join(plugin_root, get_lib_dir(), salome_subdir), "PATH") add_path(os.path.join(plugin_root, "bin", salome_subdir), "PYTHONPATH") else: add_path(os.path.join(plugin_root, get_lib_dir(), salome_subdir), "LD_LIBRARY_PATH") add_path(os.path.join(plugin_root, "bin", salome_subdir), "PYTHONPATH") add_path(os.path.join(plugin_root, "bin", salome_subdir), "PATH") pass pass pass except: continue pass pass pass pass os.environ["GEOM_PluginsList"] = ":".join(plugin_list) os.environ["SalomeAppConfig"] = os.environ["SalomeAppConfig"] + psep + psep.join(resource_path_list) pass
def appliCleanOmniOrbConfig(port): """ Remove omniorb config files related to the port in SALOME application: - ${OMNIORB_USER_PATH}/.omniORB_${USER}_${HOSTNAME}_${NSPORT}.cfg - ${OMNIORB_USER_PATH}/.omniORB_${USER}_last.cfg the last is removed only if the link points to the first file. """ if verbose(): print "clean OmniOrb config for port %s"%port from salome_utils import generateFileName, getUserName omniorbUserPath = os.getenv("OMNIORB_USER_PATH") if omniorbUserPath is None: #Run outside application context pass else: omniorb_config = generateFileName(omniorbUserPath, prefix="omniORB", extension="cfg", hidden=True, with_username=True, with_hostname=True, with_port=port) last_running_config = generateFileName(omniorbUserPath, prefix="omniORB", with_username=True, suffix="last", extension="cfg", hidden=True) if os.access(last_running_config,os.F_OK): if not sys.platform == 'win32': pointedPath = os.readlink(last_running_config) if pointedPath[0] != '/': pointedPath=os.path.join(os.path.dirname(last_running_config), pointedPath) pass if pointedPath == omniorb_config: os.unlink(last_running_config) pass pass else: os.remove(last_running_config) pass pass if os.access(omniorb_config,os.F_OK): os.remove(omniorb_config) pass if os.path.lexists(last_running_config):return #try to relink last.cfg to an existing config file if any files = glob.glob(os.path.join(omniorbUserPath,".omniORB_"+getUserName()+"_*.cfg")) current_config=None current=0 for f in files: stat=os.stat(f) if stat.st_atime > current: current=stat.st_atime current_config=f if current_config: if sys.platform == "win32": import shutil shutil.copyfile(os.path.normpath(current_config), last_running_config) pass else: os.symlink(os.path.normpath(current_config), last_running_config) pass pass pass pass
def set_env(args, modules_list, modules_root_dir, silent=False): """Add to the PATH-variables modules specific paths""" import os from salome_utils import getLogDir, generateFileName, makeTmpDir, getPortNumber # create temporary directory for environment files needed by modules from the list port = getPortNumber(False) if port: tmp_dir = getLogDir() env_dir = generateFileName(tmp_dir, prefix="env", with_port=True) makeTmpDir(env_dir) pass python_version="python%d.%d" % sys.version_info[0:2] modules_root_dir_list = [] if os.getenv('SALOME_BATCH') == None: os.putenv('SALOME_BATCH','0') if args["gui"] : modules_list = modules_list[:] + ["GUI"] modules_list = modules_list[:] + ["KERNEL"] for module in modules_list : if modules_root_dir.has_key(module): module_root_dir = modules_root_dir[module] if module_root_dir not in modules_root_dir_list: modules_root_dir_list[:0] = [module_root_dir] if sys.platform == "win32": add_path(os.path.join(module_root_dir,get_lib_dir(),salome_subdir), "PATH") else: add_path(os.path.join(module_root_dir,get_lib_dir(),salome_subdir), "LD_LIBRARY_PATH") add_path(os.path.join(module_root_dir,"bin",salome_subdir), "PATH") if os.path.exists(module_root_dir + "/examples") : add_path(os.path.join(module_root_dir,"examples"), "PYTHONPATH") pass add_path(os.path.join(module_root_dir,"bin",salome_subdir), "PYTHONPATH") # add lib before site-packages to load script instead of dll if any (win32 platform) add_path(os.path.join(module_root_dir,get_lib_dir(),salome_subdir), "PYTHONPATH") add_path(os.path.join(module_root_dir,get_lib_dir(), python_version,"site-packages", salome_subdir), "PYTHONPATH") import platform if platform.machine() == "x86_64": add_path(os.path.join(module_root_dir,"lib64", python_version,"site-packages", salome_subdir), "PYTHONPATH") pass add_path(os.path.join(module_root_dir,get_lib_dir(), python_version,"site-packages", salome_subdir, "shared_modules"), "PYTHONPATH") # set environment by modules from the list if port: try: mod=__import__(module.lower()+"_setenv") mod.set_env(args) pass except: pass pass pass pass if sys.platform == 'win32': os.environ["SALOMEPATH"]=";".join(modules_root_dir_list) else: os.environ["SALOMEPATH"]=":".join(modules_root_dir_list) # set trace environment variable if not os.environ.has_key("SALOME_trace"): os.environ["SALOME_trace"]="local" if args['file']: os.environ["SALOME_trace"]="file:"+args['file'][0] if args['logger']: os.environ["SALOME_trace"]="with_logger" # set resources variables if not yet set os.environ["CSF_SALOMEDS_ResourcesDefaults"] \ = os.path.join(modules_root_dir["KERNEL"],"share", salome_subdir,"resources","kernel")