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