Commit 955ef8cf authored by David Trattnig's avatar David Trattnig
Browse files

Linting, cleanup and fixes.

parent 8d6f8244
......@@ -54,8 +54,6 @@ def get_database_uri():
db_pass = config.get("db_pass")
db_host = config.get("db_host")
db_charset = config.get("db_charset", "utf8")
#### return created database uri ####
return "mysql://" + db_user + ":" + db_pass + "@" + db_host + "/" + db_name + "?charset=" + db_charset
......@@ -82,11 +80,8 @@ class Aura:
# ------------------------------------------------------------------------------------------ #
def __init__(self):
# set config
self.config = config
# init logger
AuraLogger(self.config)
# use logger
self.logger = logging.getLogger("AuraEngine")
def startup(self):
......@@ -98,7 +93,6 @@ class Aura:
AuraScheduler(self.config) # handles recreate and exits program
# self.controller = AuraController(self.config)
# create scheduler and ls_communicator
self.liquidsoapcommunicator = LiquidSoapCommunicator(self.config)
self.scheduler = AuraScheduler(self.config)
......@@ -112,21 +106,20 @@ class Aura:
self.messenger.scheduler = self.scheduler
self.messenger.liquidsoapcommunicator = self.liquidsoapcommunicator
# FIXME Check if it's working / needed.
#self.diskspace_watcher = DiskSpaceWatcher(self.config, self.logger, self.liquidsoapcommunicator)
#self.diskspace_watcher.start()
# and finally wait for redis message
self.join_comm()
# and finally wait for redis message / start listener thread
self.messenger.start()
# start the web service
self.start_web_service()
def join_comm(self):
# start listener thread
self.messenger.start()
def start_web_service(self):
# FIXME Test current state of Web Services
try:
self.logger.info("Listening on Port 5000 for API or Webcalls")
# Routes(self.scheduler, self.liquidsoapcommunicator, self.messenger, self.config)
......@@ -142,6 +135,7 @@ class Aura:
def main():
aura = Aura()
# FIXME MAKE THE STARTTIME OF A SCHEDULE TO ITS PK
aura.logger.critical("MAKE THE STARTTIME OF A SCHEDULE TO ITS PK")
......@@ -149,7 +143,7 @@ def main():
if "--use-test-data" in sys.argv:
aura.config.set("use_test_data", True)
if "--recreate-database" in sys.argv:
aura.config.set("recreate_db", True);
aura.config.set("recreate_db", True)
aura.startup()
......
......@@ -223,10 +223,6 @@ class ServerRedisAdapter(threading.Thread, RedisMessenger):
"""
if self.shutdown_event.is_set():
return
try:
del self.auracontroller
except:
pass
self.shutdown_event.set()
result = 'failed'
try:
......
......@@ -105,21 +105,23 @@ class AuraCalendarService(threading.Thread):
return self.queue
# ------------------------------------------------------------------------------------------ #
def get_uri(self):
if not self.playlistdir:
return False
if not self.datefrom:
return False
if not self.__calc_date_to__():
return
hostname = self.get("servername");
port = self.get("serviceport");
date_from = self.datefrom[0:16] + ":00";
date_to = self.dateto[0:16] + ":00";
uri = "http://" + hostname + ":" + port + "/playlist/" + date_from + "/" + date_to
return uri
# FIXME is get_uri() needed?
# def get_uri(self):
# if not self.playlistdir:
# return False
# if not self.datefrom:
# return False
# if not self.__calc_date_to__():
# return
# hostname = self.get("servername")
# port = self.get("serviceport")
# date_from = self.datefrom[0:16] + ":00"
# date_to = self.dateto[0:16] + ":00"
# uri = "http://" + hostname + ":" + port + "/playlist/" + date_from + "/" + date_to
# return uri
# ------------------------------------------------------------------------------------------ #
def run(self):
......@@ -161,6 +163,7 @@ class AuraCalendarService(threading.Thread):
self.queue.put(ret_schedule)
except Exception as e:
# release the mutex
self.logger.warning("Fetching aborted due to: %s" % str(e))
self.queue.put("fetching_aborted " + str(e))
# terminate the thread
......@@ -246,7 +249,6 @@ class AuraCalendarService(threading.Thread):
playlistentry_db.uri = entry["uri"]
playlistentry_db.filename = entry["filename"]
playlistentry_db.duration = entry["file"]["duration"]
playlistentry_db.store(havetoadd, True)
self.store_playlist_entry_metadata(playlistentry_db, entry["file"]["metadata"])
......@@ -261,12 +263,16 @@ class AuraCalendarService(threading.Thread):
havetoadd = True
playlistentrymetadata_db.artificial_entry_id = playlistentry_db.artificial_id
playlistentrymetadata_db.artist = metadata["artist"]
if "artist" not in metadata:
self.logger.warning("Artist not found in metadata for track '%s'. Setting to 'N/a'" % playlistentry_db.filename)
playlistentrymetadata_db.artist = "N/a"
else:
playlistentrymetadata_db.artist = metadata["artist"]
playlistentrymetadata_db.title = metadata["title"]
if "album" in metadata:
playlistentrymetadata_db.album = metadata["album"]
playlistentrymetadata_db.store(havetoadd, True);
playlistentrymetadata_db.store(havetoadd, True)
# ------------------------------------------------------------------------------------------ #
def store_playlist_entry(self, schedule_db, playlist, entry, lastentry, entrynum, fallbackplaylist_type=0):
......@@ -275,7 +281,8 @@ class AuraCalendarService(threading.Thread):
if not schedule_entry_db:
self.logger.debug("no scheduleentry with id " + str(playlist["id"]) + " and pos " + str(entrynum) + " in database => creating a new one")
schedule_entry_db = ScheduleEntry()
# FIXME Needed? No active class declaration
#schedule_entry_db = ScheduleEntry()
havetoadd = True
......@@ -325,9 +332,9 @@ class AuraCalendarService(threading.Thread):
@rtype: int
@return: Zeit in Sekunden
"""
sec1 = int(datetime.strptime(start[0:16].replace(" ","T"),"%Y-%m-%dT%H:%M").strftime("%s"));
sec2 = int(datetime.strptime(end[0:16].replace(" ","T"),"%Y-%m-%dT%H:%M").strftime("%s"));
return (sec2 - sec1);
sec1 = int(datetime.strptime(start[0:16].replace(" ","T"),"%Y-%m-%dT%H:%M").strftime("%s"))
sec2 = int(datetime.strptime(end[0:16].replace(" ","T"),"%Y-%m-%dT%H:%M").strftime("%s"))
return (sec2 - sec1)
# ------------------------------------------------------------------------------------------ #
def get_length(self, entry):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment