Skip to content
Snippets Groups Projects
Commit 4791a65c authored by David Trattnig's avatar David Trattnig
Browse files

Cleanup. #44

parent b540ac73
No related branches found
No related tags found
No related merge requests found
......@@ -50,8 +50,8 @@ class Padavan:
elif self.args.mixer_status:
self.mixer_status()
elif self.args.get_act_programme:
self.get_act_programme()
# elif self.args.get_act_programme:
# self.get_act_programme()
elif self.args.get_status:
self.get_status()
......@@ -142,15 +142,15 @@ class Padavan:
json_reply = self.send_and_wait_redis("aura", "fetch_new_programme", RedisChannel.FNP_REPLY)
if json_reply != "":
actprogramme = json.loads(json_reply)
self.print_programme(actprogramme)
# self.print_programme(actprogramme)
else:
print("No programme fetched")
# ------------------------------------------------------------------------------------------ #
def get_act_programme(self):
json_reply = self.send_and_wait_redis("aura", "get_act_programme", RedisChannel.GAP_REPLY)
actprogramme = json.loads(json_reply)
self.print_programme(actprogramme)
# def get_act_programme(self):
# json_reply = self.send_and_wait_redis("aura", "get_act_programme", RedisChannel.GAP_REPLY)
# actprogramme = json.loads(json_reply)
# self.print_programme(actprogramme)
def get_status(self):
......@@ -169,16 +169,16 @@ class Padavan:
self.print_connection_status(connection_status)
# ------------------------------------------------------------------------------------------ #
def print_programme(self, programme):
cnt = 1
for show in programme:
for entry in show["playlist"]:
self.stringreply += str(cnt) + \
" --- schedule id #" + str(show["schedule_id"]) + "." + str(entry["entry_num"]) + \
" - show: " + show["show_name"] + \
" - starts @ " + entry["entry_start"] + \
" - plays " + str(entry["source"]) + "\n"
cnt = cnt + 1
# def print_programme(self, programme):
# cnt = 1
# for show in programme:
# for entry in show["playlist"]:
# self.stringreply += str(cnt) + \
# " --- schedule id #" + str(show["schedule_id"]) + "." + str(entry["entry_num"]) + \
# " - show: " + show["show_name"] + \
# " - starts @ " + entry["entry_start"] + \
# " - plays " + str(entry["source"]) + "\n"
# cnt = cnt + 1
# ------------------------------------------------------------------------------------------ #
def print_connection_status(self, connection_status):
......
......@@ -140,8 +140,8 @@ class ServerRedisAdapter(threading.Thread, RedisMessenger):
# ------------------------------------------------------------------------------------------ #
def work(self, item):
if item["data"] == "fetch_new_programme":
#self.execute(RedisChannel.FNP_REPLY.value, self.scheduler.fetch_new_programme)
self.execute(RedisChannel.FNP_REPLY.value, self.scheduler.get_act_programme_as_string)
self.execute(RedisChannel.FNP_REPLY.value, self.scheduler.fetch_new_programme)
# self.execute(RedisChannel.FNP_REPLY.value, self.scheduler.get_act_programme_as_string)
elif item["data"] == "shutdown":
self.terminate()
......@@ -149,8 +149,8 @@ class ServerRedisAdapter(threading.Thread, RedisMessenger):
elif item["data"] == "init_player":
self.execute(RedisChannel.IP_REPLY.value, self.engine.init_player)
elif item["data"] == "get_act_programme":
self.execute(RedisChannel.GAP_REPLY.value, self.scheduler.get_act_programme_as_string)
# elif item["data"] == "get_act_programme":
# self.execute(RedisChannel.GAP_REPLY.value, self.scheduler.get_act_programme_as_string)
elif item["data"] == "get_status":
def get_status_string():
......
......@@ -26,7 +26,7 @@ class RedisChannel(Enum):
DPE_REPLY = "delete_playlist_entry_reply"
FNP_REPLY = "fetch_new_programme_reply"
GAP_REPLY = "get_act_programme_reply"
# GAP_REPLY = "get_act_programme_reply"
GS_REPLY = "get_status_reply"
GCS_REPLY = "get_connection_status_reply"
GNF_REPLY = "get_next_file_reply"
......
......@@ -21,9 +21,6 @@
import logging
import threading
import time
import json
import decimal
import traceback
import sqlalchemy
from enum import Enum
......@@ -41,19 +38,6 @@ from modules.scheduling.calendar import AuraCalendarService
from modules.scheduling.fallback_manager import FallbackManager
# FIXME this is probably not needed?
def alchemyencoder(obj):
"""JSON encoder function for SQLAlchemy special classes."""
if isinstance(obj, datetime.date):
return obj.isoformat()
elif isinstance(obj, decimal.Decimal):
return float(obj)
elif isinstance(obj, sqlalchemy.orm.state.InstanceState):
return ""
elif isinstance(obj, Schedule):
return json.dumps([obj._asdict()], default=alchemyencoder)
else:
return str(obj)
class EntryQueueState(Enum):
......@@ -243,10 +227,6 @@ class AuraScheduler(threading.Thread):
self.engine.player.preroll(active_entry)
self.engine.player.play(active_entry, TransitionType.FADE)
# Check if this is the last item of the schedule
# if active_entry.end_unix > active_entry.playlist.schedule.end_unix:
# self.queue_end_of_schedule(active_schedule, True)
# Fast-forward to the scheduled position
if seconds_to_seek > 0:
# Without plenty of timeout (10s) the seek doesn't work
......@@ -267,8 +247,6 @@ class AuraScheduler(threading.Thread):
self.engine.player.preroll(active_entry)
self.engine.player.play(active_entry, TransitionType.FADE)
# self.queue_end_of_schedule(active_schedule, True)
else:
self.logger.critical("Unknown Entry Type: %s" % active_entry)
......@@ -374,33 +352,6 @@ class AuraScheduler(threading.Thread):
return None
# FIXME Review relevance.
def get_act_programme_as_string(self):
"""
Fetches the latest programme and returns it as `String`.
Also used by `ServerRedisAdapter`.
Return:
(String): Programme
Raises:
(Exception): In case the programme cannot be converted to String
"""
programme_as_string = ""
if self.programme is None or len(self.programme) == 0:
self.fetch_new_programme()
try:
programme_as_string = json.dumps([p._asdict() for p in self.programme], default=alchemyencoder)
# FIXME Change to more specific exception
except Exception as e:
self.logger.error("Cannot transform programme into JSON String. Reason: " + str(e))
traceback.print_exc()
return programme_as_string
def print_timer_queue(self):
"""
......@@ -602,19 +553,6 @@ class AuraScheduler(threading.Thread):
#
# def engine_time(self):
# """
# Liquidsoap is slow in executing commands, therefore it's needed to schedule
# actions by (n) seconds in advance, as defined in the configuration file by
# the property `lqs_delay_offset`.
# Returns:
# (Integer): the Unix epoch timestamp including the offset
# """
# time_offset = int(self.config.lqs_delay_offset)
# return SU.timestamp() + time_offset
def filter_scheduling_window(self, schedules):
"""
......@@ -1095,31 +1033,7 @@ class AuraScheduler(threading.Thread):
self.logger.info("Shutting down scheduler ...")
# ------------------------------------------------------------------------------------------ #
# class SetNextFile(threading.Thread):
# fallbackname = None
# show = None
# def __init__(self, fallbackname, show):
# threading.Thread.__init__(self)
# self.fallbackname = fallbackname
# self.show = show
# def run(self):
# if self.fallbackname == "show":
# self.detect_next_file_for(self.show.showfallback)
# elif self.fallbackname == "timeslow":
# self.detect_next_file_for(self.show.timeslotfallback)
# elif self.fallbackname == "station":
# self.detect_next_file_for(self.show.stationfallback)
# def detect_next_file_for(self, playlist):
# return ""
# #if playlist.startswith("pool"):
# # self.find_next_file_in_pool(playlist)
# #def find_next_file_in_pool(self, pool):
# # return ""
# ------------------------------------------------------------------------------------------ #
class CallFunctionTimer(threading.Timer):
......
......@@ -22,75 +22,41 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import json
import logging
import sqlalchemy
import decimal
import datetime
from modules.core.engine import Engine
from modules.base.config import AuraConfig
from modules.base.models import Schedule, ScheduleEntry
from modules.scheduling.scheduler import AuraScheduler, AuraCalendarService
def alchemyencoder(obj):
"""JSON encoder function for SQLAlchemy special classes."""
if isinstance(obj, datetime.date):
return obj.isoformat()
elif isinstance(obj, decimal.Decimal):
return float(obj)
elif isinstance(obj, sqlalchemy.orm.state.InstanceState):
return ""
#elif isinstance(obj, Schedule):
# return json.dumps([obj._asdict()], default=alchemyencoder)
else:
return str(obj)
# programme_as_string = json.dumps([se[0]._asdict()], default=alchemyencoder)
# print(programme_as_string)
from modules.base.models import PlaylistEntry
from modules.core.engine import Engine
from modules.scheduling.scheduler import AuraScheduler
def select_current_programme():
# select_programme()
config = AuraConfig()
config.read_config()
engine = Engine(config.config)
sched = AuraScheduler(config.config)
engine = Engine(config)
sched = AuraScheduler(config, engine, None)
engine.scheduler = sched
sched.engine = engine
programme = sched.load_programme_from_db()
sched.load_programme_from_db()
for show in programme:
print(show)
def fadeout(lsc):
entry = ScheduleEntry.select_programme()
lsc.fade_out(entry, 2)
def fadein(lsc):
entry = ScheduleEntry.select_programme()
lsc.fade_in(entry, 1)
def fetch_new_programme():
config = AuraConfig()
config.read_config()
acs = AuraCalendarService(config.config)
queue = acs.get_queue()
# start fetching thread
acs.start()
# wait for the end
response = queue.get()
# # ## ## ## ## ## # #
# # ENTRY FUNCTION # #
# # ## ## ## ## ## # #
def main():
fetch_new_programme()
True
# # ## ## ## ## ## ## # #
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment