2012-02-07 15:14:48 +01:00
|
|
|
|
#!/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={}
|
2018-04-09 12:34:01 +02:00
|
|
|
|
def hasAttr(self, attr_name):
|
|
|
|
|
return attr_name in self.m_attrs.keys()
|
2012-02-07 15:14:48 +01:00
|
|
|
|
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<attrName>[^\s]+)[ ]+(?P<attrValue>[^\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:
|
2013-12-06 11:41:50 +01:00
|
|
|
|
matchObj = re.match( "^\s*(?P<attrName>[^=]+)=(?P<attrValue>.*)$", strAttrDef )
|
2012-02-07 15:14:48 +01:00
|
|
|
|
#print matchObj.group("attrName")
|
|
|
|
|
self.m_attrs[ matchObj.group("attrName") ] = matchObj.group("attrValue")
|
|
|
|
|
def asFormat1String( self ):
|
|
|
|
|
strResult = ""
|
2019-07-10 10:34:42 +02:00
|
|
|
|
for (k,v) in self.m_attrs.items():
|
2012-02-07 15:14:48 +01:00
|
|
|
|
#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
|
2019-07-10 10:34:42 +02:00
|
|
|
|
for (k,v) in self.m_attrs.items():
|
2012-02-07 15:14:48 +01:00
|
|
|
|
#print "%s %s" % (k,v)
|
|
|
|
|
strResult += "%s=%s" % (k,v)
|
|
|
|
|
if iAttr != (iNumAttrs - 1):
|
|
|
|
|
strResult += ","
|
|
|
|
|
iAttr+=1
|
|
|
|
|
#print strSgeConfigString
|
|
|
|
|
return strResult
|
2013-12-06 11:41:50 +01:00
|
|
|
|
def dump( self ):
|
2019-07-10 10:34:42 +02:00
|
|
|
|
for (k,v) in self.m_attrs.items():
|
|
|
|
|
print("['%s']='%s'" % (k,v))
|
2013-12-06 11:41:50 +01:00
|
|
|
|
|
2012-02-07 15:14:48 +01:00
|
|
|
|
|