2022-08-08 20:51:41 +00:00
#!/usr/bin/python3
import subprocess # nosec 404
import click
2022-08-15 20:37:03 +00:00
from cli . maintain . copy_admin_templates . main import _copy_admin_templates
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 ) :
return subprocess . run ( command , shell = True , * * 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
@maintain.command (
short_help = " Copy admin templates " ,
help = " Copy the templates from the Flask-Admin package. This is only needed if the templates should be updated to a new version after a new release of Flask-Admin. " ,
)
def copy_admin_templates ( ) :
2022-08-14 00:54:22 +00:00
_copy_admin_templates ( )
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 ( )