Salome HOME
0023629: [CEA] KERNEL_SALOME_CONCURRENT_TestConcurrentSession: does not return
[modules/kernel.git] / bin / appliskel / kill_remote_containers.py
index 4c3a39429a31dd7551a5a5817ce5e2e45bb421b4..39fa36c9423a300072959ea4c337235e1198d524 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 #  -*- coding: utf-8 -*-
 # Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
 #
 """
 """
 import sys,os,shutil,glob,socket
-import optparse
+import argparse
 from salome_utils import getUserName
 
 import getAppliPath
 appli_local=os.path.realpath(os.path.dirname(__file__))
 APPLI=getAppliPath.relpath(appli_local,os.path.realpath(os.getenv('HOME')))
 
-usage="""usage: %prog [options]
+usage="""%(prog)s [options]
 
 This procedure kill all containers that have been launched in a SALOME session on remote machines.
 A SALOME session is identified by a machine name and a port number.
@@ -110,15 +110,14 @@ class Resource:
     return appliPath
 
 def main():
-  parser = optparse.OptionParser(usage=usage)
-  parser.add_option('-p','--port', dest="port",
-                            help="The SALOME session port (default NSPORT or 2810)")
+  parser = argparse.ArgumentParser(usage=usage)
+  parser.add_argument('-p','--port', dest="port",
+                      help="The SALOME session port (default NSPORT or 2810)")
 
-
-  options, args = parser.parse_args()
+  args = parser.parse_args()
 
   if not os.path.exists(catalog_file):
-    print("ERROR: the catalog file %s is mandatory" % catalog_file_base)
+    print("ERROR: the catalog file %s is mandatory" % catalog_file)
     sys.exit(1)
 
   #Parse CatalogResource.xml
@@ -142,13 +141,14 @@ def main():
     if resource.get_host() in local_names:continue
     command=resource.get_rsh() +" -l "+resource.get_user()+" "+resource.get_host()
     command=command+ " " + os.path.join(resource.get_appliPath(),"runRemote.sh")
-    if options.port:
-      port=options.port
+    if args.port:
+      port=args.port
     else:
       port=os.getenv("NSPORT") or "2810"
     command=command+ " " + get_hostname() + " " + port +" killSalomeWithPort.py " + port
     print(command)
-    os.system(command)
+    return subprocess.call(command, shell=True)
+
 
 if __name__ == '__main__':
   main()