Debugging scripts import hell.

This commit is contained in:
lwark
2024-12-30 08:37:41 -06:00
parent 5fd36308b2
commit 0808b54264
22 changed files with 156 additions and 85 deletions

View File

@@ -1,6 +1,7 @@
import sys, os
from tools import ctx, setup_logger, check_if_app
from tools import ctx, setup_logger, check_if_app, timer
from threading import Thread
# environment variable must be set to enable qtwebengine in network path
if check_if_app():
os.environ['QTWEBENGINE_DISABLE_SANDBOX'] = "1"
@@ -8,46 +9,27 @@ if check_if_app():
# setup custom logger
logger = setup_logger(verbosity=3)
# from backend.scripts import modules
from backend import scripts
# from backend import scripts
from PyQt6.QtWidgets import QApplication
from frontend.widgets.app import App
@timer
def run_startup():
try:
startup_scripts = ctx.startup_scripts
except AttributeError as e:
logger.error(f"Couldn't get startup scripts due to {e}")
return
for script in startup_scripts:
try:
func = getattr(scripts, script)
except AttributeError as e:
logger.error(f"Couldn't run startup script {script} due to {e}")
continue
logger.info(f"Running startup script: {func.__name__}")
thread = Thread(target=func.script, args=(ctx, ))
for script in ctx.startup_scripts.values():
logger.info(f"Running startup script: {script.__name__}")
thread = Thread(target=script, args=(ctx,))
thread.start()
@timer
def run_teardown():
try:
teardown_scripts = ctx.teardown_scripts
except AttributeError as e:
logger.error(f"Couldn't get teardown scripts due to {e}")
return
for script in teardown_scripts:
try:
func = getattr(scripts, script)
# func = modules[script]
except AttributeError as e:
logger.error(f"Couldn't run teardown script {script} due to {e}")
continue
logger.info(f"Running teardown script: {func.__name__}")
thread = Thread(target=func.script, args=(ctx,))
for script in ctx.teardown_scripts.values():
logger.info(f"Running teardown script: {script.__name__}")
thread = Thread(target=script, args=(ctx,))
thread.start()
if __name__ == '__main__':
run_startup()
app = QApplication(['', '--no-sandbox'])