move infobases api
This commit is contained in:
parent
f5680564d2
commit
83d6388e35
39
app/api/infobases.py
Normal file
39
app/api/infobases.py
Normal 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
|
@ -7,10 +7,9 @@ from flask_cors import CORS
|
|||||||
|
|
||||||
from app.api.apache_restart import ApacheRestartFlag
|
from app.api.apache_restart import ApacheRestartFlag
|
||||||
from app.api.index import APIIndex
|
from app.api.index import APIIndex
|
||||||
|
from app.api.infobases import InfobasesAvailable, InfobasesAll
|
||||||
from app.glob import get_config, get_manager
|
from app.glob import get_config, get_manager
|
||||||
from app.manager import infobase_data_blank
|
|
||||||
from app.utils import validate_url
|
from app.utils import validate_url
|
||||||
from brackets import get_infobases as br_get_infobases
|
|
||||||
|
|
||||||
pub_parser = reqparse.RequestParser()
|
pub_parser = reqparse.RequestParser()
|
||||||
pub_parser.add_argument('url', type=str)
|
pub_parser.add_argument('url', type=str)
|
||||||
@ -27,20 +26,6 @@ remove_parser = reqparse.RequestParser()
|
|||||||
remove_parser.add_argument('force', type=bool, default=False)
|
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):
|
class Config(Resource):
|
||||||
def get(self):
|
def get(self):
|
||||||
return get_config()
|
return get_config()
|
||||||
@ -52,24 +37,6 @@ class ConfigTest(Resource):
|
|||||||
return manager.check()
|
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):
|
class Publications(Resource):
|
||||||
def get(self) -> List[Dict[str, str]]:
|
def get(self) -> List[Dict[str, str]]:
|
||||||
manager = get_manager()
|
manager = get_manager()
|
||||||
|
Loading…
Reference in New Issue
Block a user