33 lines
1.5 KiB
Python
Executable File
33 lines
1.5 KiB
Python
Executable File
#!/usr/bin/env python
|
|
from main import app
|
|
from app.extensions import db
|
|
from app.models import *
|
|
from app.tools.data import save
|
|
from app.tools.logs import write
|
|
from sqlalchemy_utils import create_database, database_exists
|
|
from cryptography.fernet import Fernet
|
|
from os import mkdir, path
|
|
from pathlib import Path
|
|
|
|
data = Path(app.config.get('DATA'))
|
|
database_uri = app.config.get('SQLALCHEMY_DATABASE_URI')
|
|
|
|
with app.app_context():
|
|
if not path.isdir(f'./{data}'): mkdir(f'./{data}')
|
|
if not path.isdir(f'./{data}/questions'): mkdir(f'./{data}/questions')
|
|
if not path.isfile(f'./{data}/.gitignore'):
|
|
with open(f'./{data}/.gitignore', 'w') as file: file.write(f'*')
|
|
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('tests.log', 'Log file created.')
|
|
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)
|
|
if not database_exists(database_uri):
|
|
create_database(database_uri)
|
|
write('system.log', 'No database found. Creating a new database.')
|
|
db.create_all() |