2023-08-07 11:39:15 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
import logging
|
|
|
|
from argparse import ArgumentParser
|
|
|
|
from queue import Queue
|
|
|
|
from sys import exit
|
|
|
|
from time import sleep
|
|
|
|
|
2023-08-07 18:05:20 +00:00
|
|
|
from conf import load_and_validate_config
|
2023-08-07 11:39:15 +00:00
|
|
|
from dmx_queue import DMXQueue
|
2023-08-07 12:48:18 +00:00
|
|
|
from mqtt_queue import MQTTQueue
|
2023-08-07 11:39:15 +00:00
|
|
|
|
|
|
|
logging.basicConfig(
|
2023-08-07 13:06:38 +00:00
|
|
|
level=logging.INFO,
|
2024-08-17 10:19:01 +00:00
|
|
|
format="%(asctime)s %(name)20s [%(levelname)-8s] %(message)s",
|
2023-08-07 11:39:15 +00:00
|
|
|
)
|
|
|
|
|
2024-08-17 10:19:01 +00:00
|
|
|
LOG = logging.getLogger("main")
|
2023-08-07 11:39:15 +00:00
|
|
|
|
|
|
|
|
2023-08-07 12:48:18 +00:00
|
|
|
def main():
|
2023-08-07 11:39:15 +00:00
|
|
|
parser = ArgumentParser()
|
2023-08-07 12:46:22 +00:00
|
|
|
parser.add_argument(
|
2024-08-17 10:19:01 +00:00
|
|
|
"--config",
|
|
|
|
default="config.toml",
|
2023-08-07 12:46:22 +00:00
|
|
|
)
|
2023-08-07 11:39:15 +00:00
|
|
|
args = parser.parse_args()
|
2023-08-07 18:05:20 +00:00
|
|
|
config = load_and_validate_config(args.config)
|
2023-08-07 11:39:15 +00:00
|
|
|
|
2024-08-17 10:19:01 +00:00
|
|
|
LOG.info("Welcome to Voc2DMX")
|
2023-08-07 11:39:15 +00:00
|
|
|
|
2024-08-17 10:19:01 +00:00
|
|
|
queues = {}
|
|
|
|
dmx_workers = {}
|
|
|
|
|
|
|
|
LOG.info("Initializing worker queues ...")
|
|
|
|
|
|
|
|
mqttq = MQTTQueue(config, queues)
|
2023-08-07 11:39:15 +00:00
|
|
|
mqttq.start()
|
|
|
|
|
2024-08-17 10:19:01 +00:00
|
|
|
for universe in config.universes:
|
|
|
|
queues[universe] = Queue()
|
|
|
|
dmx_workers[universe] = DMXQueue(config, universe, queues[universe])
|
|
|
|
dmx_workers[universe].start()
|
|
|
|
|
|
|
|
LOG.info("initialization done, now running. Press Ctrl-C to stop")
|
2023-08-07 11:39:15 +00:00
|
|
|
|
|
|
|
try:
|
|
|
|
while True:
|
|
|
|
sleep(1)
|
2024-08-17 10:19:01 +00:00
|
|
|
finally:
|
|
|
|
LOG.warning("Got interrupt, stopping queues ...")
|
2023-08-07 11:39:15 +00:00
|
|
|
mqttq.stop()
|
2024-08-17 10:19:01 +00:00
|
|
|
for universe in config.universes:
|
|
|
|
dmx_workers[universe].stop()
|
2023-08-07 11:39:15 +00:00
|
|
|
|
2024-08-17 10:19:01 +00:00
|
|
|
LOG.info("Bye!")
|
2023-08-07 11:39:15 +00:00
|
|
|
|
2023-08-07 12:48:18 +00:00
|
|
|
|
2024-08-17 10:19:01 +00:00
|
|
|
if __name__ == "__main__":
|
2023-08-07 11:39:15 +00:00
|
|
|
main()
|