diff --git a/run.py b/run.py index 3fa2d593ccbbe76066adbf5cbac648653ccca570..eed4cc5626d60699a6972cf477a1264d237ece95 100755 --- a/run.py +++ b/run.py @@ -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) diff --git a/src/scheduling/models.py b/src/scheduling/models.py index f0f751e9df732bee60232eeea4e752ec9fd76156..89ae33c4a379190499c27eb0c4003a6dde56accd 100644 --- a/src/scheduling/models.py +++ b/src/scheduling/models.py @@ -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): """ diff --git a/src/scheduling/scheduler.py b/src/scheduling/scheduler.py index 731ce57daa5bdcad8a573d25c3c436e64b2b18c3..4aab1ac3b462e0d0dc2fc370d97854abb7089401 100644 --- a/src/scheduling/scheduler.py +++ b/src/scheduling/scheduler.py @@ -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): """