1
0
Fork 0
mirror of https://codeberg.org/Mo8it/AdvLabDB.git synced 2024-11-06 21:17:43 +00:00
AdvLabDB/manage.py

90 lines
1.9 KiB
Python
Raw Normal View History

2022-09-07 22:12:55 +00:00
#!/usr/bin/env python3
2022-08-08 20:51:41 +00:00
import subprocess # nosec 404
import click
2022-08-15 20:37:03 +00:00
from cli.maintain.reset_admin_password.main import _reset_admin_password
from cli.setup.generate_secrets.main import _generate_secrets
from cli.setup.init_db.main import _init_db
from cli.test.generate_test_db.main import _generate_test_db
2022-08-08 20:51:41 +00:00
2022-08-14 00:54:22 +00:00
class Manage:
@staticmethod
def run(command: str, **kwargs):
2023-11-02 19:04:09 +00:00
return subprocess.run(command, shell=True, check=False, **kwargs) # nosec B602
2022-08-09 23:15:29 +00:00
2022-08-14 00:54:22 +00:00
@staticmethod
def box(message: str):
click.echo()
click.echo(click.style(f" {message} ", bg="white", fg="black"))
click.echo()
2022-08-08 20:51:41 +00:00
@click.group(
help="Command line tool to manage AdvLabDB.",
)
def cli():
pass
@cli.group(
short_help="Setup commands.",
help="Commands used to setup an AdvLabDB instance.",
)
def setup():
pass
@setup.command(
short_help="Generate required secrets.",
help="Generate the file secrets.ini if it does not already exist.",
)
def generate_secrets():
2022-08-14 00:54:22 +00:00
_generate_secrets()
2022-08-08 20:51:41 +00:00
@setup.command(
short_help="Initialize the database.",
help="Initialize the database if it does not already exist.",
)
2022-08-09 12:46:48 +00:00
def init_db():
2022-08-14 00:54:22 +00:00
_init_db(Manage)
2022-08-08 20:51:41 +00:00
@cli.group(
2022-08-09 13:50:59 +00:00
short_help="Maintenance commands.",
2022-08-08 20:51:41 +00:00
help="Commands used to maintain an AdvLabDB instance.",
)
def maintain():
pass
@maintain.command(
short_help="Reset the password of an admin.",
help="Reset the password of a chosen active admin. A random password will be generated. If no admins are active, a chosen admin will be activated.",
)
def reset_admin_password():
2022-08-14 00:54:22 +00:00
_reset_admin_password(Manage)
2022-08-08 20:51:41 +00:00
2022-08-09 23:15:29 +00:00
@cli.group(
short_help="Test commands.",
help="Commands used to test AdvLabDB.",
)
def test():
pass
@test.command(
short_help="Generate test database.",
help="Generate a test database if no database already exists.",
)
def generate_test_db():
2022-08-14 00:54:22 +00:00
_generate_test_db()
2022-08-09 23:15:29 +00:00
2022-08-08 20:51:41 +00:00
if __name__ == "__main__":
cli()