def getValue(value):
    filteredValue = StringHelper.filterString(value)
    if isSettingValue(filteredValue):
        if StringHelper.isNotBlank(filteredValue):
            if c.OPEN_LIST == filteredValue[0]:
                return getList(filteredValue)
            elif c.OPEN_TUPLE == filteredValue[0]:
                return getTuple(filteredValue)
            elif c.OPEN_DICTIONARY == filteredValue[0]:
                return getDictionary(filteredValue)
            elif c.OPEN_SET == filteredValue[0]:
                return getSet(filteredValue)
        parsedValue = None
        try:
            parsedValue = int(filteredValue)
        except:
            try:
                parsedValue = float(filteredValue)
            except:
                try:
                    parsedValue = filteredValue
                    if not filteredValue is None:
                        if filteredValue == c.TRUE:
                            parsedValue = True
                        elif filteredValue == c.FALSE:
                            parsedValue = False
                except:
                    parsedValue = filteredValue
        return parsedValue
    return filteredValue
def lineAproved(settingLine):
    approved = True
    if c.NEW_LINE == settingLine:
        approved = False
    if c.HASH_TAG in settingLine:
        filteredSettingLine = StringHelper.filterString(settingLine)
        if filteredSettingLine is None or c.NOTHING == filteredSettingLine or c.NEW_LINE == filteredSettingLine:
            approved = False
    return approved
Example #3
0
def update(environmentKey, environmentValue, default=None) :
    if ObjectHelper.isNotEmpty(environmentKey) :
        associatedValue = None
        if not environmentValue is None :
            associatedValue = str(StringHelper.filterString(environmentValue))
            OS.environ[environmentKey] = associatedValue
        elif not default is None :
            associatedValue = str(StringHelper.filterString(default))
            OS.environ[environmentKey] = associatedValue
        else :
            try:
                delete(environmentKey)
            except Exception as exception :
                LogHelper.warning(update, f'Failed to delete "{environmentKey}" enviroment variable key', exception=exception)
        return associatedValue
    else :
        LogHelper.debug(update, f'arguments: environmentKey: {environmentKey}, environmentValue: {environmentValue}, default: {default}')
        raise Exception(f'Error associating environment variable "{environmentKey}" key to environment variable "{environmentValue}" value')
def getSetting(nodeKey, settingTree):
    setting = None
    try:
        setting = SettingHelperHelper.accessTree(nodeKey, settingTree)
    except Exception as exception:
        LogHelper.failure(
            getSetting,
            f'Not possible to get {nodeKey} node key. Returning "{setting}" by default',
            exception)
    return StringHelper.filterString(setting) if isinstance(setting,
                                                            str) else setting
def getFilteredSetting(settingKey, settingValue, nodeKey, settingTree):
    # print(f'getFilteredSetting: settingValue: "{settingValue}"')
    if StringHelper.isNotBlank(settingValue):
        settingEvaluationList = settingValue.split(c.COLON)
        if len(settingEvaluationList) > 1:
            defaultSettingValue = c.COLON.join(
                settingValue.split(c.COLON)[1:]).strip()
            # print(f'    defaultSettingValue: {defaultSettingValue}')
        else:
            defaultSettingValue = c.NONE
        if isSettingInjection(defaultSettingValue):
            return getSettingInjectionValue(settingKey, defaultSettingValue,
                                            nodeKey, settingTree)
        return StringHelper.filterString(defaultSettingValue)
    # print(f'    settingValue: {settingValue}')
    return settingValue
def getDictionary(value):
    splitedValue = value[1:-1].split(c.COLON)
    keyList = []
    for index in range(len(splitedValue) - 1):
        keyList.append(
            StringHelper.filterString(splitedValue[index].split(
                c.COMA)[-1].strip()))
    valueList = []
    valueListSize = len(splitedValue) - 1
    for index in range(valueListSize):
        if index == valueListSize - 1:
            correctValue = splitedValue[index + 1].strip()
        else:
            correctValue = c.COMA.join(splitedValue[index + 1].split(
                c.COMA)[:-1]).strip()
        valueList.append(getValue(correctValue))
    resultantDictionary = dict()
    for index in range(len(keyList)):
        resultantDictionary[keyList[index]] = valueList[index]
    return resultantDictionary
def accessTree(nodeKey, tree):
    if ObjectHelper.isNotNone(tree):
        strippedNodeKey = nodeKey.strip()
        if ObjectHelper.isEmpty(nodeKey):
            returnTree = None
            try:
                returnTree = StringHelper.filterString(tree)
            except Exception as exception:
                LogHelper.failure(
                    accessTree,
                    f'Failed to get filtered string from {tree} tree. Returning it the way it is by default',
                    exception)
                returnTree = tree
            return returnTree
        elif isinstance(nodeKey, str):
            nodeKeyList = nodeKey.split(c.DOT)
            if len(nodeKeyList) == 1:
                nextNodeKey = c.NOTHING
            else:
                nextNodeKey = c.DOT.join(nodeKeyList[1:])
            return accessTree(nextNodeKey, tree.get(nodeKeyList[0]))
def getStrReturn(
        key,
        value,
        collectionType,
        quote,
        prettyFunction,
        tabCount,
        nullValue,
        trueValue,
        falseValue,
        withColors
    ) :
    valueValue = prettyFunction(
        value,
        quote = quote,
        tabCount = tabCount,
        nullValue = nullValue,
        trueValue = trueValue,
        falseValue = falseValue,
        withColors = withColors,
        joinAtReturn = False
    )
    if c.TYPE_DICT == collectionType :
        filteredAndColoredQuote = getFilteredAndColoredQuote(key, quote, prettyFunction, withColors, c.QUOTE_PROMPT_COLOR)
        filteredAndColoredColonSpace = getItAsColoredString(c.COLON_SPACE, prettyFunction, withColors, color=c.COLON_PROMPT_COLOR)
        return [tabCount * c.TAB, *filteredAndColoredQuote, *getItAsColoredString(key if StringHelper.prettyPython==prettyFunction else StringHelper.filterString(prettyFunction(key, quote=quote, tabCount=tabCount, nullValue=nullValue, trueValue=trueValue, falseValue=falseValue)), prettyFunction, withColors), *filteredAndColoredQuote, *filteredAndColoredColonSpace, *valueValue]
    else :
        return [tabCount * c.TAB, *valueValue]
def getAttibuteValue(settingLine):
    possibleValue = StringHelper.filterString(settingLine)
    return getValue(c.COLON.join(possibleValue.split(c.COLON)[1:]))
def getAttributeKey(settingLine):
    possibleKey = StringHelper.filterString(settingLine)
    return possibleKey.split(c.COLON)[0].strip()