本文整理汇总了Python中DIRAC.Core.Utilities.CFG.CFG.mergeWith方法的典型用法代码示例。如果您正苦于以下问题:Python CFG.mergeWith方法的具体用法?Python CFG.mergeWith怎么用?Python CFG.mergeWith使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DIRAC.Core.Utilities.CFG.CFG
的用法示例。
在下文中一共展示了CFG.mergeWith方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _parseConfigTemplate
# 需要导入模块: from DIRAC.Core.Utilities.CFG import CFG [as 别名]
# 或者: from DIRAC.Core.Utilities.CFG.CFG import mergeWith [as 别名]
def _parseConfigTemplate(self, templatePath, cfg=None):
"""Parse the ConfigTemplate.cfg files.
:param str templatePath: path to the folder containing a ConfigTemplate.cfg file
:param CFG cfg: cfg to merge with the systems config
:returns: CFG object
"""
cfg = CFG() if cfg is None else cfg
system = os.path.split(templatePath.rstrip("/"))[1]
if system.lower().endswith('system'):
system = system[:-len('System')]
if self.systems and system not in self.systems:
return S_OK(cfg)
templatePath = os.path.join(templatePath, 'ConfigTemplate.cfg')
if not os.path.exists(templatePath):
return S_ERROR("File not found: %s" % templatePath)
loadCfg = CFG()
loadCfg.loadFromFile(templatePath)
newCfg = CFG()
newCfg.createNewSection("/%s" % system, contents=loadCfg)
cfg = cfg.mergeWith(newCfg)
return S_OK(cfg)
示例2: mergeWithServer
# 需要导入模块: from DIRAC.Core.Utilities.CFG import CFG [as 别名]
# 或者: from DIRAC.Core.Utilities.CFG.CFG import mergeWith [as 别名]
def mergeWithServer( self ):
retVal = self.rpcClient.getCompressedData()
if retVal[ 'OK' ]:
remoteCFG = CFG()
remoteCFG.loadFromBuffer( zlib.decompress( retVal[ 'Value' ] ) )
serverVersion = gConfigurationData.getVersion( remoteCFG )
self.cfgData = remoteCFG.mergeWith( self.cfgData )
gConfigurationData.setVersion( serverVersion, self.cfgData )
return retVal
示例3: loadWebAppCFGFiles
# 需要导入模块: from DIRAC.Core.Utilities.CFG import CFG [as 别名]
# 或者: from DIRAC.Core.Utilities.CFG.CFG import mergeWith [as 别名]
def loadWebAppCFGFiles():
"""
Load WebApp/web.cfg definitions
"""
exts = []
for ext in CSGlobals.getCSExtensions():
if ext == "DIRAC":
continue
if ext[-5:] != "DIRAC":
ext = "%sDIRAC" % ext
if ext != "WebAppDIRAC":
exts.append( ext )
exts.append( "DIRAC" )
exts.append( "WebAppDIRAC" )
webCFG = CFG()
for modName in reversed( exts ):
try:
modPath = imp.find_module( modName )[1]
except ImportError:
continue
gLogger.verbose( "Found module %s at %s" % ( modName, modPath ) )
cfgPath = os.path.join( modPath, "WebApp", "web.cfg" )
if not os.path.isfile( cfgPath ):
gLogger.verbose( "Inexistant %s" % cfgPath )
continue
try:
modCFG = CFG().loadFromFile( cfgPath )
except Exception, excp:
gLogger.error( "Could not load %s: %s" % ( cfgPath, excp ) )
continue
gLogger.verbose( "Loaded %s" % cfgPath )
expl = [ BASECS ]
while len( expl ):
current = expl.pop( 0 )
if not modCFG.isSection( current ):
continue
if modCFG.getOption( "%s/AbsoluteDefinition" % current, False ):
gLogger.verbose( "%s:%s is an absolute definition" % ( modName, current ) )
try:
webCFG.deleteKey( current )
except:
pass
modCFG.deleteKey( "%s/AbsoluteDefinition" % current )
else:
for sec in modCFG[ current ].listSections():
expl.append( "%s/%s" % ( current, sec ) )
#Add the modCFG
webCFG = webCFG.mergeWith( modCFG )
示例4: _loadWebAppCFGFiles
# 需要导入模块: from DIRAC.Core.Utilities.CFG import CFG [as 别名]
# 或者: from DIRAC.Core.Utilities.CFG.CFG import mergeWith [as 别名]
def _loadWebAppCFGFiles(self, extension):
"""
Load WebApp/web.cfg definitions
:param str extension: the module name of the extension of WebAppDirac for example: LHCbWebDIRAC
"""
exts = [extension, "WebAppDIRAC"]
webCFG = CFG()
for modName in reversed(exts):
cfgPath = os.path.join(self.__params.destination, "%s/WebApp" % modName, "web.cfg")
if not os.path.isfile(cfgPath):
gLogger.verbose("Web configuration file %s does not exists!" % cfgPath)
continue
try:
modCFG = CFG().loadFromFile(cfgPath)
except Exception, excp:
gLogger.error("Could not load %s: %s" % (cfgPath, excp))
continue
gLogger.verbose("Loaded %s" % cfgPath)
expl = ["/WebApp"]
while len(expl):
current = expl.pop(0)
if not modCFG.isSection(current):
continue
if modCFG.getOption("%s/AbsoluteDefinition" % current, False):
gLogger.verbose("%s:%s is an absolute definition" % (modName, current))
try:
webCFG.deleteKey(current)
except:
pass
modCFG.deleteKey("%s/AbsoluteDefinition" % current)
else:
for sec in modCFG[current].listSections():
expl.append("%s/%s" % (current, sec))
# Add the modCFG
webCFG = webCFG.mergeWith(modCFG)
示例5: __init__
# 需要导入模块: from DIRAC.Core.Utilities.CFG import CFG [as 别名]
# 或者: from DIRAC.Core.Utilities.CFG.CFG import mergeWith [as 别名]
class ConfigurationData:
def __init__( self, loadDefaultCFG = True ):
lr = LockRing()
self.threadingEvent = lr.getEvent()
self.threadingEvent.set()
self.threadingLock = lr.getLock()
self.runningThreadsNumber = 0
self.compressedConfigurationData = ""
self.configurationPath = "/DIRAC/Configuration"
self.backupsDir = os.path.join( DIRAC.rootPath, "etc", "csbackup" )
self._isService = False
self.localCFG = CFG()
self.remoteCFG = CFG()
self.mergedCFG = CFG()
self.remoteServerList = []
if loadDefaultCFG:
defaultCFGFile = os.path.join( DIRAC.rootPath, "etc", "dirac.cfg" )
gLogger.debug( "dirac.cfg should be at", "%s" % defaultCFGFile )
retVal = self.loadFile( defaultCFGFile )
if not retVal[ 'OK' ]:
gLogger.warn( "Can't load %s file" % defaultCFGFile )
self.sync()
def getBackupDir( self ):
return self.backupsDir
def sync( self ):
gLogger.debug( "Updating configuration internals" )
self.mergedCFG = self.remoteCFG.mergeWith( self.localCFG )
self.remoteServerList = []
localServers = self.extractOptionFromCFG( "%s/Servers" % self.configurationPath,
self.localCFG,
disableDangerZones = True )
if localServers:
self.remoteServerList.extend( List.fromChar( localServers, "," ) )
remoteServers = self.extractOptionFromCFG( "%s/Servers" % self.configurationPath,
self.remoteCFG,
disableDangerZones = True )
if remoteServers:
self.remoteServerList.extend( List.fromChar( remoteServers, "," ) )
self.remoteServerList = List.uniqueElements( self.remoteServerList )
self.compressedConfigurationData = zlib.compress( str( self.remoteCFG ), 9 )
def loadFile( self, fileName ):
try:
fileCFG = CFG()
fileCFG.loadFromFile( fileName )
except IOError:
self.localCFG = self.localCFG.mergeWith( fileCFG )
return S_ERROR( "Can't load a cfg file '%s'" % fileName )
return self.mergeWithLocal( fileCFG )
def mergeWithLocal( self, extraCFG ):
self.lock()
try:
self.localCFG = self.localCFG.mergeWith( extraCFG )
self.unlock()
gLogger.debug( "CFG merged" )
except Exception, e:
self.unlock()
return S_ERROR( "Cannot merge with new cfg: %s" % str( e ) )
self.sync()
return S_OK()
示例6: CFG
# 需要导入模块: from DIRAC.Core.Utilities.CFG import CFG [as 别名]
# 或者: from DIRAC.Core.Utilities.CFG.CFG import mergeWith [as 别名]
DIRAC.gLogger.initialize('test_gConfig','/testSectionDebug')
testconfig = '%s/DIRAC/ConfigurationSystem/test/test.cfg' % DIRAC.rootPath
dumpconfig = '%s/DIRAC/ConfigurationSystem/test/dump.cfg' % DIRAC.rootPath
cfg1 = CFG()
cfg1.loadFromFile( testconfig )
fd = file( testconfig )
cfg1String = fd.read()
fd.close()
cfg2 = CFG()
cfg2.loadFromBuffer( cfg1.serialize() )
cfg3 = cfg1.mergeWith( cfg2 )
testList = [{ 'method' : DIRAC.gConfig.loadFile,
'arguments' : ( testconfig, ),
'output' : {'OK': True, 'Value': ''}
},
{ 'method' : DIRAC.gConfig.dumpLocalCFGToFile,
'arguments' : ( dumpconfig, ),
'output' : {'OK': True, 'Value': ''}
},
{ 'method' : cfg1.serialize,
'arguments' : ( ),
'output' : cfg1String
},
{ 'method' : cfg3.serialize,
'arguments' : ( ),
示例7: __init__
# 需要导入模块: from DIRAC.Core.Utilities.CFG import CFG [as 别名]
# 或者: from DIRAC.Core.Utilities.CFG.CFG import mergeWith [as 别名]
#.........这里部分代码省略.........
return False
pathList = List.fromChar( originalKeyPath, "/" )
originalKey = pathList[-1]
if parentCfg[ 'value' ].copyKey( originalKey, newKey ):
self.__setCommiter( "/%s/%s" % ( "/".join( pathList[:-1] ), newKey ) )
return True
return False
def removeOption( self, optionPath ):
if not self.existsOption( optionPath ):
return False
cfg = self.__getParentCFG( optionPath )
optionName = List.fromChar( optionPath, "/" )[-1]
return cfg.deleteKey( optionName )
def removeSection( self, sectionPath ):
if not self.existsSection( sectionPath ):
return False
cfg = self.__getParentCFG( sectionPath )
sectionName = List.fromChar( sectionPath, "/" )[-1]
return cfg.deleteKey( sectionName )
def loadFromBuffer( self, data ):
self.cfgData = CFG()
self.cfgData.loadFromBuffer( data )
def loadFromFile( self, filename ):
self.cfgData = CFG()
self.mergeFromFile( filename )
def dumpToFile( self, filename ):
fd = file( filename, "w" )
fd.write( str( self.cfgData ) )
fd.close()
def mergeFromFile( self, filename ):
cfg = CFG()
cfg.loadFromFile( filename )
self.cfgData = self.cfgData.mergeWith( cfg )
def mergeFromCFG( self, cfg ):
self.cfgData = self.cfgData.mergeWith( cfg )
def mergeSectionFromCFG( self, sectionPath, cfg ):
parentDict = self.cfgData.getRecursive( sectionPath, -1 )
parentCFG = parentDict[ 'value' ]
secName = [ lev.strip() for lev in sectionPath.split( "/" ) if lev.strip() ][-1]
secCFG = parentCFG[ secName ]
if not secCFG:
return False
mergedCFG = secCFG.mergeWith( cfg )
parentCFG.deleteKey( secName )
parentCFG.createNewSection( secName, parentDict[ 'comment' ], mergedCFG )
self.__setCommiter( sectionPath )
return True
def __str__( self ):
return str( self.cfgData )
def commit( self ):
compressedData = zlib.compress( str( self.cfgData ), 9 )
return self.rpcClient.commitNewData( compressedData )
def getHistory( self, limit = 0 ):
retVal = self.rpcClient.getCommitHistory( limit )
if retVal[ 'OK' ]:
return retVal[ 'Value' ]
return []
def showCurrentDiff( self ):
retVal = self.rpcClient.getCompressedData()
if retVal[ 'OK' ]:
remoteData = zlib.decompress( retVal[ 'Value' ] ).splitlines()
localData = str( self.cfgData ).splitlines()
return difflib.ndiff( remoteData, localData )
return []
def getVersionDiff( self, fromDate, toDate ):
retVal = self.rpcClient.getVersionContents( [ fromDate, toDate ] )
if retVal[ 'OK' ]:
fromData = zlib.decompress( retVal[ 'Value' ][0] )
toData = zlib.decompress( retVal[ 'Value' ][1] )
return difflib.ndiff( fromData.split( "\n" ), toData.split( "\n" ) )
return []
def mergeWithServer( self ):
retVal = self.rpcClient.getCompressedData()
if retVal[ 'OK' ]:
remoteCFG = CFG()
remoteCFG.loadFromBuffer( zlib.decompress( retVal[ 'Value' ] ) )
serverVersion = gConfigurationData.getVersion( remoteCFG )
self.cfgData = remoteCFG.mergeWith( self.cfgData )
gConfigurationData.setVersion( serverVersion, self.cfgData )
return retVal
def rollbackToVersion( self, version ):
return self.rpcClient.rollbackToVersion( version )
def updateGConfigurationData( self ):
gConfigurationData.setRemoteCFG( self.cfgData )
示例8: ConfigurationData
# 需要导入模块: from DIRAC.Core.Utilities.CFG import CFG [as 别名]
# 或者: from DIRAC.Core.Utilities.CFG.CFG import mergeWith [as 别名]
class ConfigurationData( object ):
def __init__( self, loadDefaultCFG = True ):
lr = LockRing()
self.threadingEvent = lr.getEvent()
self.threadingEvent.set()
self.threadingLock = lr.getLock()
self.runningThreadsNumber = 0
self.__compressedConfigurationData = None
self.configurationPath = "/DIRAC/Configuration"
self.backupsDir = os.path.join( DIRAC.rootPath, "etc", "csbackup" )
self._isService = False
self.localCFG = CFG()
self.remoteCFG = CFG()
self.mergedCFG = CFG()
self.remoteServerList = []
if loadDefaultCFG:
defaultCFGFile = os.path.join( DIRAC.rootPath, "etc", "dirac.cfg" )
gLogger.debug( "dirac.cfg should be at", "%s" % defaultCFGFile )
retVal = self.loadFile( defaultCFGFile )
if not retVal[ 'OK' ]:
gLogger.warn( "Can't load %s file" % defaultCFGFile )
self.sync()
def getBackupDir( self ):
return self.backupsDir
def sync( self ):
gLogger.debug( "Updating configuration internals" )
self.mergedCFG = self.remoteCFG.mergeWith( self.localCFG )
self.remoteServerList = []
localServers = self.extractOptionFromCFG( "%s/Servers" % self.configurationPath,
self.localCFG,
disableDangerZones = True )
if localServers:
self.remoteServerList.extend( List.fromChar( localServers, "," ) )
remoteServers = self.extractOptionFromCFG( "%s/Servers" % self.configurationPath,
self.remoteCFG,
disableDangerZones = True )
if remoteServers:
self.remoteServerList.extend( List.fromChar( remoteServers, "," ) )
self.remoteServerList = List.uniqueElements( self.remoteServerList )
self.__compressedConfigurationData = None
def loadFile( self, fileName ):
try:
fileCFG = CFG()
fileCFG.loadFromFile( fileName )
except IOError:
self.localCFG = self.localCFG.mergeWith( fileCFG )
return S_ERROR( "Can't load a cfg file '%s'" % fileName )
return self.mergeWithLocal( fileCFG )
def mergeWithLocal( self, extraCFG ):
self.lock()
try:
self.localCFG = self.localCFG.mergeWith( extraCFG )
self.unlock()
gLogger.debug( "CFG merged" )
except Exception as e:
self.unlock()
return S_ERROR( "Cannot merge with new cfg: %s" % str( e ) )
self.sync()
return S_OK()
def loadRemoteCFGFromCompressedMem( self, data ):
sUncompressedData = zlib.decompress( data )
self.loadRemoteCFGFromMem( sUncompressedData )
def loadRemoteCFGFromMem( self, data ):
self.lock()
self.remoteCFG.loadFromBuffer( data )
self.unlock()
self.sync()
def loadConfigurationData( self, fileName = False ):
name = self.getName()
self.lock()
try:
if not fileName:
fileName = "%s.cfg" % name
if fileName[0] != "/":
fileName = os.path.join( DIRAC.rootPath, "etc", fileName )
self.remoteCFG.loadFromFile( fileName )
except Exception as e:
print e
pass
self.unlock()
self.sync()
def getCommentFromCFG( self, path, cfg = False ):
if not cfg:
cfg = self.mergedCFG
self.dangerZoneStart()
try:
levelList = [ level.strip() for level in path.split( "/" ) if level.strip() != "" ]
for section in levelList[:-1]:
cfg = cfg[ section ]
return self.dangerZoneEnd( cfg.getComment( levelList[-1] ) )
except Exception:
#.........这里部分代码省略.........