parent
7e7f8147da
commit
a6eb74b1fd
|
@ -10,6 +10,7 @@
|
|||
### END INIT INFO
|
||||
|
||||
USERID=pypo
|
||||
ROOTUSERID=root
|
||||
GROUPID=pypo
|
||||
NAME=Airtime\ Playout
|
||||
|
||||
|
@ -47,7 +48,7 @@ start () {
|
|||
chown pypo:pypo /etc/airtime
|
||||
chown pypo:pypo /etc/airtime/liquidsoap.cfg
|
||||
|
||||
start-stop-daemon --start --background --quiet --make-pidfile --pidfile $PIDFILE0 --startas $DAEMON0
|
||||
start-stop-daemon --start --background --quiet --chuid $ROOTUSERID:$ROOTUSERID --make-pidfile --pidfile $PIDFILE0 --startas $DAEMON0
|
||||
monit monitor airtime-playout >/dev/null 2>&1
|
||||
|
||||
liquidsoap_start
|
||||
|
@ -80,7 +81,7 @@ monit_restart() {
|
|||
}
|
||||
|
||||
start_no_monit() {
|
||||
start-stop-daemon --start --background --quiet --chuid $USERID:$GROUPID --make-pidfile --pidfile $PIDFILE0 --startas $DAEMON0
|
||||
start-stop-daemon --start --background --quiet --chuid $ROOTUSERID:$ROOTUSERID --make-pidfile --pidfile $PIDFILE0 --startas $DAEMON0
|
||||
liquidsoap_start
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ import logging.config
|
|||
import shutil
|
||||
import os
|
||||
import sys
|
||||
import stat
|
||||
|
||||
from std_err_override import LogWriter
|
||||
|
||||
|
@ -33,21 +34,21 @@ except Exception, e:
|
|||
|
||||
|
||||
class PypoFile(Thread):
|
||||
|
||||
|
||||
def __init__(self, schedule_queue):
|
||||
Thread.__init__(self)
|
||||
self.logger = logging.getLogger()
|
||||
self.media_queue = schedule_queue
|
||||
self.media = None
|
||||
self.cache_dir = os.path.join(config["cache_dir"], "scheduler")
|
||||
|
||||
|
||||
def copy_file(self, media_item):
|
||||
"""
|
||||
Copy media_item from local library directory to local cache directory.
|
||||
"""
|
||||
"""
|
||||
src = media_item['uri']
|
||||
dst = media_item['dst']
|
||||
|
||||
|
||||
try:
|
||||
src_size = os.path.getsize(src)
|
||||
except Exception, e:
|
||||
|
@ -59,14 +60,14 @@ class PypoFile(Thread):
|
|||
dst_size = os.path.getsize(dst)
|
||||
except Exception, e:
|
||||
dst_exists = False
|
||||
|
||||
|
||||
do_copy = False
|
||||
if dst_exists:
|
||||
if src_size != dst_size:
|
||||
do_copy = True
|
||||
else:
|
||||
do_copy = True
|
||||
|
||||
|
||||
if do_copy:
|
||||
self.logger.debug("copying from %s to local cache %s" % (src, dst))
|
||||
try:
|
||||
|
@ -74,9 +75,13 @@ class PypoFile(Thread):
|
|||
copy will overwrite dst if it already exists
|
||||
"""
|
||||
shutil.copy(src, dst)
|
||||
except:
|
||||
|
||||
#make file world readable
|
||||
os.chmod(dst, stat.S_IRUSR | stat.S_IRGRP | stat.S_IXOTH)
|
||||
except Exception, e:
|
||||
self.logger.error("Could not copy from %s to %s" % (src, dst))
|
||||
|
||||
self.logger.error(e)
|
||||
|
||||
def get_highest_priority_media_item(self, schedule):
|
||||
"""
|
||||
Get highest priority media_item in the queue. Currently the highest
|
||||
|
@ -84,17 +89,17 @@ class PypoFile(Thread):
|
|||
"""
|
||||
if schedule is None or len(schedule) == 0:
|
||||
return None
|
||||
|
||||
|
||||
sorted_keys = sorted(schedule.keys())
|
||||
|
||||
|
||||
if len(sorted_keys) == 0:
|
||||
return None
|
||||
|
||||
|
||||
highest_priority = sorted_keys[0]
|
||||
media_item = schedule[highest_priority]
|
||||
|
||||
|
||||
self.logger.debug("Highest priority item: %s" % highest_priority)
|
||||
|
||||
|
||||
"""
|
||||
Remove this media_item from the dictionary. On the next iteration
|
||||
(from the main function) we won't consider it for prioritization
|
||||
|
@ -103,11 +108,11 @@ class PypoFile(Thread):
|
|||
again. In this situation, the worst possible case is that we try to
|
||||
copy the file again and realize we already have it (thus aborting the copy).
|
||||
"""
|
||||
del schedule[highest_priority]
|
||||
|
||||
del schedule[highest_priority]
|
||||
|
||||
return media_item
|
||||
|
||||
|
||||
|
||||
|
||||
def main(self):
|
||||
while True:
|
||||
try:
|
||||
|
@ -128,7 +133,7 @@ class PypoFile(Thread):
|
|||
self.media = self.media_queue.get_nowait()
|
||||
except Empty, e:
|
||||
pass
|
||||
|
||||
|
||||
|
||||
media_item = self.get_highest_priority_media_item(self.media)
|
||||
if media_item is not None:
|
||||
|
@ -139,7 +144,7 @@ class PypoFile(Thread):
|
|||
self.logger.error(str(e))
|
||||
self.logger.error(top)
|
||||
raise
|
||||
|
||||
|
||||
def run(self):
|
||||
"""
|
||||
Entry point of the thread
|
||||
|
|
Loading…
Reference in New Issue