startup.py 2.04 KB
Newer Older
David Trattnig's avatar
David Trattnig committed
1
#
David Trattnig's avatar
David Trattnig committed
2
3
4
# Aura Engine (https://gitlab.servus.at/aura/engine)
#
# Copyright (C) 2017-2020 - The Aura Engine Team.
David Trattnig's avatar
David Trattnig committed
5
6
7
8
9
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
David Trattnig's avatar
David Trattnig committed
10
#
David Trattnig's avatar
David Trattnig committed
11
12
13
14
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
David Trattnig's avatar
David Trattnig committed
15
#
David Trattnig's avatar
David Trattnig committed
16
17
18
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

David Trattnig's avatar
David Trattnig committed
19

David Trattnig's avatar
David Trattnig committed
20
21
22
23
24
import time
import logging
import datetime
import threading
import meta
25
import json
David Trattnig's avatar
David Trattnig committed
26

David Trattnig's avatar
David Trattnig committed
27
from modules.base.exceptions    import NoActiveScheduleException
28
from modules.base.utils         import TerminalColors, SimpleUtil, EngineUtil
David Trattnig's avatar
David Trattnig committed
29
30
31
32
33
34
35
36
37

class StartupThread(threading.Thread):
    """
    StartupThread class.

    Boots the mixer and starts playing the current schedule.
    """
    logger = None
    active_entry = None
David Trattnig's avatar
David Trattnig committed
38
    soundsystem = None
39
    scheduler = None
40
    monitoring = None   
David Trattnig's avatar
David Trattnig committed
41

David Trattnig's avatar
David Trattnig committed
42
    def __init__(self, soundsystem):
David Trattnig's avatar
David Trattnig committed
43
44
45
46
47
        """
        Initialize the thread.
        """
        threading.Thread.__init__(self)
        self.logger = logging.getLogger("AuraEngine")
David Trattnig's avatar
David Trattnig committed
48
49
        self.soundsystem = soundsystem
        self.scheduler = soundsystem.scheduler
David Trattnig's avatar
David Trattnig committed
50
51
52
53


    def run(self):
        """
54
        Boots the soundsystem.
David Trattnig's avatar
David Trattnig committed
55
56
        """
        try:
David Trattnig's avatar
David Trattnig committed
57
            self.soundsystem.start()            
David Trattnig's avatar
David Trattnig committed
58
            self.logger.info(EngineUtil.engine_info("Engine Core", meta.__version__))
59
            self.scheduler.on_ready()
David Trattnig's avatar
David Trattnig committed
60

61
62
        except NoActiveScheduleException as e:
            self.logger.info("Nothing scheduled at startup time. Please check if there are follow-up schedules.")
David Trattnig's avatar
David Trattnig committed
63
        except Exception as e:
David Trattnig's avatar
David Trattnig committed
64
65
            self.logger.error(SimpleUtil.red("Error while initializing the soundsystem: " + str(e)), e)

David Trattnig's avatar
David Trattnig committed
66
67
68