sintonia/playout/liquidsoap/generate_liquidsoap_cfg.py

65 lines
2.2 KiB
Python
Raw Normal View History

import logging
import os
import sys
import time
import traceback
2020-01-30 14:47:36 +01:00
from api_clients.version1 import AirtimeApiClient
2021-05-27 16:23:02 +02:00
def generate_liquidsoap_config(ss):
2021-05-27 16:23:02 +02:00
data = ss["msg"]
fh = open("/etc/airtime/liquidsoap.cfg", "w")
fh.write("################################################\n")
fh.write("# THIS FILE IS AUTO GENERATED. DO NOT CHANGE!! #\n")
fh.write("################################################\n")
fh.write("# The ignore() lines are to squash unused variable warnings\n")
2020-01-16 15:32:51 +01:00
for key, value in data.items():
try:
2021-05-27 16:23:02 +02:00
if not "port" in key and not "bitrate" in key: # Stupid hack
raise ValueError()
str_buffer = "%s = %s\n" % (key, int(value))
except ValueError:
2021-05-27 16:23:02 +02:00
try: # Is it a boolean?
if value == "true" or value == "false":
str_buffer = "%s = %s\n" % (key, value.lower())
else:
2021-05-27 16:23:02 +02:00
raise ValueError() # Just drop into the except below
except: # Everything else is a string
str_buffer = '%s = "%s"\n' % (key, value)
2020-01-23 11:37:49 +01:00
fh.write(str_buffer)
# ignore squashes unused variable errors from Liquidsoap
2020-01-23 11:37:49 +01:00
fh.write("ignore(%s)\n" % key)
auth_path = os.path.dirname(os.path.realpath(__file__))
fh.write('log_file = "/var/log/airtime/pypo-liquidsoap/<script>.log"\n')
fh.write('auth_path = "%s/liquidsoap_auth.py"\n' % auth_path)
fh.close()
2020-01-23 11:37:49 +01:00
2021-05-27 16:23:02 +02:00
def run():
2021-05-27 16:23:02 +02:00
logging.basicConfig(format="%(message)s")
attempts = 0
max_attempts = 10
successful = False
2020-01-23 11:37:49 +01:00
while not successful:
try:
ac = AirtimeApiClient(logging.getLogger())
ss = ac.get_stream_setting()
generate_liquidsoap_config(ss)
successful = True
2020-01-16 15:32:51 +01:00
except Exception as e:
2020-01-16 14:33:44 +01:00
print("Unable to connect to the Airtime server.")
logging.error(str(e))
logging.error("traceback: %s", traceback.format_exc())
if attempts == max_attempts:
logging.error("giving up and exiting...")
sys.exit(1)
else:
Merge branch '2.5.x-installer' into saas-installer-albert Conflicts: .gitignore airtime_mvc/application/Bootstrap.php airtime_mvc/application/configs/conf.php airtime_mvc/application/controllers/SystemstatusController.php airtime_mvc/application/controllers/UpgradeController.php airtime_mvc/application/upgrade/Upgrades.php airtime_mvc/application/views/scripts/systemstatus/index.phtml airtime_mvc/build/airtime.conf airtime_mvc/build/sql/defaultdata.sql airtime_mvc/public/index.php airtime_mvc/tests/application/helpers/AirtimeInstall.php install_minimal/airtime-install install_minimal/include/airtime-constants.php install_minimal/include/airtime-copy-files.sh install_minimal/include/airtime-db-install.php install_minimal/include/airtime-initialize.sh install_minimal/include/airtime-install.php install_minimal/include/airtime-installed-check.php install_minimal/include/airtime-remove-files.sh install_minimal/include/airtime-upgrade.php python_apps/media-monitor/install/media-monitor-copy-files.py python_apps/monit/monit-airtime-generic.cfg python_apps/pypo/airtime-playout python_apps/pypo/install/pypo-copy-files.py python_apps/pypo/liquidsoap/generate_liquidsoap_cfg.py python_apps/pypo/liquidsoap/ls_script.liq python_apps/pypo/pypo/__main__.py python_apps/pypo/pypo/media/update/replaygain.py python_apps/pypo/pypo/media/update/replaygainupdater.py python_apps/pypo/pypo/media/update/silananalyzer.py python_apps/python-virtualenv/airtime_virtual_env.pybundle python_apps/python-virtualenv/requirements utils/airtime-check-system.php
2015-05-22 22:05:29 +02:00
logging.info("Retrying in 3 seconds...")
time.sleep(3)
attempts += 1