2 # -*- coding: utf-8 -*-
3 # Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
5 # Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
6 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
8 # This library is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU Lesser General Public
10 # License as published by the Free Software Foundation; either
11 # version 2.1 of the License, or (at your option) any later version.
13 # This library is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 # Lesser General Public License for more details.
18 # You should have received a copy of the GNU Lesser General Public
19 # License along with this library; if not, write to the Free Software
20 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
27 import sys,os,shutil,glob,socket
29 from salome_utils import getUserName
32 appli_local=os.path.realpath(os.path.dirname(__file__))
33 APPLI=getAppliPath.relpath(appli_local,os.path.realpath(os.getenv('HOME')))
35 usage="""usage: %prog [options]
37 This procedure kill all containers that have been launched in a SALOME session on remote machines.
38 A SALOME session is identified by a machine name and a port number.
40 You need to have a well installed SALOME application with a CatalogResources.xml file.
41 This file is used (parsed) to collect all remote resources.
42 Remote resources are all the resources on remote machines not including the main local SALOME application.
46 # cElementTree from Python 2.5+
47 import xml.etree.cElementTree as etree_
50 import xml.etree.ElementTree as etree_
53 import cElementTree as etree_
56 # normal ElementTree install
57 import elementtree.ElementTree as etree_
61 class ParseError(Exception):
64 catalog_file=os.path.join(appli_local,"CatalogResources.xml")
67 if sys.platform == "win32":SEP=";"
70 return socket.gethostname().split('.')[0]
73 """Define a SALOME resource
74 - components : the list of available components of the resource
76 def __init__(self,node):
79 self.resource_dir=None
82 protocol= self.node.get("protocol")
83 if protocol and protocol[0]=='s':return "scp"
87 protocol= self.node.get("protocol")
88 if protocol and protocol[0]=='s':return "ssh"
92 userName= self.node.get("userName")
94 userName=getUserName()
98 hostname= self.node.get("hostname")
102 name= self.node.get("name")
104 return self.get_host()
106 def get_appliPath(self):
107 appliPath= self.node.get("appliPath")
108 if appliPath is None:
113 parser = optparse.OptionParser(usage=usage)
114 parser.add_option('-p','--port', dest="port",
115 help="The SALOME session port (default NSPORT or 2810)")
118 options, args = parser.parse_args()
120 if not os.path.exists(catalog_file):
121 print "ERROR: the catalog file %s is mandatory" % catalog_file_base
124 #Parse CatalogResource.xml
125 doc = etree_.parse(catalog_file)
127 rootNode = doc.getroot()
128 if rootNode.tag != "resources":
129 raise ParseError("First level tag must be resources not %s" % rootNode.tag)
134 for child in rootNode:
135 if child.tag != "machine":
136 raise ParseError("Second level tag must be machine not %s" % child.tag)
137 resources.append(Resource(child))
139 local_names=("localhost",get_hostname())
141 for resource in resources:
142 if resource.get_host() in local_names:continue
143 command=resource.get_rsh() +" -l "+resource.get_user()+" "+resource.get_host()
144 command=command+ " " + os.path.join(resource.get_appliPath(),"runRemote.sh")
148 port=os.getenv("NSPORT") or "2810"
149 command=command+ " " + get_hostname() + " " + port +" killSalomeWithPort.py " + port
153 if __name__ == '__main__':