예제 #1
0
def init_resources() -> None:
    """Initialize resources table """

    level1, level2, level3, level4 = [], [], [], []
    services_path = get_services_path().values()
    for service_path in services_path:
        resource_path = os.path.join(service_path, 'resources.yml')
        if not os.path.isfile(resource_path):
            continue
        else:
            with open(resource_path, 'r', encoding='utf-8') as load_file:
                resource_data = yaml.load(load_file, Loader=FullLoader)
            if not resource_data:
                continue
            for _, value in resource_data.items():
                if value.get('level') == 1:
                    level1.append(value)
                elif value.get('level') == 2:
                    level2.append(value)
                elif value.get('level') == 3:
                    level3.append(value)
                else:
                    level4.append(value)

    all_levels_resources = [level1, level2, level3, level4]
    for level_resources in all_levels_resources:
        _insert_resources(level_resources=level_resources)
    info = "resources successfully!"
    print(info)
예제 #2
0
def register_blueprints():
    active_services = get_services_path()
    for key, value in active_services.items():
        service_path = '.'.join(value.partition('app')[-1].split('/'))
        service_views_path = f'app{service_path}.views'
        views_module = import_module(service_views_path)
        if hasattr(views_module, 'bp'):
            app.register_blueprint(views_module.bp, url_prefix='/api/v1')
예제 #3
0
def register_blueprints2():
    active_services = get_services_path()
    for key, value in active_services.items():
        schemas_path = os.path.join(value, 'views\\' + key + '.py')
        if not os.path.exists(schemas_path):
            continue
        views_module = path_import(schemas_path)
        if hasattr(views_module, 'bp'):
            app.register_blueprint(views_module.bp, url_prefix='/api/v1')
예제 #4
0
def import_schemas():
    active_services = get_services_path()
    for key, value in active_services.items():
        schemas_path = os.path.join(value, 'schemas.py')
        if not os.path.exists(schemas_path):
            continue
        schemas_module = path_import(schemas_path)
        service_schemas = schemas_module.__all__ if hasattr(
            schemas_module, '__all__') else []
        for name, attr in schemas_module.__dict__.items():
            if name in service_schemas:
                setattr(sys.modules[__name__], name, attr)
예제 #5
0
파일: schemas.py 프로젝트: imfht/flaskapp1
def import_schemas():
    active_services = get_services_path()
    for key, value in active_services.items():
        schemas_path = os.path.join(value, 'schemas.py')
        if not os.path.exists(schemas_path):
            continue
        service_path = '.'.join(value.partition('app')[-1].split('/'))
        service_schemas_path = 'app{0}.schemas'.format(service_path)
        schemas_module = import_module(service_schemas_path)
        service_schemas = schemas_module.__all__ if hasattr(
            schemas_module, '__all__') else []
        for name, attr in schemas_module.__dict__.items():
            if name in service_schemas:
                setattr(sys.modules[__name__], name, attr)
예제 #6
0
def import_models():
    active_services = get_services_path()