2023-02-26 18:48:07 +00:00
|
|
|
import functools
|
2021-10-13 08:12:44 +00:00
|
|
|
import sys
|
2021-10-13 07:38:44 +00:00
|
|
|
|
2021-12-20 22:57:27 +00:00
|
|
|
import click
|
2023-04-10 09:44:30 +00:00
|
|
|
from canaille.backends import Backend
|
2021-10-13 07:38:44 +00:00
|
|
|
from flask import current_app
|
2021-12-20 22:57:27 +00:00
|
|
|
from flask.cli import with_appcontext
|
2021-04-04 16:25:37 +00:00
|
|
|
|
2023-02-26 18:48:07 +00:00
|
|
|
|
|
|
|
def with_backendcontext(func):
|
|
|
|
@functools.wraps(func)
|
|
|
|
def _func(*args, **kwargs):
|
|
|
|
if not current_app.config["TESTING"]: # pragma: no cover
|
2023-04-10 09:44:30 +00:00
|
|
|
with Backend.get().session():
|
|
|
|
result = func(*args, **kwargs)
|
2023-02-26 18:48:07 +00:00
|
|
|
|
2023-04-08 18:42:38 +00:00
|
|
|
else:
|
|
|
|
result = func(*args, **kwargs)
|
2023-02-26 18:48:07 +00:00
|
|
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
return _func
|
|
|
|
|
2021-04-04 16:25:37 +00:00
|
|
|
|
2023-04-09 14:14:38 +00:00
|
|
|
@click.command()
|
2021-10-13 08:12:44 +00:00
|
|
|
@with_appcontext
|
|
|
|
def check():
|
|
|
|
"""
|
|
|
|
Check the configuration file.
|
|
|
|
"""
|
2023-04-09 14:14:38 +00:00
|
|
|
from canaille.app.configuration import ConfigurationException
|
|
|
|
from canaille.app.configuration import validate
|
2021-10-29 12:20:06 +00:00
|
|
|
|
2021-10-13 08:12:44 +00:00
|
|
|
try:
|
|
|
|
validate(current_app.config, validate_remote=True)
|
|
|
|
except ConfigurationException as exc:
|
|
|
|
print(exc)
|
|
|
|
sys.exit(1)
|
2021-11-08 17:09:05 +00:00
|
|
|
|
|
|
|
|
2023-04-09 14:14:38 +00:00
|
|
|
@click.command()
|
2021-11-08 17:09:05 +00:00
|
|
|
@with_appcontext
|
|
|
|
def install():
|
|
|
|
"""
|
2021-11-08 17:30:31 +00:00
|
|
|
Installs canaille elements from the configuration.
|
2021-11-08 17:09:05 +00:00
|
|
|
"""
|
2023-04-09 13:52:55 +00:00
|
|
|
from canaille.app.installation import install
|
|
|
|
from canaille.app.configuration import ConfigurationException
|
2021-11-08 17:09:05 +00:00
|
|
|
|
|
|
|
try:
|
|
|
|
install(current_app.config)
|
|
|
|
|
2022-12-10 00:11:33 +00:00
|
|
|
except ConfigurationException as exc: # pragma: no cover
|
2021-11-08 17:09:05 +00:00
|
|
|
print(exc)
|
|
|
|
sys.exit(1)
|
2023-02-26 18:48:07 +00:00
|
|
|
|
|
|
|
|
2023-04-09 14:14:38 +00:00
|
|
|
def register(cli):
|
|
|
|
cli.add_command(check)
|
|
|
|
cli.add_command(install)
|