Ensure only telnetliquidsoap has telnet responsibilities
-also added module docstrings
This commit is contained in:
parent
888e6db812
commit
060980d8c6
13 changed files with 303 additions and 389 deletions
|
@ -2,10 +2,9 @@
|
|||
Python part of radio playout (pypo)
|
||||
"""
|
||||
|
||||
from optparse import OptionParser
|
||||
from datetime import datetime
|
||||
|
||||
import telnetlib
|
||||
from configobj import ConfigObj
|
||||
from Queue import Queue
|
||||
|
||||
import time
|
||||
import sys
|
||||
|
@ -13,10 +12,6 @@ import signal
|
|||
import logging
|
||||
import locale
|
||||
import os
|
||||
import re
|
||||
|
||||
from Queue import Queue
|
||||
from threading import Lock
|
||||
|
||||
from schedule.pypopush import PypoPush
|
||||
from schedule.pypofetch import PypoFetch
|
||||
|
@ -30,55 +25,10 @@ from schedule.pypoliquidsoap import PypoLiquidsoap
|
|||
from media.update.replaygainupdater import ReplayGainUpdater
|
||||
from media.update.silananalyzer import SilanAnalyzer
|
||||
|
||||
from configobj import ConfigObj
|
||||
|
||||
# custom imports
|
||||
from api_clients import api_client
|
||||
from std_err_override import LogWriter
|
||||
|
||||
# Set up command-line options
|
||||
parser = OptionParser()
|
||||
|
||||
# help screen / info
|
||||
usage = "%prog [options]" + " - python playout system"
|
||||
parser = OptionParser(usage=usage)
|
||||
|
||||
# Options
|
||||
parser.add_option("-v", "--compat",
|
||||
help="Check compatibility with server API version",
|
||||
default=False,
|
||||
action="store_true",
|
||||
dest="check_compat")
|
||||
|
||||
parser.add_option("-t", "--test",
|
||||
help="Do a test to make sure everything is working properly.",
|
||||
default=False,
|
||||
action="store_true",
|
||||
dest="test")
|
||||
|
||||
parser.add_option("-b",
|
||||
"--cleanup",
|
||||
help="Cleanup",
|
||||
default=False,
|
||||
action="store_true",
|
||||
dest="cleanup")
|
||||
|
||||
parser.add_option("-c",
|
||||
"--check",
|
||||
help="Check the cached schedule and exit",
|
||||
default=False,
|
||||
action="store_true",
|
||||
dest="check")
|
||||
|
||||
# parse options
|
||||
(options, args) = parser.parse_args()
|
||||
|
||||
LIQUIDSOAP_MIN_VERSION = "1.1.1"
|
||||
|
||||
|
||||
#need to wait for Python 2.7 for this..
|
||||
#logging.captureWarnings(True)
|
||||
|
||||
# configure logging
|
||||
try:
|
||||
logging.config.fileConfig("configs/logging.cfg")
|
||||
|
@ -131,16 +81,6 @@ def configure_locale():
|
|||
current_locale_encoding)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
configure_locale()
|
||||
|
||||
# loading config file
|
||||
try:
|
||||
config = ConfigObj('/etc/airtime/pypo.cfg')
|
||||
except Exception, e:
|
||||
logger.error('Error loading config file: %s', e)
|
||||
sys.exit(1)
|
||||
|
||||
class Global:
|
||||
def __init__(self, api_client):
|
||||
self.api_client = api_client
|
||||
|
@ -148,67 +88,21 @@ class Global:
|
|||
def selfcheck(self):
|
||||
return self.api_client.is_server_compatible()
|
||||
|
||||
def test_api(self):
|
||||
self.api_client.test()
|
||||
|
||||
def keyboardInterruptHandler(signum, frame):
|
||||
logger = logging.getLogger()
|
||||
logger.info('\nKeyboard Interrupt\n')
|
||||
sys.exit(0)
|
||||
|
||||
def liquidsoap_get_info(telnet_lock, host, port, logger):
|
||||
logger.debug("Checking to see if Liquidsoap is running")
|
||||
try:
|
||||
telnet_lock.acquire()
|
||||
tn = telnetlib.Telnet(host, port)
|
||||
msg = "version\n"
|
||||
tn.write(msg)
|
||||
tn.write("exit\n")
|
||||
response = tn.read_all()
|
||||
except Exception, e:
|
||||
logger.error(str(e))
|
||||
return None
|
||||
finally:
|
||||
telnet_lock.release()
|
||||
|
||||
return get_liquidsoap_version(response)
|
||||
|
||||
def get_liquidsoap_version(version_string):
|
||||
m = re.match(r"Liquidsoap (\d+.\d+.\d+)", "Liquidsoap 1.1.1")
|
||||
|
||||
if m:
|
||||
return m.group(1)
|
||||
else:
|
||||
return None
|
||||
|
||||
|
||||
if m:
|
||||
current_version = m.group(1)
|
||||
return pure.version_cmp(current_version, LIQUIDSOAP_MIN_VERSION) >= 0
|
||||
return False
|
||||
|
||||
def liquidsoap_startup_test():
|
||||
|
||||
liquidsoap_version_string = \
|
||||
liquidsoap_get_info(telnet_lock, ls_host, ls_port, logger)
|
||||
while not liquidsoap_version_string:
|
||||
logger.warning("Liquidsoap doesn't appear to be running!, " + \
|
||||
"Sleeping and trying again")
|
||||
time.sleep(1)
|
||||
liquidsoap_version_string = \
|
||||
liquidsoap_get_info(telnet_lock, ls_host, ls_port, logger)
|
||||
|
||||
while pure.version_cmp(liquidsoap_version_string, LIQUIDSOAP_MIN_VERSION) < 0:
|
||||
logger.warning("Liquidsoap is running but in incorrect version! " + \
|
||||
"Make sure you have at least Liquidsoap %s installed" % LIQUIDSOAP_MIN_VERSION)
|
||||
time.sleep(1)
|
||||
liquidsoap_version_string = \
|
||||
liquidsoap_get_info(telnet_lock, ls_host, ls_port, logger)
|
||||
|
||||
logger.info("Liquidsoap version string found %s" % liquidsoap_version_string)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
configure_locale()
|
||||
|
||||
# loading config file
|
||||
try:
|
||||
config = ConfigObj('/etc/airtime/pypo.cfg')
|
||||
except Exception, e:
|
||||
logger.error('Error loading config file: %s', e)
|
||||
sys.exit(1)
|
||||
|
||||
logger.info('###########################################')
|
||||
logger.info('# *** pypo *** #')
|
||||
logger.info('# Liquidsoap Scheduled Playout System #')
|
||||
|
@ -237,17 +131,11 @@ if __name__ == '__main__':
|
|||
logger.error(str(e))
|
||||
time.sleep(10)
|
||||
|
||||
telnet_lock = Lock()
|
||||
|
||||
ls_host = config['ls_host']
|
||||
ls_port = config['ls_port']
|
||||
|
||||
liquidsoap_startup_test()
|
||||
|
||||
if options.test:
|
||||
g.test_api()
|
||||
sys.exit(0)
|
||||
|
||||
pypo_liquidsoap = PypoLiquidsoap(logger, ls_host, ls_port)
|
||||
pypo_liquidsoap.liquidsoap_startup_test()
|
||||
|
||||
ReplayGainUpdater.start_reply_gain(api_client)
|
||||
SilanAnalyzer.start_silan(api_client, logger)
|
||||
|
@ -256,9 +144,6 @@ if __name__ == '__main__':
|
|||
recorder_q = Queue()
|
||||
pypoPush_q = Queue()
|
||||
|
||||
pypo_liquidsoap = PypoLiquidsoap(logger, telnet_lock,\
|
||||
ls_host, ls_port)
|
||||
|
||||
"""
|
||||
This queue is shared between pypo-fetch and pypo-file, where pypo-file
|
||||
is the consumer. Pypo-fetch will send every schedule it gets to pypo-file
|
||||
|
@ -275,11 +160,11 @@ if __name__ == '__main__':
|
|||
pfile.daemon = True
|
||||
pfile.start()
|
||||
|
||||
pf = PypoFetch(pypoFetch_q, pypoPush_q, media_q, telnet_lock, pypo_liquidsoap, config)
|
||||
pf = PypoFetch(pypoFetch_q, pypoPush_q, media_q, pypo_liquidsoap, config)
|
||||
pf.daemon = True
|
||||
pf.start()
|
||||
|
||||
pp = PypoPush(pypoPush_q, telnet_lock, pypo_liquidsoap, config)
|
||||
pp = PypoPush(pypoPush_q, pypo_liquidsoap)
|
||||
pp.daemon = True
|
||||
pp.start()
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue