2 # -*- coding: utf-8 -*-
5 import sys,os,shutil,glob,socket
9 appli_local=os.path.realpath(os.path.dirname(__file__))
10 APPLI=getAppliPath.relpath(appli_local,os.path.realpath(os.getenv('HOME')))
12 usage="""usage: %prog [options]
14 This procedure kill all containers that have been launched in a SALOME session on remote machines.
15 A SALOME session is identified by a machine name and a port number.
17 You need to have a well installed SALOME application with a CatalogResources.xml file.
18 This file is used (parsed) to collect all remote resources.
19 Remote resources are all the resources on remote machines not including the main local SALOME application.
23 # cElementTree from Python 2.5+
24 import xml.etree.cElementTree as etree_
27 import xml.etree.ElementTree as etree_
30 import cElementTree as etree_
33 # normal ElementTree install
34 import elementtree.ElementTree as etree_
38 class ParseError(Exception):
41 catalog_file=os.path.join(appli_local,"CatalogResources.xml")
44 if sys.platform == "win32":SEP=";"
47 return socket.gethostname().split('.')[0]
50 """Define a SALOME resource
51 - components : the list of available components of the resource
53 def __init__(self,node):
56 self.resource_dir=None
59 protocol= self.node.get("protocol")
60 if protocol and protocol[0]=='s':return "scp"
64 protocol= self.node.get("protocol")
65 if protocol and protocol[0]=='s':return "ssh"
69 userName= self.node.get("userName")
71 userName=os.getenv('USER')
75 hostname= self.node.get("hostname")
79 name= self.node.get("name")
81 return self.get_host()
83 def get_appliPath(self):
84 appliPath= self.node.get("appliPath")
90 parser = optparse.OptionParser(usage=usage)
91 parser.add_option('-p','--port', dest="port",
92 help="The SALOME session port (default NSPORT or 2810)")
95 options, args = parser.parse_args()
97 if not os.path.exists(catalog_file):
98 print "ERROR: the catalog file %s is mandatory" % catalog_file_base
101 #Parse CatalogResource.xml
102 doc = etree_.parse(catalog_file)
104 rootNode = doc.getroot()
105 if rootNode.tag != "resources":
106 raise ParseError("First level tag must be resources not %s" % rootNode.tag)
111 for child in rootNode:
112 if child.tag != "machine":
113 raise ParseError("Second level tag must be machine not %s" % child.tag)
114 resources.append(Resource(child))
116 local_names=("localhost",get_hostname())
118 for resource in resources:
119 if resource.get_host() in local_names:continue
120 command=resource.get_rsh() +" -l "+resource.get_user()+" "+resource.get_host()
121 command=command+ " " + os.path.join(resource.get_appliPath(),"runRemote.sh")
125 port=os.getenv("NSPORT") or "2810"
126 command=command+ " " + get_hostname() + " " + port +" killSalomeWithPort.py " + port
130 if __name__ == '__main__':