rename PublicationManager

This commit is contained in:
Dmitry Belyaev 2021-09-24 16:14:59 +03:00
parent f715fb11dc
commit d89715b8fd
Signed by: b4tman
GPG Key ID: 41A00BF15EA7E5F3

View File

@ -41,11 +41,11 @@ def publication_data(publication: WebPublication):
}
class WebPub1C:
class PublicationManager:
def __init__(self, config, verbose: bool = False):
level = logging.INFO if verbose else logging.WARNING
logging.basicConfig(level=level)
self._log = logging.getLogger("webpub1c")
self._log = logging.getLogger("manager")
self._log.setLevel(level)
self._config = config
@ -175,11 +175,11 @@ def get_config():
return g.config
def get_webpub1c():
if 'webpub1c' not in g:
g.webpub1c = WebPub1C(get_config())
def get_manager():
if 'manager' not in g:
g.manager = PublicationManager(get_config())
return g.webpub1c
return g.manager
def load_infobases(config) -> List[str]:
@ -209,16 +209,16 @@ class Config(Resource):
class ConfigTest(Resource):
def get(self):
webpub = get_webpub1c()
return webpub.check()
manager = get_manager()
return manager.check()
class InfobasesAll(Resource):
def get(self) -> List[Dict[str, str]]:
cfg = get_config()
webpub = get_webpub1c()
manager = get_manager()
infobase_names = load_infobases(cfg)
pubs = webpub.publications()
pubs = manager.publications()
result: List[Dict[str, str]] = []
for name in infobase_names:
publicated = False
@ -233,18 +233,18 @@ class InfobasesAll(Resource):
class Publications(Resource):
def get(self) -> List[Dict[str, str]]:
webpub = get_webpub1c()
return webpub.publications()
manager = get_manager()
return manager.publications()
def put(self):
args = pub_parser_with_name.parse_args()
validate_url(args.url)
webpub = get_webpub1c()
manager = get_manager()
url = args.url
if not args.force and args.name in webpub.list():
if not args.force and args.name in manager.list():
abort(409, message=f'publication exists: {args.name}')
try:
url = webpub.add(args.name, url, args.file, args.force)
url = manager.add(args.name, url, args.file, args.force)
except Exception as e:
abort(422, message=f'publication failed: {args.name}', traceback=traceback.format_exc())
return {'message': 'created', 'name': args.name, 'url': url}, 201
@ -252,33 +252,33 @@ class Publications(Resource):
class Publication(Resource):
def get(self, name: str):
webpub = get_webpub1c()
if name not in webpub.list():
manager = get_manager()
if name not in manager.list():
abort(404, message=f'publication not found: {name}')
return {
name: webpub.get(name)
name: manager.get(name)
}
def put(self, name: str):
args = pub_parser.parse_args()
validate_url(args.url)
webpub = get_webpub1c()
manager = get_manager()
url = args.url
if not args.force and name in webpub.list():
if not args.force and name in manager.list():
abort(409, message=f'publication exists: {name}')
try:
url = webpub.add(name, url, args.file, args.force)
url = manager.add(name, url, args.file, args.force)
except Exception as e:
abort(422, message=f'publication failed: {name}', traceback=traceback.format_exc())
return {'message': 'created', 'name': name, 'url': url}, 201
def delete(self, name: str):
args = remove_parser.parse_args()
webpub = get_webpub1c()
if name not in webpub.list():
manager = get_manager()
if name not in manager.list():
abort(404, message=f'publication not found: {name}')
try:
webpub.remove(name, args.force)
manager.remove(name, args.force)
except Exception as e:
abort(422, message='delete failed', traceback=traceback.format_exc())
return {'message': 'deleted', 'name': name}
@ -286,22 +286,22 @@ class Publication(Resource):
class PublicationURL(Resource):
def get(self, name: str):
webpub = get_webpub1c()
if name not in webpub.list():
manager = get_manager()
if name not in manager.list():
abort(404, message=f'publication not found: {name}')
return {
'url': webpub.get(name)['url']
'url': manager.get(name)['url']
}
def post(self, name: str):
args = url_req_parser.parse_args()
validate_url(args.url)
webpub = get_webpub1c()
manager = get_manager()
url = args.url
if name not in webpub.list():
if name not in manager.list():
abort(404, message=f'publication not found: {name}')
try:
webpub.set_url(name, url)
manager.set_url(name, url)
except Exception as e:
abort(422, message=f'set url failed', traceback=traceback.format_exc())
return {'message': 'success', 'name': name, 'url': url}
@ -309,18 +309,18 @@ class PublicationURL(Resource):
class EnterpriseModule(Resource):
def get(self):
webpub = get_webpub1c()
if not webpub.has_module():
manager = get_manager()
if not manager.has_module():
abort(404, message='not found')
return {
'message': 'found'
}
def put(self):
webpub = get_webpub1c()
if webpub.has_module():
manager = get_manager()
if manager.has_module():
return '', 304
webpub.add_module()
manager.add_module()
return {
'message': 'success'
}
@ -378,7 +378,7 @@ def index():
with app.app_context():
get_config()
get_webpub1c()
get_manager()
index_content = render_template("index.html")