コード例 #1
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
コード例 #2
0
def newApp(filePath,
           successStatus=True,
           errorStatus=True,
           failureStatus=True,
           warningStatus=True,
           settingStatus=True,
           statusStatus=True,
           infoStatus=True,
           debugStatus=False,
           wrapperStatus=False,
           testStatus=False,
           logStatus=False):
    globalsInstance = globals.newGlobalsInstance(filePath,
                                                 successStatus=successStatus,
                                                 errorStatus=errorStatus,
                                                 failureStatus=failureStatus,
                                                 settingStatus=settingStatus,
                                                 statusStatus=statusStatus,
                                                 infoStatus=infoStatus,
                                                 debugStatus=debugStatus,
                                                 warningStatus=warningStatus,
                                                 wrapperStatus=wrapperStatus,
                                                 testStatus=testStatus,
                                                 logStatus=logStatus)
    try:
        app = globals.importResource(
            KW_APP,
            resourceModuleName=ConverterStatic.getValueOrDefault(
                globalsInstance.apiName,
                StringHelper.join(EnvironmentHelper.listDirectoryContent(
                    f'{globalsInstance.BASE_API_PATH}')[0].split(c.DOT)[:-1],
                                  character=c.DOT)),
            required=True)
    except Exception as exception:
        apiPath = f'{c.DOT}{EnvironmentHelper.OS_SEPARATOR}{globalsInstance.BASE_API_PATH}{globalsInstance.apiName}.py'
        errorMessage = f"Not possible to load app. Make shure it's name is properlly configured at '{globalsInstance.settingFilePath}' and it's instance is named 'app' at '{apiPath}'"
        log.error(newApp, errorMessage, exception)
        raise exception
    if ObjectHelper.isNone(app):
        app = globals.importResource(
            KW_APP, resourceModuleName=globalsInstance.apiName)
        raise Exception(
            'Not possible to load app. Check logs for more details')
    return app
コード例 #3
0
def getControllerList(resourceName, resourceModuleName) :
    controllerNameList = getControllerNameList(resourceName)
    importedControllerList = []
    for controllerName in controllerNameList :
        resource = globals.importResource(controllerName, resourceModuleName=resourceModuleName)
        if ObjectHelper.isNotNone(resource) :
            importedControllerList.append(resource)
    if 0 == len(importedControllerList) :
        raise Exception(f'Not possible to import {resourceName} controller')
    return importedControllerList
コード例 #4
0
def resolveValue(value, key, classRole, fatherClass=None) :
    if ObjectHelper.isNativeClassInstance(value) :
        return value
    if ObjectHelper.isList(value) :
        if LIST_SUFIX == key[-4:] :
            resourceName = getResourceName(key, classRole)
            resourceModuleName = getResourceModuleName(key, classRole)
            keyClass = globals.importResource(resourceName, resourceModuleName=resourceModuleName)
            convertedValue = []
            for jsonItem in value :
                if jsonItem :
                    convertedItem = convertFromJsonToObject(jsonItem, keyClass, fatherClass=fatherClass)
                    convertedValue.append(convertedItem)
            return convertedValue
    resourceName = getResourceName(key, classRole)
    resourceModuleName = getResourceModuleName(key, classRole)
    keyClass = globals.importResource(resourceName, resourceModuleName=resourceModuleName)
    if ObjectHelper.isNone(keyClass) :
        return value
    else :
        return convertFromJsonToObject(value, keyClass, fatherClass=fatherClass)
コード例 #5
0
def getTargetClassFromFatherClassAndChildMethodName(fatherClass, childAttributeName):
    classRole = getClassRole(fatherClass)
    dtoClassName = getResourceName(childAttributeName, classRole)
    dtoModuleName  = getResourceModuleName(childAttributeName, classRole)
    # print(f'classRole: {classRole}, dtoClassName: {dtoClassName}, dtoModuleName: {dtoModuleName}')
    return globals.importResource(dtoClassName, resourceModuleName=dtoModuleName)