2 # -*- coding: utf-8 -*-
3 # Copyright (C) 2007-2011 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.
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
31 appli_local=os.path.realpath(os.path.dirname(__file__))
32 APPLI=getAppliPath.relpath(appli_local,os.path.realpath(os.getenv('HOME')))
34 usage="""usage: %prog [options]
36 This procedure kill all containers that have been launched in a SALOME session on remote machines.
37 A SALOME session is identified by a machine name and a port number.
39 You need to have a well installed SALOME application with a CatalogResources.xml file.
40 This file is used (parsed) to collect all remote resources.
41 Remote resources are all the resources on remote machines not including the main local SALOME application.
45 # cElementTree from Python 2.5+
46 import xml.etree.cElementTree as etree_
49 import xml.etree.ElementTree as etree_
52 import cElementTree as etree_
55 # normal ElementTree install
56 import elementtree.ElementTree as etree_
60 class ParseError(Exception):
63 catalog_file=os.path.join(appli_local,"CatalogResources.xml")
66 if sys.platform == "win32":SEP=";"
69 return socket.gethostname().split('.')[0]
72 """Define a SALOME resource
73 - components : the list of available components of the resource
75 def __init__(self,node):
78 self.resource_dir=None
81 protocol= self.node.get("protocol")
82 if protocol and protocol[0]=='s':return "scp"
86 protocol= self.node.get("protocol")
87 if protocol and protocol[0]=='s':return "ssh"
91 userName= self.node.get("userName")
93 userName=os.getenv('USER')
97 hostname= self.node.get("hostname")
101 name= self.node.get("name")
103 return self.get_host()
105 def get_appliPath(self):
106 appliPath= self.node.get("appliPath")
107 if appliPath is None:
112 parser = optparse.OptionParser(usage=usage)
113 parser.add_option('-p','--port', dest="port",
114 help="The SALOME session port (default NSPORT or 2810)")
117 options, args = parser.parse_args()
119 if not os.path.exists(catalog_file):
120 print "ERROR: the catalog file %s is mandatory" % catalog_file_base
123 #Parse CatalogResource.xml
124 doc = etree_.parse(catalog_file)
126 rootNode = doc.getroot()
127 if rootNode.tag != "resources":
128 raise ParseError("First level tag must be resources not %s" % rootNode.tag)
133 for child in rootNode:
134 if child.tag != "machine":
135 raise ParseError("Second level tag must be machine not %s" % child.tag)
136 resources.append(Resource(child))
138 local_names=("localhost",get_hostname())
140 for resource in resources:
141 if resource.get_host() in local_names:continue
142 command=resource.get_rsh() +" -l "+resource.get_user()+" "+resource.get_host()
143 command=command+ " " + os.path.join(resource.get_appliPath(),"runRemote.sh")
147 port=os.getenv("NSPORT") or "2810"
148 command=command+ " " + get_hostname() + " " + port +" killSalomeWithPort.py " + port
152 if __name__ == '__main__':