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


Python CFG.loadFromDict方法代码示例

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


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

示例1: convertSites

# 需要导入模块: from DIRAC.Core.Utilities.CFG import CFG [as 别名]
# 或者: from DIRAC.Core.Utilities.CFG.CFG import loadFromDict [as 别名]
def convertSites():
  
  global csapi
  
  gLogger.notice( 'Converting Computing services' )
  
  # Collect site info
  infoDict = {}
  result = gConfig.getSections( '/Resources/Sites' ) 
  
  print result
  
  if not result['OK']:
    return result
  domains = result['Value']
  for domain in domains:
    gLogger.notice( 'Analyzing domain %s' % domain )
    result = gConfig.getSections( '/Resources/Sites/%s' % domain )
    if not result['OK']:
      return result 
    sites = result['Value']
    for site in sites:
      result = getSiteName( site )
      if not result['OK']:
        gLogger.error( 'Invalid site name %s' % site )
        continue
      siteName = result['Value']
      country = result['Country']
      
      print "AT >>> siteName, country", siteName, country
      
      gLogger.notice( 'Analyzing site %s' % siteName )
      result = gConfig.getOptionsDict( '/Resources/Sites/%s/%s' % (domain,site) )
      if not result['OK']:
        return result 
      siteDict = result['Value']
      siteDict['Country'] = country
      if 'Name' in siteDict:
        siteDict['GOCName'] = siteDict['Name']
        del siteDict['Name']
      if "CE" in siteDict:
        del siteDict['CE']
      if 'SE' in siteDict:
        del siteDict['SE']  
      infoDict.setdefault( siteName, siteDict )
      infoDict[siteName].setdefault( 'Domain', [] )
      infoDict[siteName]['Domain'].append( domain )
      if 'VO' in siteDict:
        communities = List.fromChar( siteDict['VO'] )
        infoDict[siteName]['VO'] = communities
      result = gConfig.getSections('/Resources/Sites/%s/%s/CEs' % (domain,site))
      if not result['OK']:
        if 'does not exist' in result['Message']:
          continue
        return result
      ces = result['Value']
      for ce in ces:
        result = gConfig.getOptionsDict( '/Resources/Sites/%s/%s/CEs/%s' % (domain,site,ce) )
        if not result['OK']:
          return result 
        ceDict = result['Value']
        
        ceName = ce.split('.')[0]
        if not 'Host' in ceDict:
          ceDict['Host'] = ce
        if not "SubmissionMode" in ceDict or ceDict['SubmissionMode'].lower() != "direct":
          ceDict['SubmissionMode'] = 'gLite'   
        
        infoDict[siteName].setdefault( 'Computing', {} )
        infoDict[siteName]['Computing'][ceName] = ceDict
        if 'VO' in ceDict:
          communities = List.fromChar( ceDict['VO'] )
          infoDict[siteName]['Computing'][ceName]['VO'] = communities
          del ceDict['VO']
        result = gConfig.getSections('/Resources/Sites/%s/%s/CEs/%s/Queues' % (domain,site,ce))
        if not result['OK']:
          if 'does not exist' in result['Message']:
            continue
          return result
        queues = result['Value']
        for queue in queues:
          result = gConfig.getOptionsDict( '/Resources/Sites/%s/%s/CEs/%s/Queues/%s' % (domain,site,ce,queue) )
          if not result['OK']:
            return result 
          queueDict = result['Value']
          infoDict[siteName]['Computing'][ceName].setdefault( 'Queues', {} )
          infoDict[siteName]['Computing'][ceName]['Queues'][queue] = queueDict
          if 'VO' in queueDict:
            communities = List.fromChar( queueDict['VO'] )
            infoDict[siteName]['Computing'][ceName]['Queues'][queue]['VO'] = communities
            del queueDict['VO']
        
      cfg = CFG()
      cfg.loadFromDict( infoDict[siteName] )
      
      print "AT >>> siteName, cfg", siteName, cfg.serialize()
      
      csapi.mergeCFGUnderSection( '%s/Sites/%s' % (RESOURCES_NEW_SECTION,siteName), cfg)
      csapi.sortSection( '%s/Sites/%s/Computing' % (RESOURCES_NEW_SECTION,siteName) )
             
#.........这里部分代码省略.........
开发者ID:graciani,项目名称:DIRAC,代码行数:103,代码来源:dirac-configuration-convert-resources-schema.py

示例2: convertSEs

# 需要导入模块: from DIRAC.Core.Utilities.CFG import CFG [as 别名]
# 或者: from DIRAC.Core.Utilities.CFG.CFG import loadFromDict [as 别名]
def convertSEs():
  
  global csapi, defaultSite
  
  gLogger.notice( 'Converting Storage services' )
  
  result = gConfig.getSections('/Resources/StorageElements' )
  if not result['OK']:
    return result
  ses = result['Value']  
  result = gConfig.getSections('/Resources/Sites')
  if not result['OK']:
    return result
  grids = result['Value']
  sites = []
  for grid in grids:
    result = gConfig.getSections('/Resources/Sites/%s' % grid)
    if not result['OK']:
      return result  
    sites += result['Value']
  sites = [ getSiteName(site)['Value'] for site in sites ]  
    
    
  for se in ses:
    
    cfg = CFG()
    
    # Try to guess the site
    seSite = 'Unknown'
    seName = 'Unknown'
    for site in sites:
      if se.startswith(site):
        seSite = site
        seName = se.replace( site, '' )[1:]
    if seName == 'Unknown':
      seName = se    
    
    defaultFlag = False
    if defaultSite:
      if seSite == "Unknown":
        seSite = defaultSite
        defaultFlag = True
  
    inputSite = raw_input("Processing SE %s, new name %s located at site [%s]: " % ( se,seName,seSite ) )    
    if not inputSite:
      if seSite == 'Unknown':
        inputSite = raw_input("Please, provide the site name for SE %s: " % se )
      else:
        site = seSite
    else:
      site = inputSite
    if defaultFlag:
      inputSE = raw_input("New SE name [%s]: " % seName )
      if inputSE:
        seName = inputSE                      
    
    sePath = '/Resources/StorageElements/%s' % se  
    result = gConfig.getOptionsDict(sePath)
    if not result['OK']:
      gLogger.error(result['Message'])
      return result      
    seDict = result['Value']
    result = gConfig.getSections(sePath)
    if not result['OK']:
      gLogger.error(result['Message'])
      return result   
    
    seDict['AccessProtocols'] = {}
    protocols = result['Value']
    for protocol in protocols:
      result = gConfig.getOptionsDict(sePath+'/'+protocol)
      if not result['OK']:
        gLogger.error(result['Message'])
        return result      
      protoDict = result['Value']
      protoName = protoDict['ProtocolName']
      seDict['AccessProtocols'][protoName] = protoDict
      
    cfg = CFG()  
    cfg.loadFromDict( seDict )
    csapi.createSection('%s/Sites/%s/Storage/%s' % (RESOURCES_NEW_SECTION,site,seName))
    csapi.mergeCFGUnderSection( '%s/Sites/%s/Storage/%s' % (RESOURCES_NEW_SECTION,site,seName), cfg)    
          
  return S_OK()       
开发者ID:graciani,项目名称:DIRAC,代码行数:86,代码来源:dirac-configuration-convert-resources-schema.py


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