Salome HOME
Use "default" theme for Sphinx < 1.3
[modules/kernel.git] / bin / addToKillList.py
index 730ac8d35c7aeb17496de94aa6dc5a19c449c9d3..0282f10520ead456b4c0b090d697b0913d82f862 100755 (executable)
@@ -1,26 +1,28 @@
-#!/usr/bin/env python
-#  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
+#! /usr/bin/env python
+#  -*- coding: iso-8859-1 -*-
+# Copyright (C) 2007-2015  CEA/DEN, EDF R&D, OPEN CASCADE
 #
-#  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-#  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+# Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
 #
-#  This library is free software; you can redistribute it and/or
-#  modify it under the terms of the GNU Lesser General Public
-#  License as published by the Free Software Foundation; either
-#  version 2.1 of the License.
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
 #
-#  This library is distributed in the hope that it will be useful,
-#  but WITHOUT ANY WARRANTY; without even the implied warranty of
-#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-#  Lesser General Public License for more details.
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
 #
-#  You should have received a copy of the GNU Lesser General Public
-#  License along with this library; if not, write to the Free Software
-#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 #
-#  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 #
-import os, sys, pickle, string, signal
+
+import os, sys, pickle, signal
 from launchConfigureParser import verbose
 
 ########## adds to the kill list of SALOME one more process ##########
@@ -34,7 +36,7 @@ def findFileDict():
     port = getPortNumber()
     if verbose(): print "myport = ", port
     return port
-    
+
 def addToKillList(command_pid, command, port=None):
     """
     Add the process to the SALOME processes dictionary file.
@@ -47,24 +49,25 @@ def addToKillList(command_pid, command, port=None):
     # retrieve current processes dictionary
     from killSalomeWithPort import getPiDict
     if port is None: port=findFileDict()
-    filedict=getPiDict(port)
+    filedict = getPiDict(port)
+
     try:
-        fpid=open(filedict, 'r')
-        process_ids=pickle.load(fpid)
-        fpid.close()
+        with open(filedict, 'r') as fpid:
+            process_ids=pickle.load(fpid)
     except:
         process_ids=[]
         pass
     # check if PID is already in dictionary
     already_in=False
     for process_id in process_ids:
-        for pid, cmd in process_id.items():
+        for pid in process_id.keys():
             if int(pid) == int(command_pid):
                 already_in=True
                 break
             pass
         if already_in: break
         pass
+
     # add process to the dictionary
     if not already_in:
         import types
@@ -75,9 +78,8 @@ def addToKillList(command_pid, command, port=None):
             process_ids.append({int(command_pid): [command]})
             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()
+            with open(filedict,'w') as fpid:
+                pickle.dump(process_ids, fpid)
         except:
             if verbose(): print "addToKillList: can not add command %s : %s to the kill list" % ( str(command_pid), command )
             pass
@@ -93,14 +95,15 @@ def killList(port=None):
     # retrieve processes dictionary
     from killSalomeWithPort import getPiDict
     if port is None: port=findFileDict()
+
     # new-style dot-prefixed pidict file
-    filedict=getPiDict(port, hidden=True)
+    filedict=getPiDict(port)
     # 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)
-        fpid.close()
+        with open(filedict, 'r') as fpid:
+            process_ids=pickle.load(fpid)
     except:
         process_ids=[]
         pass
@@ -108,7 +111,6 @@ def killList(port=None):
     for process_id in process_ids:
         #print process_id
         for pid, cmd in process_id.items():
-            print "stop process %s : %s"% (pid, cmd[0])
             try:
                 os.kill(int(pid),signal.SIGKILL)
             except: