# add process to the dictionary
if not already_in:
import types
- if type(command) == types.ListType: command=" ".join(command)
+ if type(command) == types.ListType: command=" ".join([str(c) for c in command])
command=command.split()[0]
try:
if verbose(): print "addToKillList: %s : %s" % ( str(command_pid), command )
process_ids.append({int(command_pid): [command]})
- fpid=open(filedict,'w')
+ dir = os.path.dirname(filedict)
+ if not os.path.exists(dir): os.makedirs(dir, 0777)
+ fpid = open(filedict,'w')
pickle.dump(process_ids, fpid)
fpid.close()
except:
- if verbose(): print "addToKillList: can not add command %s to the kill list" % filedict
+ if verbose(): print "addToKillList: can not add command %s : %s to the kill list" % ( str(command_pid), command )
pass
pass
pass
# retrieve processes dictionary
from killSalomeWithPort import getPiDict
if port is None: port=findFileDict()
- filedict=getPiDict(port)
+ # new-style dot-prefixed pidict file
+ filedict=getPiDict(port, hidden=True)
+ # provide compatibility with old-style pidict file (not dot-prefixed)
+ if not os.path.exists(filedict): filedict = getPiDict(port, hidden=False)
try:
fpid=open(filedict, 'r')
process_ids=pickle.load(fpid)
"""
user = os.getenv('USER')
# new-style dot-prefixed pidict file
- fnamere = re.compile("^%s$"%(getPiDict('(\d*)',full=False,hidden=True)))
+ fpidict = getPiDict('(\d*)',hidden=True)
+ dirpidict = os.path.dirname(fpidict)
+ fpidict = os.path.basename(fpidict)
+ fnamere = re.compile("^%s$" % fpidict)
+ try:
+ for f in os.listdir(dirpidict):
+ mo = fnamere.match(f)
+ if mo: killMyPort(mo.group(1))
+ pass
+ pass
+ except:
+ pass
# provide compatibility with old-style pidict file (not dot-prefixed)
- fnamere1 = re.compile("^%s$"%(getPiDict('(\d*)',full=False,hidden=False)))
- for file in os.listdir(os.getenv("HOME")):
- mo = fnamere.match(file)
- if not mo: mo = fnamere1.match(file)
- if mo and len(mo.groups()):
- killMyPort(mo.group(1))
+ fpidict = getPiDict('(\d*)',hidden=False)
+ dirpidict = os.path.dirname(fpidict)
+ fpidict = os.path.basename(fpidict)
+ fnamere = re.compile("^%s$" % fpidict)
+ try:
+ for f in os.listdir(dirpidict):
+ mo = fnamere.match(f)
+ if mo: killMyPort(mo.group(1))
+ pass
pass
-
+ except:
+ pass
+ # kill other processes
if sys.platform != 'win32':
import commands
cmd = "ps -fea | grep '%s' | grep 'ghs3d' | grep 'f /tmp/GHS3D_' | grep -v 'grep' | awk '{print $2}'" % user
- hidden : if True, file name is prefixed with . (dot) symbol; this internal parameter is used
to support compatibility with older versions of SALOME
"""
- from salome_utilities import generateFileName
+ from salome_utilities import generateFileName, getTmpDir
dir = ""
- if full: dir = os.getenv("HOME")
+ 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 = getTmpDir()
+ 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,
# Exported functions
#
__all__ = [
+ 'getORBcfgInfo',
+ 'getHostFromORBcfg',
+ 'getPortFromORBcfg',
'getUserName',
'getHostName',
'getShortHostName',
'getAppName',
'getPortNumber',
+ 'getTmpDir',
'generateFileName',
- 'getORBcfgInfo',
- 'getHostFromORBcfg',
- 'getPortFromORBcfg',
]
# ---
1. if fails, try to parse config file defined by OMNIORB_CONFIG environment variable
2. if fails, return 2809 as default port number
"""
- import os, re
+ import os
try:
return int( os.getenv( "NSPORT" ) )
except:
# ---
+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
+
+# ---
+
def generateFileName( dir, prefix = None, suffix = None, extension = None,
unique = False, separator = "_", hidden = False, **kwargs ):
"""