clean up indentation + imports for python apps
This commit is contained in:
parent
b6483cd952
commit
0a3c9c7351
|
@ -109,20 +109,6 @@ try:
|
||||||
print e
|
print e
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
"""
|
|
||||||
logging.basicConfig(format='%(message)s')
|
|
||||||
|
|
||||||
#generate liquidsoap config file
|
|
||||||
#access the DB and generate liquidsoap.cfg under /etc/airtime/
|
|
||||||
ac = api_client.api_client_factory(config, logging.getLogger())
|
|
||||||
ss = ac.get_stream_setting()
|
|
||||||
|
|
||||||
if ss is not None:
|
|
||||||
generate_liquidsoap_config(ss)
|
|
||||||
else:
|
|
||||||
print "Unable to connect to the Airtime server."
|
|
||||||
"""
|
|
||||||
|
|
||||||
#initialize init.d scripts
|
#initialize init.d scripts
|
||||||
subprocess.call("update-rc.d airtime-playout defaults >/dev/null 2>&1", shell=True)
|
subprocess.call("update-rc.d airtime-playout defaults >/dev/null 2>&1", shell=True)
|
||||||
|
|
||||||
|
|
|
@ -3,12 +3,10 @@ Python part of radio playout (pypo)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import time
|
import time
|
||||||
from optparse import *
|
from optparse import OptionParser
|
||||||
import sys
|
import sys
|
||||||
import signal
|
import signal
|
||||||
import logging
|
import logging
|
||||||
import logging.config
|
|
||||||
import logging.handlers
|
|
||||||
import locale
|
import locale
|
||||||
import os
|
import os
|
||||||
from Queue import Queue
|
from Queue import Queue
|
||||||
|
|
|
@ -3,9 +3,7 @@
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
import logging
|
|
||||||
import logging.config
|
import logging.config
|
||||||
import shutil
|
|
||||||
import json
|
import json
|
||||||
import telnetlib
|
import telnetlib
|
||||||
import copy
|
import copy
|
||||||
|
@ -75,12 +73,12 @@ class PypoFetch(Thread):
|
||||||
try:
|
try:
|
||||||
self.logger.info("Received event from Pypo Message Handler: %s" % message)
|
self.logger.info("Received event from Pypo Message Handler: %s" % message)
|
||||||
|
|
||||||
m = json.loads(message)
|
m = json.loads(message)
|
||||||
command = m['event_type']
|
command = m['event_type']
|
||||||
self.logger.info("Handling command: " + command)
|
self.logger.info("Handling command: " + command)
|
||||||
|
|
||||||
if command == 'update_schedule':
|
if command == 'update_schedule':
|
||||||
self.schedule_data = m['schedule']
|
self.schedule_data = m['schedule']
|
||||||
self.process_schedule(self.schedule_data)
|
self.process_schedule(self.schedule_data)
|
||||||
elif command == 'update_stream_setting':
|
elif command == 'update_stream_setting':
|
||||||
self.logger.info("Updating stream setting...")
|
self.logger.info("Updating stream setting...")
|
||||||
|
@ -174,7 +172,7 @@ class PypoFetch(Thread):
|
||||||
self.logger.error('Unable to get bootstrap info.. Existing pypo...')
|
self.logger.error('Unable to get bootstrap info.. Existing pypo...')
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
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(self.logger, self.telnet_lock, 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'])
|
||||||
|
@ -267,13 +265,13 @@ class PypoFetch(Thread):
|
||||||
self.logger.info("'Need-to-restart' state detected for %s...", s[u'keyname'])
|
self.logger.info("'Need-to-restart' state detected for %s...", s[u'keyname'])
|
||||||
restart = True;
|
restart = True;
|
||||||
else:
|
else:
|
||||||
stream, dump = s[u'keyname'].split('_',1)
|
stream, dump = s[u'keyname'].split('_', 1)
|
||||||
if "_output" in s[u'keyname']:
|
if "_output" in s[u'keyname']:
|
||||||
if (existing[s[u'keyname']] != s[u'value']):
|
if (existing[s[u'keyname']] != s[u'value']):
|
||||||
self.logger.info("'Need-to-restart' state detected for %s...", s[u'keyname'])
|
self.logger.info("'Need-to-restart' state detected for %s...", s[u'keyname'])
|
||||||
restart = True;
|
restart = True;
|
||||||
state_change_restart[stream] = True
|
state_change_restart[stream] = True
|
||||||
elif ( s[u'value'] != 'disabled'):
|
elif (s[u'value'] != 'disabled'):
|
||||||
state_change_restart[stream] = True
|
state_change_restart[stream] = True
|
||||||
else:
|
else:
|
||||||
state_change_restart[stream] = False
|
state_change_restart[stream] = False
|
||||||
|
@ -314,7 +312,7 @@ class PypoFetch(Thread):
|
||||||
# we are manually adjusting the bootup time variable so the status msg will get
|
# we are manually adjusting the bootup time variable so the status msg will get
|
||||||
# updated.
|
# updated.
|
||||||
current_time = time.time()
|
current_time = time.time()
|
||||||
boot_up_time_command = "vars.bootup_time "+str(current_time)+"\n"
|
boot_up_time_command = "vars.bootup_time " + str(current_time) + "\n"
|
||||||
tn.write(boot_up_time_command)
|
tn.write(boot_up_time_command)
|
||||||
tn.write("streams.connection_status\n")
|
tn.write("streams.connection_status\n")
|
||||||
tn.write('exit\n')
|
tn.write('exit\n')
|
||||||
|
@ -425,7 +423,7 @@ class PypoFetch(Thread):
|
||||||
media_item = media[key]
|
media_item = media[key]
|
||||||
if(media_item['type'] == 'file'):
|
if(media_item['type'] == 'file'):
|
||||||
fileExt = os.path.splitext(media_item['uri'])[1]
|
fileExt = os.path.splitext(media_item['uri'])[1]
|
||||||
dst = os.path.join(download_dir, media_item['id']+fileExt)
|
dst = os.path.join(download_dir, media_item['id'] + fileExt)
|
||||||
media_item['dst'] = dst
|
media_item['dst'] = dst
|
||||||
media_filtered[key] = media_item
|
media_filtered[key] = media_item
|
||||||
|
|
||||||
|
@ -458,9 +456,9 @@ class PypoFetch(Thread):
|
||||||
unneeded_files = cached_file_set - scheduled_file_set
|
unneeded_files = cached_file_set - scheduled_file_set
|
||||||
|
|
||||||
self.logger.debug("Files to remove " + str(unneeded_files))
|
self.logger.debug("Files to remove " + str(unneeded_files))
|
||||||
for file in unneeded_files:
|
for f in unneeded_files:
|
||||||
self.logger.debug("Removing %s" % os.path.join(self.cache_dir, file))
|
self.logger.debug("Removing %s" % os.path.join(self.cache_dir, f))
|
||||||
os.remove(os.path.join(self.cache_dir, file))
|
os.remove(os.path.join(self.cache_dir, f))
|
||||||
|
|
||||||
def main(self):
|
def main(self):
|
||||||
# Bootstrap: since we are just starting up, we need to grab the
|
# Bootstrap: since we are just starting up, we need to grab the
|
||||||
|
|
|
@ -5,7 +5,6 @@ from Queue import Empty
|
||||||
from configobj import ConfigObj
|
from configobj import ConfigObj
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import logging.config
|
|
||||||
import shutil
|
import shutil
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import logging.config
|
|
||||||
import sys
|
import sys
|
||||||
from configobj import ConfigObj
|
from configobj import ConfigObj
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
|
@ -62,7 +61,7 @@ class PypoMessageHandler(Thread):
|
||||||
try:
|
try:
|
||||||
self.logger.info("Received event from RabbitMQ: %s" % message)
|
self.logger.info("Received event from RabbitMQ: %s" % message)
|
||||||
|
|
||||||
m = json.loads(message)
|
m = json.loads(message)
|
||||||
command = m['event_type']
|
command = m['event_type']
|
||||||
self.logger.info("Handling command: " + command)
|
self.logger.info("Handling command: " + command)
|
||||||
|
|
||||||
|
@ -126,10 +125,8 @@ class PypoMessageHandler(Thread):
|
||||||
There is a problem with the RabbitMq messenger service. Let's
|
There is a problem with the RabbitMq messenger service. Let's
|
||||||
log the error and get the schedule via HTTP polling
|
log the error and get the schedule via HTTP polling
|
||||||
"""
|
"""
|
||||||
import traceback
|
|
||||||
top = traceback.format_exc()
|
|
||||||
self.logger.error('Exception: %s', e)
|
self.logger.error('Exception: %s', e)
|
||||||
self.logger.error("traceback: %s", top)
|
self.logger.error("traceback: %s", traceback.format_exc())
|
||||||
|
|
||||||
loops += 1
|
loops += 1
|
||||||
|
|
||||||
|
|
|
@ -5,11 +5,9 @@ from datetime import timedelta
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
import logging
|
|
||||||
import logging.config
|
import logging.config
|
||||||
import telnetlib
|
import telnetlib
|
||||||
import calendar
|
import calendar
|
||||||
import json
|
|
||||||
import math
|
import math
|
||||||
from pypofetch import PypoFetch
|
from pypofetch import PypoFetch
|
||||||
|
|
||||||
|
@ -54,7 +52,7 @@ class PypoPush(Thread):
|
||||||
|
|
||||||
def main(self):
|
def main(self):
|
||||||
loops = 0
|
loops = 0
|
||||||
heartbeat_period = math.floor(30/PUSH_INTERVAL)
|
heartbeat_period = math.floor(30 / PUSH_INTERVAL)
|
||||||
|
|
||||||
next_media_item_chain = None
|
next_media_item_chain = None
|
||||||
media_schedule = None
|
media_schedule = None
|
||||||
|
@ -170,7 +168,7 @@ class PypoPush(Thread):
|
||||||
queue.
|
queue.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
problem_at_iteration, problem_start_time = self.find_removed_items(media_schedule, liquidsoap_queue_approx)
|
problem_at_iteration = self.find_removed_items(media_schedule, liquidsoap_queue_approx)
|
||||||
|
|
||||||
if problem_at_iteration is not None:
|
if problem_at_iteration is not None:
|
||||||
#Items that are in Liquidsoap's queue aren't scheduled anymore. We need to connect
|
#Items that are in Liquidsoap's queue aren't scheduled anymore. We need to connect
|
||||||
|
@ -201,7 +199,6 @@ class PypoPush(Thread):
|
||||||
#see if they are the same as the newly received schedule
|
#see if they are the same as the newly received schedule
|
||||||
iteration = 0
|
iteration = 0
|
||||||
problem_at_iteration = None
|
problem_at_iteration = None
|
||||||
problem_start_time = None
|
|
||||||
for queue_item in liquidsoap_queue_approx:
|
for queue_item in liquidsoap_queue_approx:
|
||||||
if queue_item['start'] in media_schedule.keys():
|
if queue_item['start'] in media_schedule.keys():
|
||||||
media_item = media_schedule[queue_item['start']]
|
media_item = media_schedule[queue_item['start']]
|
||||||
|
@ -211,23 +208,20 @@ class PypoPush(Thread):
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
problem_at_iteration = iteration
|
problem_at_iteration = iteration
|
||||||
problem_start_time = queue_item['start']
|
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
#A different item has been scheduled at the same time! Need to remove
|
#A different item has been scheduled at the same time! Need to remove
|
||||||
#all tracks from the Liquidsoap queue starting at this point, and re-add
|
#all tracks from the Liquidsoap queue starting at this point, and re-add
|
||||||
#them.
|
#them.
|
||||||
problem_at_iteration = iteration
|
problem_at_iteration = iteration
|
||||||
problem_start_time = queue_item['start']
|
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
#There are no more items scheduled for this time! The user has shortened
|
#There are no more items scheduled for this time! The user has shortened
|
||||||
#the playlist, so we simply need to remove tracks from the queue.
|
#the playlist, so we simply need to remove tracks from the queue.
|
||||||
problem_at_iteration = iteration
|
problem_at_iteration = iteration
|
||||||
problem_start_time = queue_item['start']
|
|
||||||
break
|
break
|
||||||
iteration+=1
|
iteration += 1
|
||||||
return (problem_at_iteration, problem_start_time)
|
return problem_at_iteration
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -312,7 +306,7 @@ class PypoPush(Thread):
|
||||||
|
|
||||||
|
|
||||||
def date_interval_to_seconds(self, interval):
|
def date_interval_to_seconds(self, interval):
|
||||||
return (interval.microseconds + (interval.seconds + interval.days * 24 * 3600) * 10**6) / float(10**6)
|
return (interval.microseconds + (interval.seconds + interval.days * 24 * 3600) * 10 ** 6) / float(10 ** 6)
|
||||||
|
|
||||||
def push_to_liquidsoap(self, event_chain):
|
def push_to_liquidsoap(self, event_chain):
|
||||||
|
|
||||||
|
@ -448,7 +442,7 @@ class PypoPush(Thread):
|
||||||
def create_liquidsoap_annotation(self, media):
|
def create_liquidsoap_annotation(self, media):
|
||||||
# we need lia_start_next value in the annotate. That is the value that controlls overlap duration of crossfade.
|
# we need lia_start_next value in the annotate. That is the value that controlls overlap duration of crossfade.
|
||||||
return 'annotate:media_id="%s",liq_start_next="0",liq_fade_in="%s",liq_fade_out="%s",liq_cue_in="%s",liq_cue_out="%s",schedule_table_id="%s":%s' \
|
return 'annotate:media_id="%s",liq_start_next="0",liq_fade_in="%s",liq_fade_out="%s",liq_cue_in="%s",liq_cue_out="%s",schedule_table_id="%s":%s' \
|
||||||
% (media['id'], float(media['fade_in'])/1000, float(media['fade_out'])/1000, float(media['cue_in']), float(media['cue_out']), media['row_id'], media['dst'])
|
% (media['id'], float(media['fade_in']) / 1000, float(media['fade_out']) / 1000, float(media['cue_in']), float(media['cue_out']), media['row_id'], media['dst'])
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
try: self.main()
|
try: self.main()
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import logging.config
|
|
||||||
import json
|
import json
|
||||||
import time
|
import time
|
||||||
import datetime
|
import datetime
|
||||||
|
@ -55,7 +54,7 @@ class ShowRecorder(Thread):
|
||||||
self.p = None
|
self.p = None
|
||||||
|
|
||||||
def record_show(self):
|
def record_show(self):
|
||||||
length = str(self.filelength)+".0"
|
length = str(self.filelength) + ".0"
|
||||||
filename = self.start_time
|
filename = self.start_time
|
||||||
filename = filename.replace(" ", "-")
|
filename = filename.replace(" ", "-")
|
||||||
|
|
||||||
|
@ -128,7 +127,7 @@ class ShowRecorder(Thread):
|
||||||
time = md[1].replace(":", "-")
|
time = md[1].replace(":", "-")
|
||||||
self.logger.info("time: %s" % time)
|
self.logger.info("time: %s" % time)
|
||||||
|
|
||||||
name = time+"-"+self.show_name
|
name = time + "-" + self.show_name
|
||||||
artist = "Airtime Show Recorder"
|
artist = "Airtime Show Recorder"
|
||||||
|
|
||||||
#set some metadata for our file daemon
|
#set some metadata for our file daemon
|
||||||
|
@ -181,7 +180,7 @@ class Recorder(Thread):
|
||||||
def handle_message(self):
|
def handle_message(self):
|
||||||
if not self.queue.empty():
|
if not self.queue.empty():
|
||||||
message = self.queue.get()
|
message = self.queue.get()
|
||||||
msg = json.loads(message)
|
msg = json.loads(message)
|
||||||
command = msg["event_type"]
|
command = msg["event_type"]
|
||||||
self.logger.info("Received msg from Pypo Message Handler: %s", msg)
|
self.logger.info("Received msg from Pypo Message Handler: %s", msg)
|
||||||
if command == 'cancel_recording':
|
if command == 'cancel_recording':
|
||||||
|
@ -243,14 +242,14 @@ class Recorder(Thread):
|
||||||
start_time_on_UTC = getDateTimeObj(start_time)
|
start_time_on_UTC = getDateTimeObj(start_time)
|
||||||
start_time_on_server = start_time_on_UTC.replace(tzinfo=pytz.utc).astimezone(T)
|
start_time_on_server = start_time_on_UTC.replace(tzinfo=pytz.utc).astimezone(T)
|
||||||
start_time_formatted = '%(year)d-%(month)02d-%(day)02d %(hour)02d:%(min)02d:%(sec)02d' % \
|
start_time_formatted = '%(year)d-%(month)02d-%(day)02d %(hour)02d:%(min)02d:%(sec)02d' % \
|
||||||
{'year': start_time_on_server.year, 'month': start_time_on_server.month, 'day': start_time_on_server.day,\
|
{'year': start_time_on_server.year, 'month': start_time_on_server.month, 'day': start_time_on_server.day, \
|
||||||
'hour': start_time_on_server.hour, 'min': start_time_on_server.minute, 'sec': start_time_on_server.second}
|
'hour': start_time_on_server.hour, 'min': start_time_on_server.minute, 'sec': start_time_on_server.second}
|
||||||
self.sr = ShowRecorder(show_instance, show_name, show_length.seconds, start_time_formatted)
|
self.sr = ShowRecorder(show_instance, show_name, show_length.seconds, start_time_formatted)
|
||||||
self.sr.start()
|
self.sr.start()
|
||||||
#remove show from shows to record.
|
#remove show from shows to record.
|
||||||
del self.shows_to_record[start_time]
|
del self.shows_to_record[start_time]
|
||||||
#self.time_till_next_show = self.get_time_till_next_show()
|
#self.time_till_next_show = self.get_time_till_next_show()
|
||||||
except Exception,e :
|
except Exception, e :
|
||||||
import traceback
|
import traceback
|
||||||
top = traceback.format_exc()
|
top = traceback.format_exc()
|
||||||
self.logger.error('Exception: %s', e)
|
self.logger.error('Exception: %s', e)
|
||||||
|
@ -277,7 +276,7 @@ class Recorder(Thread):
|
||||||
self.logger.info("Bootstrap complete: got initial copy of the schedule")
|
self.logger.info("Bootstrap complete: got initial copy of the schedule")
|
||||||
|
|
||||||
self.loops = 0
|
self.loops = 0
|
||||||
heartbeat_period = math.floor(30/PUSH_INTERVAL)
|
heartbeat_period = math.floor(30 / PUSH_INTERVAL)
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
if self.loops % heartbeat_period == 0:
|
if self.loops % heartbeat_period == 0:
|
||||||
|
@ -299,7 +298,7 @@ class Recorder(Thread):
|
||||||
self.logger.error('Pypo Recorder Exception: %s', e)
|
self.logger.error('Pypo Recorder Exception: %s', e)
|
||||||
time.sleep(PUSH_INTERVAL)
|
time.sleep(PUSH_INTERVAL)
|
||||||
self.loops += 1
|
self.loops += 1
|
||||||
except Exception,e :
|
except Exception, e :
|
||||||
import traceback
|
import traceback
|
||||||
top = traceback.format_exc()
|
top = traceback.format_exc()
|
||||||
self.logger.error('Exception: %s', e)
|
self.logger.error('Exception: %s', e)
|
||||||
|
|
Loading…
Reference in New Issue