From 0a8b21dda361634f8cb6e6edab255f010657ead1 Mon Sep 17 00:00:00 2001 From: Guillaume Raffy Date: Tue, 7 Feb 2012 14:14:48 +0000 Subject: [PATCH] =?UTF-8?q?correction=20du=20bug=20186=20:=20Int=C3=A9grer?= =?UTF-8?q?=20la=20configuration=20SGE=20des=20noeuds=20dans=20l'installeu?= =?UTF-8?q?r?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SunGridEngine/SgeConfig.py | 95 ++++++++++++++++++++++++++++++++++++++ SunGridEngine/__init__.py | 1 + Util.py | 11 +++++ 3 files changed, 107 insertions(+) create mode 100755 SunGridEngine/SgeConfig.py create mode 100644 SunGridEngine/__init__.py diff --git a/SunGridEngine/SgeConfig.py b/SunGridEngine/SgeConfig.py new file mode 100755 index 0000000..58d20ce --- /dev/null +++ b/SunGridEngine/SgeConfig.py @@ -0,0 +1,95 @@ +#!/usr/bin/python + +#import sys +#sys.path.insert(0, '/homes/raffy/SvnGRaffy/dev/Python') +import re +#import Lib.Util + +class SgeConfig: + def __init__( self ): + self.m_attrs={} + def getAttr( self, strAttrName ): + return self.m_attrs[ strAttrName ] + def setAttr( self, strAttrName, strAttrValue ): + self.m_attrs[ strAttrName ] = strAttrValue + def loadFromSgeFormat1String( self, strSgeConfigString ): + """ + loads attrs from a string such as : + hostname simpatix11.univ-rennes1.fr + load_scaling NONE + complex_values has_molpro_2010=0 + load_values arch=darwin-x86,num_proc=4,mem_total=8192.000000M, \ + swap_total=0.000000M,virtual_total=8192.000000M, \ + load_avg=5.126465,load_short=5.186523, \ + load_medium=5.126465,load_long=5.087891, \ + mem_free=6654.054688M,swap_free=0.000000M, \ + virtual_free=6654.054688M,mem_used=1537.945312M, \ + swap_used=0.000000M,virtual_used=1537.945312M, \ + cpu=100.000000,m_topology=NONE,m_topology_inuse=NONE, \ + m_socket=0,m_core=0,np_load_avg=1.281616, \ + np_load_short=1.296631,np_load_medium=1.281616, \ + np_load_long=1.271973 + processors 4 + user_lists NONE + xuser_lists NONE + projects NONE + xprojects NONE + usage_scaling NONE + report_variables NONE + """ + self.m_attrs={} + # put multiline attributes on one line + strSgeConfigString = re.sub(r"\\\n", "", strSgeConfigString) + for strAttrDef in strSgeConfigString.split("\n"): + #print strAttrDef + if len(strAttrDef) != 0: + matchObj = re.match( "^(?P[^\s]+)[ ]+(?P[^\s].*)$", strAttrDef ) + #print( '%s = %s\n' % (matchObj.group("attrName"), matchObj.group("attrValue") ) ) + self.m_attrs[ matchObj.group("attrName") ] = matchObj.group("attrValue") + + def loadFromSgeFormat2String( self, strSgeConfigString ): + """ + loads attrs from a string such as : + arch=darwin-x86,num_proc=4,mem_total=8192.000000M, \ + swap_total=0.000000M,virtual_total=8192.000000M, \ + load_avg=5.126465,load_short=5.186523, \ + load_medium=5.126465,load_long=5.087891, \ + mem_free=6654.054688M,swap_free=0.000000M, \ + virtual_free=6654.054688M,mem_used=1537.945312M, \ + swap_used=0.000000M,virtual_used=1537.945312M, \ + cpu=100.000000,m_topology=NONE,m_topology_inuse=NONE, \ + m_socket=0,m_core=0,np_load_avg=1.281616, \ + np_load_short=1.296631,np_load_medium=1.281616, \ + np_load_long=1.271973 + """ + self.m_attrs={} + if strSgeConfigString != "NONE": + for strAttrDef in strSgeConfigString.split(","): + #print strAttrDef + if len(strAttrDef) != 0: + matchObj = re.match( "^(?P[^=]+)=(?P.*)$", strAttrDef ) + #print matchObj.group("attrName") + self.m_attrs[ matchObj.group("attrName") ] = matchObj.group("attrValue") + def asFormat1String( self ): + strResult = "" + for (k,v) in self.m_attrs.iteritems(): + #print "%s %s" % (k,v) + strResult += "%s %s\n" % (k,v) + #print strSgeConfigString + return strResult + def asFormat2String( self ): + strResult = "" + iNumAttrs = len(self.m_attrs) + if iNumAttrs == 0: + return "NONE" + iAttr = 0 + for (k,v) in self.m_attrs.iteritems(): + #print "%s %s" % (k,v) + strResult += "%s=%s" % (k,v) + if iAttr != (iNumAttrs - 1): + strResult += "," + iAttr+=1 + #print strSgeConfigString + return strResult + + diff --git a/SunGridEngine/__init__.py b/SunGridEngine/__init__.py new file mode 100644 index 0000000..5a9ecee --- /dev/null +++ b/SunGridEngine/__init__.py @@ -0,0 +1 @@ +# this file is here just so that the containing directory is treated as a python package \ No newline at end of file diff --git a/Util.py b/Util.py index 33e856a..4580644 100644 --- a/Util.py +++ b/Util.py @@ -20,6 +20,17 @@ def sendTextMail(strFrom, to, strSubject, text ): smtp.sendmail(strFrom, [to], mail.as_string()) smtp.close() +class Error( Exception ): + def __init__( self, strMessage ): + self.m_strMessage = strMessage + +def getHostName(): + (returnCode, stdout, stderr) = executeProgram(['hostname', '-s']) + if returnCode != 0: + raise Error(stderr) + strHostName = re.sub(r"\n", "", stdout) + return strHostName + def log( message ): print time.asctime(time.localtime())+' : '+ message