move infobases api

This commit is contained in:
Dmitry Belyaev 2021-10-07 13:57:39 +03:00
parent f5680564d2
commit 83d6388e35
Signed by: b4tman
GPG Key ID: 41A00BF15EA7E5F3
2 changed files with 40 additions and 34 deletions

39
app/api/infobases.py Normal file
View File

@ -0,0 +1,39 @@
from typing import List, Dict
from flask_restful import Resource
from app.glob import get_config, get_manager
from app.manager import infobase_data_blank
from brackets import get_infobases as br_get_infobases
def load_infobases(config) -> List[str]:
result = []
if 'infobases' in config and 'server_file' in config['infobases']:
result = br_get_infobases(config['infobases']['server_file'])
return result
class InfobasesAvailable(Resource):
def get(self) -> List[str]:
cfg = get_config()
bases = load_infobases(cfg)
return bases
class InfobasesAll(Resource):
def get(self) -> List[Dict[str, str]]:
cfg = get_config()
manager = get_manager()
infobase_names = load_infobases(cfg)
pubs = manager.publications()
result: List[Dict[str, str]] = []
for name in infobase_names:
publicated = False
for pub in filter(lambda x: x["name"] == name, pubs):
publicated = True
result.append(pub)
break
if not publicated:
result.append(infobase_data_blank(name))
return result

View File

@ -7,10 +7,9 @@ from flask_cors import CORS
from app.api.apache_restart import ApacheRestartFlag
from app.api.index import APIIndex
from app.api.infobases import InfobasesAvailable, InfobasesAll
from app.glob import get_config, get_manager
from app.manager import infobase_data_blank
from app.utils import validate_url
from brackets import get_infobases as br_get_infobases
pub_parser = reqparse.RequestParser()
pub_parser.add_argument('url', type=str)
@ -27,20 +26,6 @@ remove_parser = reqparse.RequestParser()
remove_parser.add_argument('force', type=bool, default=False)
def load_infobases(config) -> List[str]:
result = []
if 'infobases' in config and 'server_file' in config['infobases']:
result = br_get_infobases(config['infobases']['server_file'])
return result
class InfobasesAvailable(Resource):
def get(self) -> List[str]:
cfg = get_config()
bases = load_infobases(cfg)
return bases
class Config(Resource):
def get(self):
return get_config()
@ -52,24 +37,6 @@ class ConfigTest(Resource):
return manager.check()
class InfobasesAll(Resource):
def get(self) -> List[Dict[str, str]]:
cfg = get_config()
manager = get_manager()
infobase_names = load_infobases(cfg)
pubs = manager.publications()
result: List[Dict[str, str]] = []
for name in infobase_names:
publicated = False
for pub in filter(lambda x: x["name"] == name, pubs):
publicated = True
result.append(pub)
break
if not publicated:
result.append(infobase_data_blank(name))
return result
class Publications(Resource):
def get(self) -> List[Dict[str, str]]:
manager = get_manager()