Skip to content
Snippets Groups Projects
Commit 66b67e2e authored by David Trattnig's avatar David Trattnig
Browse files

Recreate DB to model space. #41

parent 9ea7208e
No related branches found
No related tags found
No related merge requests found
......@@ -78,12 +78,12 @@ class EngineRunner:
"""
Starts Engine Core.
"""
from src.scheduling.scheduler import AuraScheduler
from src.scheduling.models import AuraDatabaseModel
from src.core.engine import Engine
# Check if the database has to be re-created
# Check if the database has to be re-) created
if self.config.get("recreate_db") is not None:
AuraScheduler.init_database()
AuraDatabaseModel.recreate_db()
if start_lqs:
runner.run_lqs(lqs_debug_flags)
......
......@@ -99,6 +99,30 @@ class AuraDatabaseModel():
return self.__dict__
@staticmethod
def init_database():
"""
Initializes the database.
Raises:
sqlalchemy.exc.ProgrammingError: In case the DB model is invalid
"""
if AuraConfig.config().get("recreate_db") is not None:
AuraDatabaseModel.recreate_db(systemexit=True)
# Check if tables exists, if not create them
try:
Playlist.is_empty()
except sa.exc.ProgrammingError as e:
errcode = e.orig.args[0]
if errcode == 1146: # Error for no such table
model = AuraDatabaseModel()
model.recreate_db()
else:
raise
@staticmethod
def recreate_db(systemexit = False):
"""
......
......@@ -21,12 +21,11 @@
import logging
import threading
import time
import sqlalchemy
from src.base.config import AuraConfig
from src.base.utils import SimpleUtil as SU
from src.scheduling.models import AuraDatabaseModel, Playlist
from src.scheduling.models import AuraDatabaseModel
from src.base.exceptions import NoActiveTimeslotException, LoadSourceException
from src.core.control import EngineExecutor
from src.core.engine import Engine
......@@ -82,14 +81,14 @@ class AuraScheduler(threading.Thread):
self.config = AuraConfig.config()
self.logger = logging.getLogger("AuraEngine")
self.programme = Programme()
self.timeslot_renderer = TimeslotRenderer(self)
AuraScheduler.init_database()
self.timeslot_renderer = TimeslotRenderer(self)
self.fallback = fallback_manager
self.engine = engine
self.engine.scheduler = self
self.is_soundsytem_init = False
# Scheduler Initialization
AuraDatabaseModel.init_database()
self.is_initialized = False
self.is_engine_ready = False
......@@ -364,31 +363,6 @@ class AuraScheduler(threading.Thread):
# FIXME Move to adequate module
@staticmethod
def init_database():
"""
Initializes the database.
Raises:
sqlalchemy.exc.ProgrammingError: In case the DB model is invalid
"""
if AuraConfig.config().get("recreate_db") is not None:
AuraDatabaseModel.recreate_db(systemexit=True)
# Check if tables exists, if not create them
try:
Playlist.is_empty()
except sqlalchemy.exc.ProgrammingError as e:
errcode = e.orig.args[0]
if errcode == 1146: # Error for no such table
model = AuraDatabaseModel()
model.recreate_db()
else:
raise
def terminate(self):
"""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment