CC-3535: PypoFetch: make disconnect_source() and switch_source() static method
- done
This commit is contained in:
parent
03c5daa9e7
commit
f4b9774b08
|
@ -87,10 +87,10 @@ class PypoFetch(Thread):
|
||||||
self.update_liquidsoap_transition_fade(m['transition_fade'])
|
self.update_liquidsoap_transition_fade(m['transition_fade'])
|
||||||
elif command == 'switch_source':
|
elif command == 'switch_source':
|
||||||
self.logger.info("switch_on_source show command received...")
|
self.logger.info("switch_on_source show command received...")
|
||||||
self.switch_source(m['sourcename'], m['status'])
|
self.switch_source(self.logger, self.telnet_lock, m['sourcename'], m['status'])
|
||||||
elif command == 'disconnect_source':
|
elif command == 'disconnect_source':
|
||||||
self.logger.info("disconnect_on_source show command received...")
|
self.logger.info("disconnect_on_source show command received...")
|
||||||
self.disconnect_source(m['sourcename'])
|
self.disconnect_source(self.logger, self.telnet.lock, m['sourcename'])
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
import traceback
|
import traceback
|
||||||
top = traceback.format_exc()
|
top = traceback.format_exc()
|
||||||
|
@ -98,27 +98,29 @@ class PypoFetch(Thread):
|
||||||
self.logger.error("traceback: %s", top)
|
self.logger.error("traceback: %s", top)
|
||||||
self.logger.error("Exception in handling Message Handler message: %s", e)
|
self.logger.error("Exception in handling Message Handler message: %s", e)
|
||||||
|
|
||||||
def disconnect_source(self,sourcename):
|
@staticmethod
|
||||||
self.logger.debug('Disconnecting source: %s', sourcename)
|
def disconnect_source(logger, lock, sourcename):
|
||||||
|
logger.debug('Disconnecting source: %s', sourcename)
|
||||||
command = ""
|
command = ""
|
||||||
if(sourcename == "master_dj"):
|
if(sourcename == "master_dj"):
|
||||||
command += "master_harbor.kick\n"
|
command += "master_harbor.kick\n"
|
||||||
elif(sourcename == "live_dj"):
|
elif(sourcename == "live_dj"):
|
||||||
command += "live_dj_harbor.kick\n"
|
command += "live_dj_harbor.kick\n"
|
||||||
|
|
||||||
self.telnet_lock.acquire()
|
lock.acquire()
|
||||||
try:
|
try:
|
||||||
tn = telnetlib.Telnet(LS_HOST, LS_PORT)
|
tn = telnetlib.Telnet(LS_HOST, LS_PORT)
|
||||||
tn.write(command)
|
tn.write(command)
|
||||||
tn.write('exit\n')
|
tn.write('exit\n')
|
||||||
tn.read_all()
|
tn.read_all()
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
self.logger.error(str(e))
|
logger.error(str(e))
|
||||||
finally:
|
finally:
|
||||||
self.telnet_lock.release()
|
lock.release()
|
||||||
|
|
||||||
def switch_source(self, sourcename, status):
|
@staticmethod
|
||||||
self.logger.debug('Switching source: %s to "%s" status', sourcename, status)
|
def switch_source(logger, lock, sourcename, status):
|
||||||
|
logger.debug('Switching source: %s to "%s" status', sourcename, status)
|
||||||
command = "streams."
|
command = "streams."
|
||||||
if(sourcename == "master_dj"):
|
if(sourcename == "master_dj"):
|
||||||
command += "master_dj_"
|
command += "master_dj_"
|
||||||
|
@ -132,16 +134,16 @@ class PypoFetch(Thread):
|
||||||
else:
|
else:
|
||||||
command += "stop\n"
|
command += "stop\n"
|
||||||
|
|
||||||
self.telnet_lock.acquire()
|
lock.acquire()
|
||||||
try:
|
try:
|
||||||
tn = telnetlib.Telnet(LS_HOST, LS_PORT)
|
tn = telnetlib.Telnet(LS_HOST, LS_PORT)
|
||||||
tn.write(command)
|
tn.write(command)
|
||||||
tn.write('exit\n')
|
tn.write('exit\n')
|
||||||
tn.read_all()
|
tn.read_all()
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
self.logger.error(str(e))
|
logger.error(str(e))
|
||||||
finally:
|
finally:
|
||||||
self.telnet_lock.release()
|
lock.release()
|
||||||
|
|
||||||
"""
|
"""
|
||||||
grabs some information that are needed to be set on bootstrap time
|
grabs some information that are needed to be set on bootstrap time
|
||||||
|
@ -156,7 +158,7 @@ class PypoFetch(Thread):
|
||||||
else:
|
else:
|
||||||
self.logger.debug('info:%s',info)
|
self.logger.debug('info:%s',info)
|
||||||
for k, v in info['switch_status'].iteritems():
|
for k, v in info['switch_status'].iteritems():
|
||||||
self.switch_source(k, v)
|
self.switch_source(self.logger, self.telnet_lock, k, v)
|
||||||
self.update_liquidsoap_stream_format(info['stream_label'])
|
self.update_liquidsoap_stream_format(info['stream_label'])
|
||||||
self.update_liquidsoap_station_name(info['station_name'])
|
self.update_liquidsoap_station_name(info['station_name'])
|
||||||
self.update_liquidsoap_transition_fade(info['transition_fade'])
|
self.update_liquidsoap_transition_fade(info['transition_fade'])
|
||||||
|
|
Loading…
Reference in New Issue