2022-06-11 11:29:15 +01:00
|
|
|
from main import app
|
|
|
|
from . import Config
|
|
|
|
from .data import data
|
|
|
|
from .modules import db
|
|
|
|
from .tools.data import save
|
|
|
|
from .tools.logs import write
|
|
|
|
|
|
|
|
from os import mkdir, path, system
|
|
|
|
from cryptography.fernet import Fernet
|
|
|
|
|
|
|
|
from sqlalchemy_utils import database_exists, create_database
|
|
|
|
|
|
|
|
def install_scripts():
|
|
|
|
if not path.isdir(f'./{data}'): mkdir(f'./{data}')
|
|
|
|
if not path.isfile(f'./{data}/config.json'): save({}, 'config.json')
|
|
|
|
if not path.isdir(f'./{data}/logs'): mkdir(f'./{data}/logs')
|
|
|
|
if not path.isfile(f'./{data}/logs/users.log'): write('users.log', 'Log file created.')
|
|
|
|
if not path.isfile(f'./{data}/logs/system.log'): write('system.log', 'Log file created.')
|
|
|
|
if not path.isfile(f'./{data}/logs/tests.log'): write('commands.log', 'Log file created.')
|
|
|
|
if not database_exists(Config.SQLALCHEMY_DATABASE_URI):
|
|
|
|
create_database(Config.SQLALCHEMY_DATABASE_URI)
|
|
|
|
write('system.log', 'No database found. Creating a new database.')
|
|
|
|
with app.app_context(): db.create_all()
|
|
|
|
write('system.log', 'Creating database schema.')
|
|
|
|
if not path.isfile(f'./{data}/.encryption.key'):
|
|
|
|
write('system.log', 'No encryption key found. Generating new encryption key.')
|
|
|
|
with open(f'./{data}/.encryption.key', 'wb') as key_file:
|
|
|
|
key = Fernet.generate_key()
|
|
|
|
key_file.write(key)
|