except:
pass
- from salome_utils import generateFileName, getTmpDir
+ from salome_utils import generateFileName, getLogDir
dir = ""
if not hostname:
hostname = os.getenv("NSHOST")
if hidden:
# new-style dot-prefixed pidict files
# are in the system-dependant temporary diretory
- dir = getTmpDir()
+ dir = getLogDir()
else:
# old-style non-dot-prefixed pidict files
# are in the user's home directory
try:
import time
from omniORB import CORBA
-
+
from LifeCycleCORBA import LifeCycleCORBA
# shutdown all
orb = CORBA.ORB_init([''], CORBA.ORB_ID)
try:
with open(filedict, 'r') as fpid:
#
- from salome_utils import generateFileName
- if sys.platform == "win32":
- username = os.getenv( "USERNAME" )
- tmpdir = 'c:\tmp'
- else:
- username = os.getenv('USER')
- tmpdir = '/tmp'
- path = os.path.join(tmpdir, 'logs', username)
- fpidomniNames = generateFileName(path,
+ from salome_utils import generateFileName, getLogDir
+ fpidomniNames = generateFileName(getLogDir(),
prefix="",
suffix="Pid_omniNames",
extension="log",
time.sleep(3) # wait a little, then kill processes (should be done if shutdown procedure hangs up)
try:
- import PortManager
+ import PortManager # do not remove! Test for PortManager availability!
filedict = getPiDict(port)
#filedict = __guessPiDictFilename(port)
import glob
# -----------------------------------------------------------------------------
class NamingServer(Server):
- XTERM = ""
- USER = os.getenv('USER')
- if USER is None:
- USER = 'anonymous'
+ #XTERM = ""
+ #USER = os.getenv('USER')
+ #if USER is None:
+ # USER = 'anonymous'
#os.system("mkdir -m 777 -p /tmp/logs")
- LOGDIR = "/tmp/logs/" + USER
+ #LOGDIR = "/tmp/logs/" + USER
def initNSArgs(self):
- if sys.platform == "win32":
- # temporarily using home directory for Namning Service logs
- # to be replaced with TEMP later...
- os.environ["BaseDir"]=os.environ["HOME"]
- else:
- os.environ["BaseDir"]="/tmp"
-
- try:
- os.mkdir(os.environ["BaseDir"] + "/logs")
- os.chmod(os.environ["BaseDir"] + "/logs", 0777)
- except:
- #print "Can't create " + os.environ["BaseDir"] + "/logs"
- pass
-
- upath = os.environ["BaseDir"] + "/logs/";
- if sys.platform == "win32":
- upath += os.environ["Username"];
- else:
- upath += os.environ["USER"];
-
+ from salome_utils import getLogDir
+ upath = getLogDir()
try:
- os.mkdir(upath)
+ os.makedirs(upath, mode=0777)
except:
- #print "Can't create " + upath
- pass
+ pass
if verbose(): print "Name Service... ",
#hname=os.environ["HOST"] #commands.getoutput("hostname")
# it is cleaner on linux and it is a fix for salome since it is impossible to
# remove the log files if the corresponding omniNames has not been killed.
# \end{E.A.}
-
- upath += "/omniNames_%s"%(aPort)
+
+ upath = os.path.join(upath, "omniNames_%s"%(aPort))
try:
os.mkdir(upath)
except:
#print "Can't create " + upath
pass
-
+
#os.system("touch " + upath + "/dummy")
for fname in os.listdir(upath):
try:
# Others Containers are started with start_impl method of FactoryServer Container.
# For using rsh it is necessary to have in the ${HOME} directory a .rhosts file
# Warning : on RedHat the file /etc/hosts contains by default a line like :
-# 127.0.0.1 bordolex bordolex.paris1.matra-dtv.fr localhost.localdomain localhost
+# 127.0.0.1 bordolex bordolex.paris1.matra-dtv.fr localhost.localdomain localhost
# (bordolex is the station name). omniNames on bordolex will be accessible from other
# computers only if the computer name is removed on that line like :
# 127.0.0.1 bordolex.paris1.matra-dtv.fr localhost.localdomain localhost
def __init__(self,args):
self.args=args
self.initArgs()
- from salome_utils import generateFileName
- if sys.platform == "win32": dirpath = os.environ["HOME"]
- else: dirpath = "/tmp"
- logfile = generateFileName( dirpath,
+ from salome_utils import generateFileName, getLogDir
+ logfile = generateFileName( getLogDir(),
prefix="logger",
extension="log",
with_username=True,
# set siman python path before the session server launching to import scripts inside python console
if simanStudyName(args):
# MPV: use os.environ here because session server is launched in separated process and sys.path is missed in this case
- os.environ["PYTHONPATH"] = "/tmp/SimanSalome/" + args['siman_study'] + "/" + \
- args['siman_scenario'] + "/" + args['siman_user'] + os.pathsep + os.environ["PYTHONPATH"];
+ from salome_utils import getTmpDir
+ ppath = os.path.join(getTmpDir, "SimanSalome", args['siman_study'],
+ args['siman_scenario'], args['siman_user'])
+ os.environ["PYTHONPATH"] = ppath + os.pathsep + os.environ["PYTHONPATH"]
# Launch Session Server (to show splash ASAP)
#
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/'
-
+ from salome_utils import getTmpDir
+ fileEnv = getTmpDir()
fileEnv += os.getenv('USER') + "_" + str(args['port']) \
+ '_' + args['appname'].upper() + '_env'
fenv=open(fileEnv,'w')
'getShortHostName',
'getAppName',
'getPortNumber',
+ 'getLogDir',
'getTmpDir',
'getHomeDir',
'generateFileName',
"""
Get omniORB current configuration.
Returns a list of three values: [ orb_version, host_name, port_number ].
-
+
The information is retrieved from the omniORB configuration file defined
by the OMNIORB_CONFIG environment variable.
If omniORB configuration file can not be accessed, a list of three empty
def getUserName():
"""
Get user name:
- 1. try USER environment variable
+ 1. try USER environment variable (USERNAME on windows)
2. if fails, return 'unknown' as default user name
"""
- import os
- return os.getenv( "USER", "unknown" ) # 'unknown' is default user name
-
+ import os, sys
+ if sys.platform == "win32":
+ return os.getenv("USERNAME", "unknown")
+ else:
+ return os.getenv("USER", "unknown")
# ---
def getHostName():
except:
pass
return "unknown" # 'unknown' is default host name
-
+
# ---
def getAppName():
return os.path.realpath(os.path.expanduser('~'))
# ---
+def getLogDir():
+ """
+ Get directory to be used for the log files.
+ """
+ import os
+ return os.path.join(getTmpDir(), "logs", getUserName())
+# ---
+
def getTmpDir():
"""
Get directory to be used for the temporary files.
"""
- import os, sys
- if sys.platform == "win32":
- # for Windows: temporarily using home directory for tmp files;
- # to be replaced with TEMP environment variable later...
- dir = os.getenv("HOME")
- else:
- # for Linux: use /tmp/logs/{user} folder
- dir = os.path.join( '/tmp', 'logs', getUserName() )
- pass
- return dir
-
+ import os, tempfile
+ f = tempfile.NamedTemporaryFile()
+ tmpdir = os.path.dirname(f.name)
+ f.close()
+ return tmpdir
# ---
def generateFileName( dir, prefix = None, suffix = None, extension = None,
pass
#
return _verbose
+# --
def setVerbose(level):
"""
global _verbose
_verbose = level
return
-
+# --
def get_config(silent=False):
"""
Get list of modules, paths.
-
+
Read args from launch configure xml file and command line options.
Check variables <module>_ROOT_DIR and set list of used modules.
- Return args, modules_list, modules_root_dir
+ Return args, modules_list, modules_root_dir
"""
-
+
# read args from launch configure xml file and command line options
#*** Test additional option
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 getTmpDir, generateFileName, makeTmpDir, getPortNumber
+ 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 = getTmpDir()
+ tmp_dir = getLogDir()
env_dir = generateFileName(tmp_dir, prefix="env", with_port=True)
makeTmpDir(env_dir)
pass
if os.getenv('SALOME_BATCH') == None:
os.putenv('SALOME_BATCH','0')
if args["gui"] :
- modules_list = modules_list[:] + ["GUI"]
- modules_list = modules_list[:] + ["KERNEL"]
+ 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]
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']: