-fix errors pointed out by pydev code completion
This commit is contained in:
parent
db4c916d9a
commit
7a7eb02de5
6 changed files with 15 additions and 80 deletions
|
@ -5,7 +5,6 @@ Python part of radio playout (pypo)
|
||||||
import time
|
import time
|
||||||
from optparse import *
|
from optparse import *
|
||||||
import sys
|
import sys
|
||||||
import os
|
|
||||||
import signal
|
import signal
|
||||||
import logging
|
import logging
|
||||||
import logging.config
|
import logging.config
|
||||||
|
|
|
@ -1,24 +1,13 @@
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
import calendar
|
|
||||||
import logging
|
import logging
|
||||||
import logging.config
|
import logging.config
|
||||||
import shutil
|
import shutil
|
||||||
import random
|
|
||||||
import string
|
|
||||||
import json
|
import json
|
||||||
import telnetlib
|
import telnetlib
|
||||||
import math
|
|
||||||
import copy
|
import copy
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
from threading import Lock
|
|
||||||
|
|
||||||
from subprocess import Popen, PIPE
|
|
||||||
from datetime import datetime
|
|
||||||
from datetime import timedelta
|
|
||||||
from Queue import Empty
|
|
||||||
import filecmp
|
|
||||||
|
|
||||||
from api_clients import api_client
|
from api_clients import api_client
|
||||||
|
|
||||||
|
@ -264,19 +253,19 @@ class PypoFetch(Thread):
|
||||||
fh.write("# THIS FILE IS AUTO GENERATED. DO NOT CHANGE!! #\n")
|
fh.write("# THIS FILE IS AUTO GENERATED. DO NOT CHANGE!! #\n")
|
||||||
fh.write("################################################\n")
|
fh.write("################################################\n")
|
||||||
for k, d in setting:
|
for k, d in setting:
|
||||||
buffer = d[u'keyname'] + " = "
|
buffer_str = d[u'keyname'] + " = "
|
||||||
if(d[u'type'] == 'string'):
|
if(d[u'type'] == 'string'):
|
||||||
temp = d[u'value']
|
temp = d[u'value']
|
||||||
if(temp == ""):
|
if(temp == ""):
|
||||||
temp = ""
|
temp = ""
|
||||||
buffer += "\"" + temp + "\""
|
buffer_str += "\"" + temp + "\""
|
||||||
else:
|
else:
|
||||||
temp = d[u'value']
|
temp = d[u'value']
|
||||||
if(temp == ""):
|
if(temp == ""):
|
||||||
temp = "0"
|
temp = "0"
|
||||||
buffer += temp
|
buffer_str += temp
|
||||||
buffer += "\n"
|
buffer_str += "\n"
|
||||||
fh.write(api_client.encode_to(buffer))
|
fh.write(api_client.encode_to(buffer_str))
|
||||||
fh.write("log_file = \"/var/log/airtime/pypo-liquidsoap/<script>.log\"\n");
|
fh.write("log_file = \"/var/log/airtime/pypo-liquidsoap/<script>.log\"\n");
|
||||||
fh.close()
|
fh.close()
|
||||||
# restarting pypo.
|
# restarting pypo.
|
||||||
|
|
|
@ -6,7 +6,7 @@ import logging
|
||||||
import logging.config
|
import logging.config
|
||||||
import shutil
|
import shutil
|
||||||
import os
|
import os
|
||||||
import time
|
import sys
|
||||||
|
|
||||||
# configure logging
|
# configure logging
|
||||||
logging.config.fileConfig("logging.cfg")
|
logging.config.fileConfig("logging.cfg")
|
||||||
|
@ -21,7 +21,7 @@ try:
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
logger = logging.getLogger()
|
logger = logging.getLogger()
|
||||||
logger.error('Error loading config file: %s', e)
|
logger.error('Error loading config file: %s', e)
|
||||||
sys.exit()
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
class PypoFile(Thread):
|
class PypoFile(Thread):
|
||||||
|
|
|
@ -6,8 +6,7 @@ from threading import Thread
|
||||||
import time
|
import time
|
||||||
# For RabbitMQ
|
# For RabbitMQ
|
||||||
from kombu.connection import BrokerConnection
|
from kombu.connection import BrokerConnection
|
||||||
from kombu.messaging import Exchange, Queue, Consumer, Producer
|
from kombu.messaging import Exchange, Queue
|
||||||
from kombu.exceptions import MessageStateError
|
|
||||||
from kombu.simple import SimpleQueue
|
from kombu.simple import SimpleQueue
|
||||||
import json
|
import json
|
||||||
|
|
||||||
|
|
|
@ -1,27 +1,16 @@
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
|
||||||
import os
|
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
import logging
|
import logging
|
||||||
import logging.config
|
import logging.config
|
||||||
import logging.handlers
|
|
||||||
import pickle
|
|
||||||
import telnetlib
|
import telnetlib
|
||||||
import calendar
|
import calendar
|
||||||
import json
|
import json
|
||||||
import math
|
import math
|
||||||
|
|
||||||
"""
|
|
||||||
It is possible to use a list as a queue, where the first element added is the first element
|
|
||||||
retrieved ("first-in, first-out"); however, lists are not efficient for this purpose. Let's use
|
|
||||||
"deque"
|
|
||||||
"""
|
|
||||||
from collections import deque
|
|
||||||
|
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
from threading import Lock
|
|
||||||
|
|
||||||
from api_clients import api_client
|
from api_clients import api_client
|
||||||
from configobj import ConfigObj
|
from configobj import ConfigObj
|
||||||
|
@ -69,7 +58,6 @@ class PypoPush(Thread):
|
||||||
|
|
||||||
liquidsoap_queue_approx = self.get_queue_items_from_liquidsoap()
|
liquidsoap_queue_approx = self.get_queue_items_from_liquidsoap()
|
||||||
|
|
||||||
timenow = time.time()
|
|
||||||
# get a new schedule from pypo-fetch
|
# get a new schedule from pypo-fetch
|
||||||
if not self.queue.empty():
|
if not self.queue.empty():
|
||||||
# make sure we get the latest schedule
|
# make sure we get the latest schedule
|
||||||
|
@ -82,22 +70,13 @@ class PypoPush(Thread):
|
||||||
|
|
||||||
|
|
||||||
media = self.media
|
media = self.media
|
||||||
|
|
||||||
self.logger.debug(liquidsoap_queue_approx)
|
|
||||||
|
|
||||||
if len(liquidsoap_queue_approx) < MAX_LIQUIDSOAP_QUEUE_LENGTH:
|
if len(liquidsoap_queue_approx) < MAX_LIQUIDSOAP_QUEUE_LENGTH:
|
||||||
if media:
|
if media:
|
||||||
|
|
||||||
tnow = datetime.utcnow()
|
tnow = datetime.utcnow()
|
||||||
tcoming = tnow + timedelta(seconds=self.push_ahead)
|
tcoming = tnow + timedelta(seconds=self.push_ahead)
|
||||||
|
|
||||||
"""
|
|
||||||
tnow = time.gmtime(timenow)
|
|
||||||
tcoming = time.gmtime(timenow + self.push_ahead)
|
|
||||||
str_tnow_s = "%04d-%02d-%02d-%02d-%02d-%02d" % (tnow[0], tnow[1], tnow[2], tnow[3], tnow[4], tnow[5])
|
|
||||||
str_tcoming_s = "%04d-%02d-%02d-%02d-%02d-%02d" % (tcoming[0], tcoming[1], tcoming[2], tcoming[3], tcoming[4], tcoming[5])
|
|
||||||
"""
|
|
||||||
|
|
||||||
for key in media.keys():
|
for key in media.keys():
|
||||||
media_item = media[key]
|
media_item = media[key]
|
||||||
|
|
||||||
|
@ -130,6 +109,7 @@ class PypoPush(Thread):
|
||||||
Temporary solution to make sure we don't push the same track multiple times. Not a full solution because if we
|
Temporary solution to make sure we don't push the same track multiple times. Not a full solution because if we
|
||||||
get a new schedule, the key becomes available again.
|
get a new schedule, the key becomes available again.
|
||||||
"""
|
"""
|
||||||
|
#TODO
|
||||||
del media[key]
|
del media[key]
|
||||||
|
|
||||||
def date_interval_to_seconds(self, interval):
|
def date_interval_to_seconds(self, interval):
|
||||||
|
@ -172,24 +152,7 @@ class PypoPush(Thread):
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
"""
|
|
||||||
def update_liquidsoap_queue(self):
|
|
||||||
# the queue variable liquidsoap_queue is our attempt to mirror
|
|
||||||
# what liquidsoap actually has in its own queue. Liquidsoap automatically
|
|
||||||
# updates its own queue when an item finishes playing, we have to do this
|
|
||||||
# manually.
|
|
||||||
#
|
|
||||||
# This function will iterate through the liquidsoap_queue and remove items
|
|
||||||
# whose end time are in the past.
|
|
||||||
|
|
||||||
tnow = time.gmtime(timenow)
|
|
||||||
str_tnow_s = "%04d-%02d-%02d-%02d-%02d-%02d" % (tnow[0], tnow[1], tnow[2], tnow[3], tnow[4], tnow[5])
|
|
||||||
|
|
||||||
while len(self.liquidsoap_queue) > 0:
|
|
||||||
if self.liquidsoap_queue[0]["end"] < str_tnow_s:
|
|
||||||
self.liquidsoap_queue.popleft()
|
|
||||||
"""
|
|
||||||
|
|
||||||
def get_queue_items_from_liquidsoap(self):
|
def get_queue_items_from_liquidsoap(self):
|
||||||
"""
|
"""
|
||||||
This function connects to Liquidsoap to find what media items are in its queue.
|
This function connects to Liquidsoap to find what media items are in its queue.
|
||||||
|
@ -241,10 +204,7 @@ class PypoPush(Thread):
|
||||||
call other functions that will connect to Liquidsoap and alter its
|
call other functions that will connect to Liquidsoap and alter its
|
||||||
queue.
|
queue.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
#TODO: Keys should already be sorted. Verify this.
|
|
||||||
sorted_keys = sorted(media.keys())
|
|
||||||
|
|
||||||
if len(liquidsoap_queue_approx) == 0:
|
if len(liquidsoap_queue_approx) == 0:
|
||||||
"""
|
"""
|
||||||
liquidsoap doesn't have anything in its queue, so we have nothing
|
liquidsoap doesn't have anything in its queue, so we have nothing
|
||||||
|
@ -363,8 +323,6 @@ class PypoPush(Thread):
|
||||||
show name of every media_item as well, just to keep Liquidsoap up-to-date
|
show name of every media_item as well, just to keep Liquidsoap up-to-date
|
||||||
about which show is playing.
|
about which show is playing.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.telnet_lock.acquire()
|
self.telnet_lock.acquire()
|
||||||
tn = telnetlib.Telnet(LS_HOST, LS_PORT)
|
tn = telnetlib.Telnet(LS_HOST, LS_PORT)
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
import urllib
|
|
||||||
import logging
|
import logging
|
||||||
import logging.config
|
import logging.config
|
||||||
import json
|
import json
|
||||||
|
@ -6,8 +5,6 @@ import time
|
||||||
import datetime
|
import datetime
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import shutil
|
|
||||||
import socket
|
|
||||||
import pytz
|
import pytz
|
||||||
import signal
|
import signal
|
||||||
import math
|
import math
|
||||||
|
@ -16,7 +13,6 @@ from configobj import ConfigObj
|
||||||
|
|
||||||
from poster.encode import multipart_encode
|
from poster.encode import multipart_encode
|
||||||
from poster.streaminghttp import register_openers
|
from poster.streaminghttp import register_openers
|
||||||
import urllib2
|
|
||||||
|
|
||||||
from subprocess import Popen
|
from subprocess import Popen
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
|
@ -25,15 +21,11 @@ import mutagen
|
||||||
|
|
||||||
from api_clients import api_client
|
from api_clients import api_client
|
||||||
|
|
||||||
# For RabbitMQ
|
|
||||||
from kombu.connection import BrokerConnection
|
|
||||||
from kombu.messaging import Exchange, Queue, Consumer, Producer
|
|
||||||
|
|
||||||
# loading config file
|
# loading config file
|
||||||
try:
|
try:
|
||||||
config = ConfigObj('/etc/airtime/pypo.cfg')
|
config = ConfigObj('/etc/airtime/pypo.cfg')
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
self.logger.error('Error loading config file: %s', e)
|
print ('Error loading config file: %s', e)
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
def getDateTimeObj(time):
|
def getDateTimeObj(time):
|
||||||
|
@ -89,7 +81,7 @@ class ShowRecorder(Thread):
|
||||||
|
|
||||||
#blocks at the following line until the child process
|
#blocks at the following line until the child process
|
||||||
#quits
|
#quits
|
||||||
code = self.p.wait()
|
self.p.wait()
|
||||||
|
|
||||||
self.logger.info("finishing record, return code %s", self.p.returncode)
|
self.logger.info("finishing record, return code %s", self.p.returncode)
|
||||||
code = self.p.returncode
|
code = self.p.returncode
|
||||||
|
@ -274,9 +266,7 @@ class Recorder(Thread):
|
||||||
self.logger.error(e)
|
self.logger.error(e)
|
||||||
|
|
||||||
self.logger.info("Bootstrap complete: got initial copy of the schedule")
|
self.logger.info("Bootstrap complete: got initial copy of the schedule")
|
||||||
|
|
||||||
recording = False
|
|
||||||
|
|
||||||
self.loops = 0
|
self.loops = 0
|
||||||
heartbeat_period = math.floor(30/PUSH_INTERVAL)
|
heartbeat_period = math.floor(30/PUSH_INTERVAL)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue