Salome HOME
* Issue 0019872: use dot-prefixed pidict files
authorvsr <vsr@opencascade.com>
Mon, 7 Jul 2008 10:19:17 +0000 (10:19 +0000)
committervsr <vsr@opencascade.com>
Mon, 7 Jul 2008 10:19:17 +0000 (10:19 +0000)
bin/addToKillList.py
bin/killSalome.py
bin/killSalomeWithPort.py
bin/salome_utilities.py

index c1d4b91c9c980c1552dcef96dd0838aa3aad725f..548a8958d18d99d91b8d72f41c287a0a5fd646cf 100755 (executable)
@@ -67,16 +67,18 @@ def addToKillList(command_pid, command, port=None):
     # 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
@@ -90,7 +92,10 @@ def killList(port=None):
     # 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)
index 69e0831135a1bc1d42bd83e7354dc58675bff163..722fd31c72c92d803a025f8900e666a9011770e8 100755 (executable)
@@ -29,16 +29,32 @@ def killAllPorts():
     """
     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
index d4f7a37e2dacd9b6b6c2478eedeab38997bc81f2..2308505a0e2ead3e7392b0293755269b1881cc2f 100755 (executable)
@@ -39,9 +39,20 @@ def getPiDict(port,appname='salome',full=True,hidden=True):
     - 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,
index d5d3a677b303e0bdd0798f58d7bad51b3361567f..e22215fc1658b7664272cbe992d276d96db30ec2 100644 (file)
@@ -31,15 +31,16 @@ Set of utility functions used by SALOME python scripts.
 # Exported functions
 #
 __all__ = [
+    'getORBcfgInfo',
+    'getHostFromORBcfg',
+    'getPortFromORBcfg',
     'getUserName',
     'getHostName',
     'getShortHostName',
     'getAppName',
     'getPortNumber',
+    'getTmpDir',
     'generateFileName',
-    'getORBcfgInfo',
-    'getHostFromORBcfg',
-    'getPortFromORBcfg',
     ]
 
 # ---
@@ -185,7 +186,7 @@ def getPortNumber():
     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:
@@ -196,6 +197,23 @@ def getPortNumber():
 
 # ---
 
+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 ):
     """