def prettyCollection( outterValue, collectionType, quote, prettyFunction, tabCount, nullValue, trueValue, falseValue, withColors=False, joinAtReturn=False ) : openCollection = getCollectionCharacter(collectionType, c.OPEN_COLLECTION, withColors) closeCollection = getCollectionCharacter(collectionType, c.CLOSE_COLLECTION, withColors) strReturn = [] if len(outterValue) == 0 : strReturn += [openCollection, closeCollection] else : strReturn += [openCollection] tabCount += 1 if ObjectHelper.isDictionary(outterValue) : for key,value in outterValue.items() : strReturn += newLine(strReturn, openCollection, prettyFunction, withColors) strReturn += getStrReturn(key, value, collectionType, quote, prettyFunction, tabCount, nullValue, trueValue, falseValue, withColors) else : for value in outterValue : strReturn += newLine(strReturn, openCollection, prettyFunction, withColors) strReturn += getStrReturn(None, value, collectionType, quote, prettyFunction, tabCount, nullValue, trueValue, falseValue, withColors) strReturn += [c.NEW_LINE] tabCount -= 1 strReturn += [tabCount * c.TAB, closeCollection] return returnStr(strReturn, joinAtReturn)
def sample(collection, length=None): if ObjectHelper.isCollection(collection): if ObjectHelper.isDictionary(collection): if ObjectHelper.isNone(length): key = RandomHelperHelper.sampleCollection( list(collection.keys()), list) return {key: collection[key]} sampleDictionaryKeys = RandomHelperHelper.sampleCollection( list(collection.keys()), list, length=length) sampleDictionary = {} for key in sampleDictionaryKeys: sampleDictionary[key] = collection[key] return sampleDictionary elif ObjectHelper.isList(collection): return RandomHelperHelper.sampleCollection(collection, list, length=length) elif ObjectHelper.isSet(collection): return RandomHelperHelper.sampleCollection(collection, set, length=length) elif ObjectHelper.isTuple(collection): return RandomHelperHelper.sampleCollection(collection, tuple, length=length) raise Exception(f'The "{collection}" argument is not a collection')
def printNodeTree(tree, depth, settingKeyColor=c.NOTHING, settingValueColor=c.NOTHING, colonColor=c.NOTHING, resetColor=c.NOTHING): depthSpace = c.NOTHING for nodeDeep in range(depth): depthSpace += f'{c.TAB_UNITS * c.SPACE}' depth += 1 for node in list(tree): if ObjectHelper.isDictionary(tree[node]): print( f'{depthSpace}{settingKeyColor}{node}{colonColor}{c.SPACE}{c.COLON}' ) printNodeTree(tree[node], depth, settingKeyColor=settingKeyColor, settingValueColor=settingValueColor, colonColor=colonColor, resetColor=resetColor) else: print( f'{depthSpace}{settingKeyColor}{node}{colonColor}{c.SPACE}{c.COLON_SPACE}{settingValueColor}{tree[node]}{resetColor}' )
def keepSearching(keywordQuery, tree, querySet, history=None): if ObjectHelper.isDictionary(tree): for key in tree.keys(): if StringHelper.isNotBlank(history): newHistory = f'{history}.{key}' else: newHistory = f'{key}' if StringHelper.isNotBlank(keywordQuery) and key == keywordQuery: querySet[newHistory] = tree[key] keepSearching(keywordQuery, tree[key], querySet, history=newHistory)
def replaceEnvironmentVariables(environmentVariables): global ACTIVE_ENVIRONMENT_VALUE originalActiveEnvironment = None if ObjectHelper.isNone( ACTIVE_ENVIRONMENT_VALUE) else f'{c.NOTHING}{ACTIVE_ENVIRONMENT_VALUE}' if ObjectHelper.isNotEmpty(originalActiveEnvironment): ACTIVE_ENVIRONMENT_VALUE = None originalEnvironmentVariables = {} if ObjectHelper.isDictionary(environmentVariables): for key, value in environmentVariables.items(): originalEnvironmentVariables[key] = EnvironmentHelper.switch( key, value) getActiveEnvironment() LogHelper.loadSettings() return originalEnvironmentVariables, originalActiveEnvironment
def updateSettingTree(toUpdateSettingTree, gatheringSettingTree): if ObjectHelper.isNotEmpty(gatheringSettingTree): if ObjectHelper.isNone(toUpdateSettingTree) or StringHelper.isBlank( toUpdateSettingTree): toUpdateSettingTree = {} if ObjectHelper.isCollection( gatheringSettingTree) and ObjectHelper.isDictionary( gatheringSettingTree): for key, value in gatheringSettingTree.items(): if ObjectHelper.isNotEmpty(value) and ObjectHelper.isNotNone( value): if key not in toUpdateSettingTree or ObjectHelper.isEmpty( toUpdateSettingTree[key]): toUpdateSettingTree[key] = value else: updateSettingTree(toUpdateSettingTree[key], gatheringSettingTree[key]) elif key not in toUpdateSettingTree: toUpdateSettingTree[key] = value
def returnsValueIsPresent(returns) : isPresent = ObjectHelper.isDictionary(returns) if not isPresent : LogHelper.test(returnsValueIsPresent, f'the key "returns" from {ReflectionHelper.getMethodModuleNameDotName(Test)} annotation call was not defined') return isPresent