def warmUp(): """ gConfig has its own dark side, it needs some warm up phase. """ from DIRAC.ConfigurationSystem.private.Refresher import gRefresher gRefresher.refreshConfigurationIfNeeded()
def getOptions( self, sectionPath, listOrdered = True ): gRefresher.refreshConfigurationIfNeeded() optionList = gConfigurationData.getOptionsFromCFG( sectionPath, ordered = listOrdered ) if type( optionList ) == types.ListType: return S_OK( optionList ) else: return S_ERROR( "Path %s does not exist or it's not a section" % sectionPath )
def getOption( self, optionPath, typeValue = None ): gRefresher.refreshConfigurationIfNeeded() optionValue = gConfigurationData.extractOptionFromCFG( optionPath ) if optionValue == None: return S_ERROR( "Path %s does not exist or it's not an option" % optionPath ) #Value has been returned from the configuration if typeValue == None: return S_OK( optionValue ) #Casting to typeValue's type requestedType = typeValue if not type( typeValue ) == types.TypeType: requestedType = type( typeValue ) if requestedType == types.ListType: try: return S_OK( List.fromChar( optionValue, ',' ) ) except Exception: return S_ERROR( "Can't convert value (%s) to comma separated list" % str( optionValue ) ) elif requestedType == types.BooleanType: try: return S_OK( optionValue.lower() in ( "y", "yes", "true", "1" ) ) except Exception: return S_ERROR( "Can't convert value (%s) to Boolean" % str( optionValue ) ) else: try: return S_OK( requestedType( optionValue ) ) except: return S_ERROR( "Type mismatch between default (%s) and configured value (%s) " % ( str( typeValue ), optionValue ) )
def getOption( self, optionPath, typeValue = None ): gRefresher.refreshConfigurationIfNeeded() optionValue = gConfigurationData.extractOptionFromCFG( optionPath ) if optionValue == None: return S_ERROR( "Path %s does not exist or it's not an option" % optionPath ) # Value has been returned from the configuration if typeValue == None: return S_OK( optionValue ) # Casting to typeValue's type requestedType = typeValue if not type( typeValue ) == types.TypeType: requestedType = type( typeValue ) if requestedType == types.ListType: try: return S_OK( List.fromChar( optionValue, ',' ) ) except Exception: return S_ERROR( "Can't convert value (%s) to comma separated list" % str( optionValue ) ) elif requestedType == types.BooleanType: try: return S_OK( optionValue.lower() in ( "y", "yes", "true", "1" ) ) except Exception: return S_ERROR( "Can't convert value (%s) to Boolean" % str( optionValue ) ) else: try: return S_OK( requestedType( optionValue ) ) except: return S_ERROR( "Type mismatch between default (%s) and configured value (%s) " % ( str( typeValue ), optionValue ) )
def getOption(self, optionPath, typeValue=None): """ Get configuration option :param str optionPath: option path :param typeValue: type of value :return: S_OK()/S_ERROR() """ gRefresher.refreshConfigurationIfNeeded() optionValue = gConfigurationData.extractOptionFromCFG(optionPath) if optionValue is None: return S_ERROR("Path %s does not exist or it's not an option" % optionPath) # Value has been returned from the configuration if typeValue is None: return S_OK(optionValue) # Casting to typeValue's type if not isinstance(typeValue, type): # typeValue is not a type but a default object requestedType = type(typeValue) else: requestedType = typeValue if requestedType in (list, tuple, set): try: return S_OK(requestedType(List.fromChar(optionValue, ','))) except Exception as e: return S_ERROR( "Can't convert value (%s) to comma separated list \n%s" % (str(optionValue), repr(e))) elif requestedType == bool: try: return S_OK(optionValue.lower() in ("y", "yes", "true", "1")) except Exception as e: return S_ERROR("Can't convert value (%s) to Boolean \n%s" % (str(optionValue), repr(e))) elif requestedType == dict: try: splitOption = List.fromChar(optionValue, ',') value = {} for opt in splitOption: keyVal = [x.strip() for x in opt.split(':')] if len(keyVal) == 1: keyVal.append(True) value[keyVal[0]] = keyVal[1] return S_OK(value) except Exception as e: return S_ERROR("Can't convert value (%s) to Dict \n%s" % (str(optionValue), repr(e))) else: try: return S_OK(requestedType(optionValue)) except Exception as e: return S_ERROR( "Type mismatch between default (%s) and configured value (%s) \n%s" % (str(typeValue), optionValue, repr(e)))
def getSections(self, sectionPath, listOrdered=True): gRefresher.refreshConfigurationIfNeeded() sectionList = gConfigurationData.getSectionsFromCFG( sectionPath, ordered=listOrdered) if isinstance(sectionList, list): return S_OK(sectionList) else: return S_ERROR("Path %s does not exist or it's not a section" % sectionPath)
def getOptionsDict(self, sectionPath): gRefresher.refreshConfigurationIfNeeded() optionsDict = {} optionList = gConfigurationData.getOptionsFromCFG(sectionPath) if type(optionList) == types.ListType: for option in optionList: optionsDict[option] = gConfigurationData.extractOptionFromCFG("%s/%s" % (sectionPath, option)) return S_OK(optionsDict) else: return S_ERROR("Path %s does not exist or it's not a section" % sectionPath)
def getOptionsDict( self, sectionPath ): gRefresher.refreshConfigurationIfNeeded() optionsDict = {} optionList = gConfigurationData.getOptionsFromCFG( sectionPath ) if type( optionList ) == types.ListType: for option in optionList: optionsDict[ option ] = gConfigurationData.extractOptionFromCFG( "%s/%s" % ( sectionPath, option ) ) return S_OK( optionsDict ) else: return S_ERROR( "Path %s does not exist or it's not a section" % sectionPath )
def getOptions(self, sectionPath, listOrdered=True): """ Get configuration options :param str sectionPath: section path :param bool listOrdered: ordered :return: S_OK(list)/S_ERROR() """ gRefresher.refreshConfigurationIfNeeded() optionList = gConfigurationData.getOptionsFromCFG(sectionPath, ordered=listOrdered) if isinstance(optionList, list): return S_OK(optionList) else: return S_ERROR("Path %s does not exist or it's not a section" % sectionPath)
def getOptionsDict(self, sectionPath): """ Get configuration options in dictionary :param str sectionPath: section path :return: S_OK(dict)/S_ERROR() """ gRefresher.refreshConfigurationIfNeeded() optionsDict = {} optionList = gConfigurationData.getOptionsFromCFG(sectionPath) if isinstance(optionList, list): for option in optionList: optionsDict[option] = gConfigurationData.extractOptionFromCFG( "%s/%s" % (sectionPath, option)) return S_OK(optionsDict) else: return S_ERROR("Path %s does not exist or it's not a section" % sectionPath)