コード例 #1
0
 def getSetting(self, nodeKey, settingTree=None):
     if not settingTree:
         settingTree = self.settingTree
     settingValue = SettingHelper.getSetting(nodeKey, settingTree)
     if ObjectHelper.isEmpty(settingValue):
         return SettingHelper.getSetting(nodeKey, self.defaultSettingTree)
     return settingValue
コード例 #2
0
def getResourceList(apiInstance, resourceType):
    resourceNameList = getResourceNameList(
        apiInstance.globals.apiTree[apiInstance.globals.apiPackage],
        resourceType)
    if isNotPythonFrameworkApiInstance(apiInstance):
        resourceNameList += getPythonFrameworkResourceByType(resourceType)
    resourceList = []
    for resourceName in resourceNameList:
        resource = None
        ajustedResourceName = getResourceNameAjusted(apiInstance, resourceType,
                                                     resourceName)
        ajustedResourceModuleName = getResourceModuleNameAjusted(
            apiInstance, resourceType, resourceName)
        if isControllerResourceName(resourceName):
            resource = getControllerList(ajustedResourceName,
                                         ajustedResourceModuleName)
        else:
            resource = globals.importResource(
                ajustedResourceName,
                resourceModuleName=ajustedResourceModuleName)
        if ObjectHelper.isEmpty(resource):
            raise Exception(
                f'Error while importing {ajustedResourceName} resource from {ajustedResourceModuleName} module. Resource not found.'
            )
        elif ObjectHelper.isList(resource):
            resourceList += resource
        else:
            resourceList.append(resource)
    return resourceList
コード例 #3
0
 def search(self, search):
     googleSearchResponseList = self.client.googleSearch.rawTextSearch(
         search, 1, 10)
     # log.prettyPython(self.search, f'google query: {search}, googleSearchResponseList', googleSearchResponseList, logLevel=log.SUCCESS)
     dtoList = []
     if ObjectHelper.isEmpty(googleSearchResponseList):
         title = 'Sorry'
         url = 'http://google.com.br'
         snippet = 'No relevante results were found'
         screenshotName = f'none.png'
         dtoList.append(
             GoogleSearchDto.GoogleSearchResponseDto(
                 title=title,
                 url=url,
                 snippet=snippet,
                 suggestedText=
                 f'''*Title:* {title}{c.NEW_LINE}*Link:* {url}{c.NEW_LINE}*Snipet:* {snippet}''',
                 screenshotName=screenshotName))
     else:
         for googleSearchResponse in googleSearchResponseList:
             title = googleSearchResponse.get('title')
             url = googleSearchResponse.get('link')
             snippet = googleSearchResponse.get('snippet')
             screenshotName = f'{str(time.time()).replace(c.DOT,c.BLANK)}.png'
             # self.takeScreenshot(screenshotName, url)
             dtoList.append(
                 GoogleSearchDto.GoogleSearchResponseDto(
                     title=title,
                     url=url,
                     snippet=snippet,
                     # suggestedText = f'''Title: {title.replace(c.NEW_LINE, c.SPACE)}{c.SPACE_DASH_SPACE *3}Link: {url}{c.SPACE_DASH_SPACE *3}Snipet: {snippet.replace(c.NEW_LINE, c.SPACE)}''',
                     suggestedText=
                     f'''*Title:* {title}{c.NEW_LINE}*Link:* {url}{c.NEW_LINE}*Snipet:* {snippet}''',
                     screenshotName=screenshotName))
     return dtoList
コード例 #4
0
 def getSettingTree(self,
                    settingFilePath=None,
                    defaultSettingFilePath=None,
                    settingTree=None):
     if ObjectHelper.isEmpty(settingTree):
         settingTree = {}
     fallbackSettingFilePath = defaultSettingFilePath if not settingFilePath == defaultSettingFilePath else None
     if ObjectHelper.isNone(settingFilePath) or StringHelper.isBlank(
             settingFilePath
     ) or not EnvironmentHelper.OS.path.isfile(settingFilePath):
         self.failure(
             f'The "{settingFilePath}" setting file path was not found',
             None)
         return self.getSettingTree(settingFilePath=fallbackSettingFilePath,
                                    settingTree=settingTree)
     try:
         settingTree = SettingHelper.getSettingTree(
             settingFilePath,
             fallbackSettingFilePath=fallbackSettingFilePath,
             fallbackSettingTree=settingTree,
             keepDepthInLongString=True)
     except Exception as exception:
         if ObjectHelper.isNone(fallbackSettingFilePath):
             self.error(
                 f'Failed to load setting tree from "{settingFilePath}" setting file path. Returning {settingTree} by default',
                 exception)
         else:
             self.failure(
                 f'Failed to load setting tree from "{settingFilePath}" setting file path and "{fallbackSettingFilePath}" default setting file path. Only setting file path will be loadded now',
                 exception)
             try:
                 settingTree = SettingHelper.getSettingTree(
                     settingFilePath, keepDepthInLongString=True)
             except Exception as exception:
                 self.failure(
                     f'Failed to load setting tree from "{settingFilePath}" setting file path as well. Returning {settingTree} by default',
                     exception)
     return settingTree
 def getResult(self, resultList):
     return None if ObjectHelper.isEmpty(resultList) or (
         isinstance(resultList, bs4.element.ResultSet)
         and 0 == len(resultList)) else resultList[0]
コード例 #6
0
 def __init__(self, *args, **kwargs):
     originalClassAttributeValueList = ReflectionHelper.getAttributeNameList(
         OuterEnum)
     if instanceLog:
         log.prettyPython(OuterEnum,
                          'originalClassAttributeValueList',
                          originalClassAttributeValueList)
     OuterEnum.__init__(self, *args, **kwargs)
     self.__associateReturnsTo__ = associateReturnsTo
     attributeDataList = ReflectionHelper.getAttributeDataList(self)
     if instanceLog:
         log.prettyPython(OuterEnum, 'attributeDataList',
                          attributeDataList)
     for attribute, enumValue in attributeDataList:
         if enumValue not in ENUM_STATIC_METHOD_NAME_LIST and enumValue not in originalClassAttributeValueList:
             __raiseBadImplementation__(enumValue, enum=self)
         nativeClassDataList = []
         attributeAttributeDataList = ReflectionHelper.getAttributeDataList(
             attribute)
         if instanceLog:
             log.prettyPython(OuterEnum,
                              'attributeAttributeDataList',
                              attributeAttributeDataList)
             # print(f'type({attribute}): {type(attribute)}')
         association = ReflectionHelper.getAttributeOrMethod(
             attribute, self.__associateReturnsTo__, muteLogs=True)
         if type(association) is type(None):
             # print('type(association) is type(None)')
             ReflectionHelper.setAttributeOrMethod(
                 attribute, ENUM_VALUE_AS_STRING_KEY,
                 ENUM_ITEM_CLASS_DICTIONARY.get(
                     type(enumValue))(enumValue))
             nativeClassDataList = ReflectionHelper.getAttributeDataList(
                 type(enumValue)())
             # print(f'type({enumValue}): {type(enumValue)}, type({type(enumValue)}()): {type(type(enumValue)())}')
         else:
             # print('not type(association) is type(None)')
             ReflectionHelper.setAttributeOrMethod(
                 attribute, ENUM_VALUE_AS_STRING_KEY,
                 ENUM_ITEM_CLASS_DICTIONARY.get(
                     type(association))(association))
             nativeClassDataList = ReflectionHelper.getAttributeDataList(
                 type(association)())
             # print(f'type({association}): {type(association)}, type({type(association)}()): {type(type(association)())}')
         # print()
         attribute.enumValue.enumName = enumValue
         ReflectionHelper.setAttributeOrMethod(
             attribute, ENUM_NAME_AS_STRING_KEY, enumValue)
         if isinstance(attribute, EnumItem):
             # print(attribute, attribute.enumName, attribute)
             updateEnumItem(
                 attribute, attribute.enumName,
                 attribute)  ###- so that __eq__ does not crash
         if not c.TYPE_FUNCTION == ReflectionHelper.getClassName(
                 attribute):
             attribute.enumValue.__enumItemMap__ = attribute.__enumItemMap__
             attribute.enumValue.__enumItemEqMap__ = attribute.__enumItemEqMap__
         for dataInstance, dataName in attributeAttributeDataList:
             nativeData = False
             for _, name in nativeClassDataList:
                 if dataName == name:
                     nativeData = True
                     break
             if not nativeData:
                 ReflectionHelper.setAttributeOrMethod(
                     attribute.enumValue, dataName, dataInstance)
         ReflectionHelper.setAttributeOrMethod(
             attribute.enumValue, ENUM_VALUE_AS_STRING_KEY,
             ReflectionHelper.getAttributeOrMethod(
                 attribute,
                 self.__associateReturnsTo__,
                 muteLogs=True))
         ReflectionHelper.setAttributeOrMethod(
             attribute.enumValue, ENUM_NAME_AS_STRING_KEY,
             enumValue)
         ReflectionHelper.setAttributeOrMethod(
             attribute.enumValue, ENUM_AS_STRING_KEY, self)
     if ObjectHelper.isEmpty(OuterEnum.__enumEqList__):
         for attribute, value in attributeDataList:
             # print(f'type({value}): {type(value)}')
             # print(f'type({attribute}): {type(attribute)}')
             valueAsString = str(attribute.enumValue)
             if valueAsString not in ENUM_STATIC_METHOD_NAME_LIST:
                 if valueAsString not in self.__enumMap__:
                     self.__enumMap__[
                         valueAsString] = attribute.enumValue  ###- ReflectionHelper.getAttributeOrMethod(attribute, valueAsString, muteLogs=True) ###- attribute
                 else:
                     __raiseBadImplementation__(valueAsString,
                                                enum=self)
                 if value not in self.__enumMap__:
                     self.__enumMap__[value] = attribute
                 elif not self.__enumMap__[value] == attribute:
                     __raiseBadImplementation__(valueAsString,
                                                enum=self)
                 self.__enumEqList__.append(
                     f'{value}({self.__associateReturnsTo__}:{valueAsString})'
                 )