Merge branch 'martin' into 2.3.x

This commit is contained in:
Martin Konecny 2013-01-29 12:17:36 -05:00
commit 9d4e0d2dd1
3 changed files with 55 additions and 20 deletions

View File

@ -28,10 +28,10 @@ start () {
stop () { stop () {
monit unmonitor airtime-liquidsoap >/dev/null 2>&1 monit unmonitor airtime-liquidsoap >/dev/null 2>&1
/usr/lib/airtime/airtime_virtualenv/bin/python /usr/lib/airtime/pypo/bin/liquidsoap_scripts/liquidsoap_prepare_terminate.py #send term signal after 10 seconds
timeout 10 /usr/lib/airtime/airtime_virtualenv/bin/python /usr/lib/airtime/pypo/bin/liquidsoap_scripts/liquidsoap_prepare_terminate.py
# Send TERM after 5 seconds, wait at most 30 seconds. # Send TERM after 5 seconds, wait at most 30 seconds.
start-stop-daemon --stop --oknodo --retry 5 --quiet --pidfile $PIDFILE start-stop-daemon --stop --oknodo --retry=TERM/10/KILL/5 --quiet --pidfile $PIDFILE
rm -f $PIDFILE rm -f $PIDFILE
} }

View File

@ -6,14 +6,14 @@ try:
config = ConfigObj('/etc/airtime/pypo.cfg') config = ConfigObj('/etc/airtime/pypo.cfg')
LS_HOST = config['ls_host'] LS_HOST = config['ls_host']
LS_PORT = config['ls_port'] LS_PORT = config['ls_port']
tn = telnetlib.Telnet(LS_HOST, LS_PORT) tn = telnetlib.Telnet(LS_HOST, LS_PORT)
tn.write("master_harbor.stop\n") tn.write("master_harbor.stop\n")
tn.write("live_dj_harbor.stop\n") tn.write("live_dj_harbor.stop\n")
tn.write('exit\n') tn.write('exit\n')
tn.read_all() tn.read_all()
except Exception, e: except Exception, e:
print('Error loading config file: %s', e) print('Error loading config file: %s', e)
sys.exit() sys.exit()

View File

@ -144,6 +144,24 @@ class PypoFetch(Thread):
finally: finally:
lock.release() lock.release()
@staticmethod
def telnet_send(logger, lock, commands):
try:
lock.acquire()
tn = telnetlib.Telnet(LS_HOST, LS_PORT)
for i in commands:
logger.info(i)
tn.write(i)
tn.write('exit\n')
tn.read_all()
except Exception, e:
logger.error(str(e))
finally:
lock.release()
@staticmethod @staticmethod
def switch_source(logger, lock, sourcename, status): def switch_source(logger, lock, sourcename, status):
logger.debug('Switching source: %s to "%s" status', sourcename, status) logger.debug('Switching source: %s to "%s" status', sourcename, status)
@ -160,17 +178,26 @@ class PypoFetch(Thread):
else: else:
command += "stop\n" command += "stop\n"
try: PypoFetch.telnet_send(logger, lock, [command])
lock.acquire()
tn = telnetlib.Telnet(LS_HOST, LS_PORT)
tn.write(command) #TODO: Merge this with switch_source
tn.write('exit\n') def switch_source_temp(self, sourcename, status):
tn.read_all() self.logger.debug('Switching source: %s to "%s" status', sourcename, status)
except Exception, e: command = "streams."
logger.error(str(e)) if sourcename == "master_dj":
finally: command += "master_dj_"
lock.release() elif sourcename == "live_dj":
command += "live_dj_"
elif sourcename == "scheduled_play":
command += "scheduled_play_"
if status == "on":
command += "start\n"
else:
command += "stop\n"
return command
""" """
grabs some information that are needed to be set on bootstrap time grabs some information that are needed to be set on bootstrap time
@ -183,11 +210,18 @@ class PypoFetch(Thread):
self.logger.error('Unable to get bootstrap info.. Exiting pypo...') self.logger.error('Unable to get bootstrap info.. Exiting pypo...')
else: else:
self.logger.debug('info:%s', info) self.logger.debug('info:%s', info)
commands = []
for k, v in info['switch_status'].iteritems(): for k, v in info['switch_status'].iteritems():
self.switch_source(self.logger, self.telnet_lock, k, v) commands.append(self.switch_source_temp(k, v))
self.update_liquidsoap_stream_format(info['stream_label'])
self.update_liquidsoap_station_name(info['station_name']) stream_format = info['stream_label']
self.update_liquidsoap_transition_fade(info['transition_fade']) station_name = info['station_name']
fade = info['transition_fade']
commands.append(('vars.stream_metadata_type %s\n' % stream_format).encode('utf-8'))
commands.append(('vars.station_name %s\n' % station_name).encode('utf-8'))
commands.append(('vars.default_dj_fade %s\n' % fade).encode('utf-8'))
PypoFetch.telnet_send(self.logger, self.telnet_lock, commands)
def restart_liquidsoap(self): def restart_liquidsoap(self):
@ -362,6 +396,7 @@ class PypoFetch(Thread):
if(status == "true"): if(status == "true"):
self.api_client.notify_liquidsoap_status("OK", stream_id, str(fake_time)) self.api_client.notify_liquidsoap_status("OK", stream_id, str(fake_time))
def update_liquidsoap_stream_format(self, stream_format): def update_liquidsoap_stream_format(self, stream_format):
# Push stream metadata to liquidsoap # Push stream metadata to liquidsoap
# TODO: THIS LIQUIDSOAP STUFF NEEDS TO BE MOVED TO PYPO-PUSH!!! # TODO: THIS LIQUIDSOAP STUFF NEEDS TO BE MOVED TO PYPO-PUSH!!!