-fix errors pointed out by pydev code completion

This commit is contained in:
Martin Konecny 2012-03-17 14:16:11 -04:00
parent db4c916d9a
commit 7a7eb02de5
6 changed files with 15 additions and 80 deletions

View file

@ -5,7 +5,6 @@ Python part of radio playout (pypo)
import time
from optparse import *
import sys
import os
import signal
import logging
import logging.config

View file

@ -1,24 +1,13 @@
import os
import sys
import time
import calendar
import logging
import logging.config
import shutil
import random
import string
import json
import telnetlib
import math
import copy
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
@ -264,19 +253,19 @@ class PypoFetch(Thread):
fh.write("# THIS FILE IS AUTO GENERATED. DO NOT CHANGE!! #\n")
fh.write("################################################\n")
for k, d in setting:
buffer = d[u'keyname'] + " = "
buffer_str = d[u'keyname'] + " = "
if(d[u'type'] == 'string'):
temp = d[u'value']
if(temp == ""):
temp = ""
buffer += "\"" + temp + "\""
buffer_str += "\"" + temp + "\""
else:
temp = d[u'value']
if(temp == ""):
temp = "0"
buffer += temp
buffer += "\n"
fh.write(api_client.encode_to(buffer))
buffer_str += temp
buffer_str += "\n"
fh.write(api_client.encode_to(buffer_str))
fh.write("log_file = \"/var/log/airtime/pypo-liquidsoap/<script>.log\"\n");
fh.close()
# restarting pypo.

View file

@ -6,7 +6,7 @@ import logging
import logging.config
import shutil
import os
import time
import sys
# configure logging
logging.config.fileConfig("logging.cfg")
@ -21,7 +21,7 @@ try:
except Exception, e:
logger = logging.getLogger()
logger.error('Error loading config file: %s', e)
sys.exit()
sys.exit(1)
class PypoFile(Thread):

View file

@ -6,8 +6,7 @@ from threading import Thread
import time
# For RabbitMQ
from kombu.connection import BrokerConnection
from kombu.messaging import Exchange, Queue, Consumer, Producer
from kombu.exceptions import MessageStateError
from kombu.messaging import Exchange, Queue
from kombu.simple import SimpleQueue
import json

View file

@ -1,27 +1,16 @@
from datetime import datetime
from datetime import timedelta
import os
import sys
import time
import logging
import logging.config
import logging.handlers
import pickle
import telnetlib
import calendar
import json
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 Lock
from api_clients import api_client
from configobj import ConfigObj
@ -69,7 +58,6 @@ class PypoPush(Thread):
liquidsoap_queue_approx = self.get_queue_items_from_liquidsoap()
timenow = time.time()
# get a new schedule from pypo-fetch
if not self.queue.empty():
# make sure we get the latest schedule
@ -82,22 +70,13 @@ class PypoPush(Thread):
media = self.media
self.logger.debug(liquidsoap_queue_approx)
if len(liquidsoap_queue_approx) < MAX_LIQUIDSOAP_QUEUE_LENGTH:
if media:
tnow = datetime.utcnow()
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():
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
get a new schedule, the key becomes available again.
"""
#TODO
del media[key]
def date_interval_to_seconds(self, interval):
@ -172,24 +152,7 @@ class PypoPush(Thread):
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):
"""
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
queue.
"""
#TODO: Keys should already be sorted. Verify this.
sorted_keys = sorted(media.keys())
if len(liquidsoap_queue_approx) == 0:
"""
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
about which show is playing.
"""
try:
self.telnet_lock.acquire()
tn = telnetlib.Telnet(LS_HOST, LS_PORT)

View file

@ -1,4 +1,3 @@
import urllib
import logging
import logging.config
import json
@ -6,8 +5,6 @@ import time
import datetime
import os
import sys
import shutil
import socket
import pytz
import signal
import math
@ -16,7 +13,6 @@ from configobj import ConfigObj
from poster.encode import multipart_encode
from poster.streaminghttp import register_openers
import urllib2
from subprocess import Popen
from threading import Thread
@ -25,15 +21,11 @@ import mutagen
from api_clients import api_client
# For RabbitMQ
from kombu.connection import BrokerConnection
from kombu.messaging import Exchange, Queue, Consumer, Producer
# loading config file
try:
config = ConfigObj('/etc/airtime/pypo.cfg')
except Exception, e:
self.logger.error('Error loading config file: %s', e)
print ('Error loading config file: %s', e)
sys.exit()
def getDateTimeObj(time):
@ -89,7 +81,7 @@ class ShowRecorder(Thread):
#blocks at the following line until the child process
#quits
code = self.p.wait()
self.p.wait()
self.logger.info("finishing record, return code %s", self.p.returncode)
code = self.p.returncode
@ -274,9 +266,7 @@ class Recorder(Thread):
self.logger.error(e)
self.logger.info("Bootstrap complete: got initial copy of the schedule")
recording = False
self.loops = 0
heartbeat_period = math.floor(30/PUSH_INTERVAL)