当前位置: 首页>>代码示例>>Python>>正文


Python CFG.getRecursive方法代码示例

本文整理汇总了Python中DIRAC.Core.Utilities.CFG.CFG.getRecursive方法的典型用法代码示例。如果您正苦于以下问题:Python CFG.getRecursive方法的具体用法?Python CFG.getRecursive怎么用?Python CFG.getRecursive使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DIRAC.Core.Utilities.CFG.CFG的用法示例。


在下文中一共展示了CFG.getRecursive方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: execute

# 需要导入模块: from DIRAC.Core.Utilities.CFG import CFG [as 别名]
# 或者: from DIRAC.Core.Utilities.CFG.CFG import getRecursive [as 别名]
  def execute( self ):
    """ execute
    
    """

    stopAgents = self.findStopAgents()[ 'Value' ]
    if stopAgents:
      self.log.info( 'Aborting, there are stop_agents to be picked' )
      return S_OK()

    pilotVersion = self.opHelper.getValue( 'Pilot/Version', '' )
    if not pilotVersion:
      self.log.error( 'There is no pilot version on the CS' )
      return S_OK()

    pilotVersion = self.getNewestPilotVersion()
    if not pilotVersion[ 'OK' ]:
      self.log.error( pilotVersion[ 'Message' ] )
      return S_ERROR( pilotVersion[ 'Message' ] )
    pilotVersion = pilotVersion[ 'Value' ]
      
    localCFG = CFG()
    
    #load local CFG
    localCFG.loadFromFile( self.cfgToUpdate )
    releaseVersion = localCFG.getRecursive( 'LocalSite/ReleaseVersion' )[ 'value' ]
    
    self.log.info( 'PilotVersion : %s' % pilotVersion )
    self.log.info( 'ReleaseVersion : %s' % releaseVersion )
            
    if LooseVersion( pilotVersion ) > LooseVersion( releaseVersion ):
    
      self.log.info( 'UPDATING %s > %s' % ( pilotVersion, releaseVersion ) )
    
      localCFG.setOption( 'LocalSite/ReleaseVersion', pilotVersion )
      localCFG.writeToFile( self.cfgToUpdate )  
      
      self.touchStopAgents()
    
    else:
      
      self.log.info( 'Nothing to do' )
    
    return S_OK()     
开发者ID:myco,项目名称:VMDIRAC,代码行数:46,代码来源:VirtualMachineConfigUpdater.py

示例2: JobManifest

# 需要导入模块: from DIRAC.Core.Utilities.CFG import CFG [as 别名]
# 或者: from DIRAC.Core.Utilities.CFG.CFG import getRecursive [as 别名]

#.........这里部分代码省略.........
        if not result["OK"]:
            return result

        result = self.__checkMultiChoice("PilotTypes", ["private"])
        if not result["OK"]:
            return result

        maxInputData = Operations().getValue("JobDescription/MaxInputData", 500)
        result = self.__checkMaxInputData(maxInputData)
        if not result["OK"]:
            return result

        transformationTypes = Operations().getValue("Transformations/DataProcessing", [])
        result = self.__checkMultiChoice("JobType", ["User", "Test", "Hospital"] + transformationTypes)
        if not result["OK"]:
            return result
        return S_OK()

    def createSection(self, secName, contents=False):
        if secName not in self.__manifest:
            if contents and not isinstance(contents, CFG):
                return S_ERROR("Contents for section %s is not a cfg object" % secName)
            self.__dirty = True
            return S_OK(self.__manifest.createNewSection(secName, contents=contents))
        return S_ERROR("Section %s already exists" % secName)

    def getSection(self, secName):
        self.__dirty = True
        sec = self.__manifest[secName]
        if not sec:
            return S_ERROR("%s does not exist")
        return S_OK(sec)

    def setSectionContents(self, secName, contents):
        if contents and not isinstance(contents, CFG):
            return S_ERROR("Contents for section %s is not a cfg object" % secName)
        self.__dirty = True
        if secName in self.__manifest:
            self.__manifest[secName].reset()
            self.__manifest[secName].mergeWith(contents)
        else:
            self.__manifest.createNewSection(secName, contents=contents)

    def setOption(self, varName, varValue):
        """
    Set a var in job manifest
    """
        self.__dirty = True
        levels = List.fromChar(varName, "/")
        cfg = self.__manifest
        for l in levels[:-1]:
            if l not in cfg:
                cfg.createNewSection(l)
            cfg = cfg[l]
        cfg.setOption(levels[-1], varValue)

    def remove(self, opName):
        levels = List.fromChar(opName, "/")
        cfg = self.__manifest
        for l in levels[:-1]:
            if l not in cfg:
                return S_ERROR("%s does not exist" % opName)
            cfg = cfg[l]
        if cfg.deleteKey(levels[-1]):
            self.__dirty = True
            return S_OK()
        return S_ERROR("%s does not exist" % opName)

    def getOption(self, varName, defaultValue=None):
        """
     Get a variable from the job manifest
    """
        cfg = self.__manifest
        return cfg.getOption(varName, defaultValue)

    def getOptionList(self, section=""):
        """
    Get a list of variables in a section of the job manifest
    """
        cfg = self.__manifest.getRecursive(section)
        if not cfg or "value" not in cfg:
            return []
        cfg = cfg["value"]
        return cfg.listOptions()

    def isOption(self, opName):
        """
    Check if it is a valid option
    """
        return self.__manifest.isOption(opName)

    def getSectionList(self, section=""):
        """
    Get a list of sections in the job manifest
    """
        cfg = self.__manifest.getRecursive(section)
        if not cfg or "value" not in cfg:
            return []
        cfg = cfg["value"]
        return cfg.listSections()
开发者ID:DIRACGrid,项目名称:DIRAC,代码行数:104,代码来源:JobManifest.py

示例3: __init__

# 需要导入模块: from DIRAC.Core.Utilities.CFG import CFG [as 别名]
# 或者: from DIRAC.Core.Utilities.CFG.CFG import getRecursive [as 别名]

#.........这里部分代码省略.........
        createdSection = True
      cfg = cfg[ section ]
    return createdSection

  def setComment( self, entryPath, value ):
    cfg = self.__getParentCFG( entryPath )
    entry = List.fromChar( entryPath, "/" )[-1]
    if cfg.setComment( entry, value ):
      self.__setCommiter( entryPath )
      return True
    return False

  def existsSection( self, sectionPath ):
    sectionList = List.fromChar( sectionPath, "/" )
    cfg = self.cfgData
    try:
      for section in sectionList[:-1]:
        cfg = cfg[ section ]
      return len( sectionList ) == 0 or sectionList[-1] in cfg.listSections()
    except:
      return False

  def existsOption( self, optionPath ):
    sectionList = List.fromChar( optionPath, "/" )
    cfg = self.cfgData
    try:
      for section in sectionList[:-1]:
        cfg = cfg[ section ]
      return sectionList[-1] in cfg.listOptions()
    except:
      return False

  def renameKey( self, path, newName ):
    parentCfg = self.cfgData.getRecursive( path, -1 )
    if not parentCfg:
      return False
    pathList = List.fromChar( path, "/" )
    oldName = pathList[-1]
    if parentCfg[ 'value' ].renameKey( oldName, newName ):
      pathList[-1] = newName
      self.__setCommiter( "/%s" % "/".join( pathList ) )
      return True
    else:
      return False

  def copyKey( self, originalKeyPath, newKey ):
    parentCfg = self.cfgData.getRecursive( originalKeyPath, -1 )
    if not parentCfg:
      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
开发者ID:ahaupt,项目名称:DIRAC,代码行数:70,代码来源:Modificator.py

示例4: S_OK

# 需要导入模块: from DIRAC.Core.Utilities.CFG import CFG [as 别名]
# 或者: from DIRAC.Core.Utilities.CFG.CFG import getRecursive [as 别名]
        session.save()
        return S_OK(modCfg.getComment(path))

    @jsonify
    def moveNode(self):
        try:
            nodePath = request.params["nodePath"]
            destinationParentPath = request.params["parentPath"]
            beforeOfIndex = int(request.params["beforeOfIndex"])
        except Exception, e:
            return S_ERROR("Can't decode parameter: %s" % str(e))

        gLogger.info("Moving %s under %s before pos %s" % (nodePath, destinationParentPath, beforeOfIndex))
        cfgData = CFG()
        cfgData.loadFromBuffer(session["cfgData"])
        nodeDict = cfgData.getRecursive(nodePath)
        if not nodeDict:
            return S_ERROR("Moving entity does not exist")
        oldParentDict = cfgData.getRecursive(nodePath, -1)
        newParentDict = cfgData.getRecursive(destinationParentPath)
        if type(newParentDict) == types.StringType:
            return S_ERROR("Destination is not a section")
        if not newParentDict:
            return S_ERROR("Destination does not exist")
        # Calculate the old parent path
        oldParentPath = "/%s" % "/".join(List.fromChar(nodePath, "/")[:-1])
        if not oldParentPath == destinationParentPath and newParentDict["value"].existsKey(nodeDict["key"]):
            return S_ERROR("Another entry with the same name already exists")

        try:
            brothers = newParentDict["value"].listAll()
开发者ID:sfayer,项目名称:DIRACWeb,代码行数:33,代码来源:configuration.py

示例5: JobDescription

# 需要导入模块: from DIRAC.Core.Utilities.CFG import CFG [as 别名]
# 或者: from DIRAC.Core.Utilities.CFG.CFG import getRecursive [as 别名]

#.........这里部分代码省略.........
    return S_OK( varValue )

  def __checkMultiChoiceInDescription( self, varName, choices ):
    """
    Check a multi choice var
    """
    initialVal = False
    if varName not in self.__description:
      return S_OK()
    else:
      varValue = self.__description[ varName ]
      initialVal = varValue
    choices = Operations().getValue( "JobDescription/Choices%s" % varName , choices )
    for v in List.fromChar( varValue ):
      if v not in choices:
        return S_ERROR( "%s is not a valid value for %s" % ( v, varName ) )
    if initialVal != varValue:
      self.__description.setOption( varName, varValue )
    return S_OK( varValue )

  def __checkMaxInputData( self, maxNumber ):
    """
    Check Maximum Number of Input Data files allowed
    """
    varName = "InputData"
    if varName not in self.__description:
      return S_OK()
    varValue = self.__description[ varName ]
    if len( List.fromChar( varValue ) ) > maxNumber:
      return S_ERROR( 'Number of Input Data Files (%s) greater than current limit: %s' % ( len( List.fromChar( varValue ) ), maxNumber ) )
    return S_OK()

  def setVarsFromDict( self, varDict ):
    for k in sorted( varDict ):
      self.setVar( k, varDict[ k ] )

  def checkDescription( self ):
    """
    Check that the description is OK
    """
    for k in [ 'OwnerName', 'OwnerDN', 'OwnerGroup', 'DIRACSetup' ]:
      if k not in self.__description:
        return S_ERROR( "Missing var %s in description" % k )
    # Check CPUTime
    result = self.__checkNumericalVarInDescription( "CPUTime", 86400, 0, 500000 )
    if not result[ 'OK' ]:
      return result
    result = self.__checkNumericalVarInDescription( "Priority", 1, 0, 10 )
    if not result[ 'OK' ]:
      return result

    allowedSubmitPools = getSubmitPools( self.__description['OwnerGroup'] )
    result = self.__checkMultiChoiceInDescription( "SubmitPools", list( set( allowedSubmitPools ) ) )
    if not result[ 'OK' ]:
      return result

    result = self.__checkMultiChoiceInDescription( "SubmitPools", list( set( allowedSubmitPools ) ) )
    if not result[ 'OK' ]:
      return result
    result = self.__checkMultiChoiceInDescription( "PilotTypes", [ 'private' ] )
    if not result[ 'OK' ]:
      return result
    maxInputData = Operations().getValue( "JobDescription/MaxInputData", 500 )
    result = self.__checkMaxInputData( maxInputData )
    if not result[ 'OK' ]:
      return result
    transformationTypes = Operations().getValue( "Transformations/DataProcessing", [] )
    result = self.__checkMultiChoiceInDescription( "JobType", ['User', 'Test', 'Hospital'] + transformationTypes )
    return S_OK()

  def setVar( self, varName, varValue ):
    """
    Set a var in job description
    """
    self.__dirty = True
    levels = List.fromChar( varName, "/" )
    cfg = self.__description
    for l in levels[:-1]:
      if l not in cfg:
        cfg.createNewSection( l )
      cfg = cfg[ l ]
    cfg.setOption( levels[-1], varValue )

  def getVar( self, varName, defaultValue = None ):
    cfg = self.__description
    return cfg.getOption( varName, defaultValue )

  def getOptionList( self, section = "" ):
    cfg = self.__description.getRecursive( section )
    if not cfg or 'value' not in cfg:
      return []
    cfg = cfg[ 'value' ]
    return cfg.listOptions()

  def getSectionList( self, section = "" ):
    cfg = self.__description.getRecursive( section )
    if not cfg or 'value' not in cfg:
      return []
    cfg = cfg[ 'value' ]
    return cfg.listSections()
开发者ID:DIRACGrid-test,项目名称:DIRAC,代码行数:104,代码来源:JobDescription.py


注:本文中的DIRAC.Core.Utilities.CFG.CFG.getRecursive方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。