Last few pep issues.
This commit is contained in:
parent
612478b777
commit
023cafad90
7 changed files with 29 additions and 26 deletions
|
@ -9,6 +9,7 @@ from helpers.logging_manager import LoggingManager
|
||||||
from helpers.state_manager import StateManager
|
from helpers.state_manager import StateManager
|
||||||
from controllers.controller import Controller
|
from controllers.controller import Controller
|
||||||
|
|
||||||
|
|
||||||
class MattchBox(Controller):
|
class MattchBox(Controller):
|
||||||
ser: Optional[serial.Serial]
|
ser: Optional[serial.Serial]
|
||||||
port: Optional[str]
|
port: Optional[str]
|
||||||
|
@ -86,7 +87,7 @@ class MattchBox(Controller):
|
||||||
self.sendToPlayer(int(line / 2), "PLAY")
|
self.sendToPlayer(int(line / 2), "PLAY")
|
||||||
elif line in [2, 4, 6]:
|
elif line in [2, 4, 6]:
|
||||||
self.sendToPlayer(int(line / 2) - 1, "STOP")
|
self.sendToPlayer(int(line / 2) - 1, "STOP")
|
||||||
except Exception :
|
except Exception:
|
||||||
continue
|
continue
|
||||||
finally:
|
finally:
|
||||||
time.sleep(0.01)
|
time.sleep(0.01)
|
||||||
|
|
|
@ -19,7 +19,7 @@ class LoggingManager:
|
||||||
try:
|
try:
|
||||||
# Try creating the directory.
|
# Try creating the directory.
|
||||||
os.mkdir(logpath)
|
os.mkdir(logpath)
|
||||||
except Exception :
|
except Exception:
|
||||||
print("Failed to create log directory.")
|
print("Failed to create log directory.")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ class LoggingManager:
|
||||||
# Try creating the file.
|
# Try creating the file.
|
||||||
file = open(filename, "x")
|
file = open(filename, "x")
|
||||||
file.close()
|
file.close()
|
||||||
except Exception :
|
except Exception:
|
||||||
print("Failed to create log file.")
|
print("Failed to create log file.")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ def resolve_local_file_path(relative_path: str):
|
||||||
try:
|
try:
|
||||||
# PyInstaller creates a temp folder and stores path in _MEIPASS
|
# PyInstaller creates a temp folder and stores path in _MEIPASS
|
||||||
base_path: str = sys._MEIPASS
|
base_path: str = sys._MEIPASS
|
||||||
except Exception :
|
except Exception:
|
||||||
base_path = os.path.abspath(".")
|
base_path = os.path.abspath(".")
|
||||||
|
|
||||||
return os.path.join(base_path, relative_path)
|
return os.path.join(base_path, relative_path)
|
||||||
|
|
|
@ -39,7 +39,7 @@ class StateManager:
|
||||||
try:
|
try:
|
||||||
# Try creating the file.
|
# Try creating the file.
|
||||||
open(self.filepath, "x")
|
open(self.filepath, "x")
|
||||||
except Exception :
|
except Exception:
|
||||||
self._log("Failed to create state file.", CRITICAL)
|
self._log("Failed to create state file.", CRITICAL)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ class StateManager:
|
||||||
|
|
||||||
# Now feed the loaded state into the initialised state manager.
|
# Now feed the loaded state into the initialised state manager.
|
||||||
self.state = file_state
|
self.state = file_state
|
||||||
except Exception :
|
except Exception:
|
||||||
self._logException(
|
self._logException(
|
||||||
"Failed to parse state JSON. Resetting to default state."
|
"Failed to parse state JSON. Resetting to default state."
|
||||||
)
|
)
|
||||||
|
@ -116,7 +116,7 @@ class StateManager:
|
||||||
]
|
]
|
||||||
try:
|
try:
|
||||||
state_json = json.dumps(state_to_json, indent=2, sort_keys=True)
|
state_json = json.dumps(state_to_json, indent=2, sort_keys=True)
|
||||||
except Exception :
|
except Exception:
|
||||||
self._logException("Failed to dump JSON state.")
|
self._logException("Failed to dump JSON state.")
|
||||||
else:
|
else:
|
||||||
with open(self.filepath, "w") as file:
|
with open(self.filepath, "w") as file:
|
||||||
|
|
27
player.py
27
player.py
|
@ -42,6 +42,7 @@ from plan import PlanItem
|
||||||
# TODO ENUM
|
# TODO ENUM
|
||||||
VALID_MESSAGE_SOURCES = ["WEBSOCKET", "UI", "CONTROLLER", "TEST", "ALL"]
|
VALID_MESSAGE_SOURCES = ["WEBSOCKET", "UI", "CONTROLLER", "TEST", "ALL"]
|
||||||
|
|
||||||
|
|
||||||
class Player:
|
class Player:
|
||||||
out_q: multiprocessing.Queue
|
out_q: multiprocessing.Queue
|
||||||
last_msg: str
|
last_msg: str
|
||||||
|
@ -81,7 +82,7 @@ class Player:
|
||||||
def isInit(self):
|
def isInit(self):
|
||||||
try:
|
try:
|
||||||
mixer.music.get_busy()
|
mixer.music.get_busy()
|
||||||
except Exception :
|
except Exception:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
@ -110,10 +111,10 @@ class Player:
|
||||||
position: float = self.state.state["pos"]
|
position: float = self.state.state["pos"]
|
||||||
mixer.music.set_volume(0)
|
mixer.music.set_volume(0)
|
||||||
mixer.music.play(0)
|
mixer.music.play(0)
|
||||||
except Exception :
|
except Exception:
|
||||||
try:
|
try:
|
||||||
mixer.music.set_volume(1)
|
mixer.music.set_volume(1)
|
||||||
except Exception :
|
except Exception:
|
||||||
self.logger.log.exception(
|
self.logger.log.exception(
|
||||||
"Failed to reset volume after attempting loaded test."
|
"Failed to reset volume after attempting loaded test."
|
||||||
)
|
)
|
||||||
|
@ -148,7 +149,7 @@ class Player:
|
||||||
try:
|
try:
|
||||||
mixer.music.play(0, pos)
|
mixer.music.play(0, pos)
|
||||||
self.state.update("pos_offset", pos)
|
self.state.update("pos_offset", pos)
|
||||||
except Exception :
|
except Exception:
|
||||||
self.logger.log.exception("Failed to play at pos: " + str(pos))
|
self.logger.log.exception("Failed to play at pos: " + str(pos))
|
||||||
return False
|
return False
|
||||||
self.state.update("paused", False)
|
self.state.update("paused", False)
|
||||||
|
@ -159,7 +160,7 @@ class Player:
|
||||||
def pause(self):
|
def pause(self):
|
||||||
try:
|
try:
|
||||||
mixer.music.pause()
|
mixer.music.pause()
|
||||||
except Exception :
|
except Exception:
|
||||||
self.logger.log.exception("Failed to pause.")
|
self.logger.log.exception("Failed to pause.")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -172,7 +173,7 @@ class Player:
|
||||||
position: float = self.state.state["pos_true"]
|
position: float = self.state.state["pos_true"]
|
||||||
try:
|
try:
|
||||||
self.play(position)
|
self.play(position)
|
||||||
except Exception :
|
except Exception:
|
||||||
self.logger.log.exception(
|
self.logger.log.exception(
|
||||||
"Failed to unpause from pos: " + str(position)
|
"Failed to unpause from pos: " + str(position)
|
||||||
)
|
)
|
||||||
|
@ -186,7 +187,7 @@ class Player:
|
||||||
# if self.isPlaying or self.isPaused:
|
# if self.isPlaying or self.isPaused:
|
||||||
try:
|
try:
|
||||||
mixer.music.stop()
|
mixer.music.stop()
|
||||||
except Exception :
|
except Exception:
|
||||||
self.logger.log.exception("Failed to stop playing.")
|
self.logger.log.exception("Failed to stop playing.")
|
||||||
return False
|
return False
|
||||||
self.state.update("pos", 0)
|
self.state.update("pos", 0)
|
||||||
|
@ -203,7 +204,7 @@ class Player:
|
||||||
if self.isPlaying:
|
if self.isPlaying:
|
||||||
try:
|
try:
|
||||||
self.play(pos)
|
self.play(pos)
|
||||||
except Exception :
|
except Exception:
|
||||||
self.logger.log.exception("Failed to seek to pos: " + str(pos))
|
self.logger.log.exception("Failed to seek to pos: " + str(pos))
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
@ -330,7 +331,7 @@ class Player:
|
||||||
self.logger.log.info("Loading file: " +
|
self.logger.log.info("Loading file: " +
|
||||||
str(loaded_item.filename))
|
str(loaded_item.filename))
|
||||||
mixer.music.load(loaded_item.filename)
|
mixer.music.load(loaded_item.filename)
|
||||||
except Exception :
|
except Exception:
|
||||||
# We couldn't load that file.
|
# We couldn't load that file.
|
||||||
self.logger.log.exception(
|
self.logger.log.exception(
|
||||||
"Couldn't load file: " + str(loaded_item.filename)
|
"Couldn't load file: " + str(loaded_item.filename)
|
||||||
|
@ -346,7 +347,7 @@ class Player:
|
||||||
"length", mixer.Sound(
|
"length", mixer.Sound(
|
||||||
loaded_item.filename).get_length() / 1000
|
loaded_item.filename).get_length() / 1000
|
||||||
)
|
)
|
||||||
except Exception :
|
except Exception:
|
||||||
self.logger.log.exception(
|
self.logger.log.exception(
|
||||||
"Failed to update the length of item.")
|
"Failed to update the length of item.")
|
||||||
return False
|
return False
|
||||||
|
@ -362,7 +363,7 @@ class Player:
|
||||||
mixer.music.unload()
|
mixer.music.unload()
|
||||||
self.state.update("paused", False)
|
self.state.update("paused", False)
|
||||||
self.state.update("loaded_item", None)
|
self.state.update("loaded_item", None)
|
||||||
except Exception :
|
except Exception:
|
||||||
self.logger.log.exception("Failed to unload channel.")
|
self.logger.log.exception("Failed to unload channel.")
|
||||||
return False
|
return False
|
||||||
return not self.isLoaded
|
return not self.isLoaded
|
||||||
|
@ -372,7 +373,7 @@ class Player:
|
||||||
mixer.quit()
|
mixer.quit()
|
||||||
self.state.update("paused", False)
|
self.state.update("paused", False)
|
||||||
self.logger.log.info("Quit mixer.")
|
self.logger.log.info("Quit mixer.")
|
||||||
except Exception :
|
except Exception:
|
||||||
self.logger.log.exception("Failed to quit mixer.")
|
self.logger.log.exception("Failed to quit mixer.")
|
||||||
|
|
||||||
def output(self, name: Optional[str] = None):
|
def output(self, name: Optional[str] = None):
|
||||||
|
@ -387,7 +388,7 @@ class Player:
|
||||||
mixer.init(44100, -16, 2, 1024, devicename=name)
|
mixer.init(44100, -16, 2, 1024, devicename=name)
|
||||||
else:
|
else:
|
||||||
mixer.init(44100, -16, 2, 1024)
|
mixer.init(44100, -16, 2, 1024)
|
||||||
except Exception :
|
except Exception:
|
||||||
self.logger.log.exception(
|
self.logger.log.exception(
|
||||||
"Failed to init mixer with device name: " + str(name)
|
"Failed to init mixer with device name: " + str(name)
|
||||||
)
|
)
|
||||||
|
|
|
@ -5,6 +5,7 @@ from os import _exit
|
||||||
|
|
||||||
from helpers.logging_manager import LoggingManager
|
from helpers.logging_manager import LoggingManager
|
||||||
|
|
||||||
|
|
||||||
class PlayerHandler:
|
class PlayerHandler:
|
||||||
logger: LoggingManager
|
logger: LoggingManager
|
||||||
|
|
||||||
|
@ -31,7 +32,7 @@ class PlayerHandler:
|
||||||
ui_to_q[channel].put(message)
|
ui_to_q[channel].put(message)
|
||||||
if source in ["ALL", "CONTROLLER"]:
|
if source in ["ALL", "CONTROLLER"]:
|
||||||
controller_to_q[channel].put(message)
|
controller_to_q[channel].put(message)
|
||||||
except Exception :
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
sleep(0.02)
|
sleep(0.02)
|
||||||
|
|
|
@ -11,6 +11,7 @@ from os import _exit
|
||||||
from helpers.logging_manager import LoggingManager
|
from helpers.logging_manager import LoggingManager
|
||||||
from websockets.server import Serve
|
from websockets.server import Serve
|
||||||
|
|
||||||
|
|
||||||
class WebsocketServer:
|
class WebsocketServer:
|
||||||
|
|
||||||
threads = Future
|
threads = Future
|
||||||
|
@ -39,7 +40,7 @@ class WebsocketServer:
|
||||||
|
|
||||||
try:
|
try:
|
||||||
asyncio.get_event_loop().run_forever()
|
asyncio.get_event_loop().run_forever()
|
||||||
except Exception :
|
except Exception:
|
||||||
# Sever died somehow, just quit out.
|
# Sever died somehow, just quit out.
|
||||||
self.quit()
|
self.quit()
|
||||||
|
|
||||||
|
@ -52,7 +53,7 @@ class WebsocketServer:
|
||||||
print("Deleting websocket server")
|
print("Deleting websocket server")
|
||||||
self.quit()
|
self.quit()
|
||||||
|
|
||||||
async def websocket_handler(self, websocket, _):
|
async def websocket_handler(self, websocket, path):
|
||||||
self.baps_clients.add(websocket)
|
self.baps_clients.add(websocket)
|
||||||
await websocket.send(
|
await websocket.send(
|
||||||
json.dumps({"message": "Hello", "serverName": self.server_name})
|
json.dumps({"message": "Hello", "serverName": self.server_name})
|
||||||
|
@ -84,7 +85,6 @@ class WebsocketServer:
|
||||||
self.logger.log.error(
|
self.logger.log.error(
|
||||||
"Client Disconncted {}, {}".format(websocket, e))
|
"Client Disconncted {}, {}".format(websocket, e))
|
||||||
|
|
||||||
# TODO: Proper Logging
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.log.exception(
|
self.logger.log.exception(
|
||||||
"Exception handling messages from Websocket.\n{}".format(e)
|
"Exception handling messages from Websocket.\n{}".format(e)
|
||||||
|
@ -195,12 +195,12 @@ class WebsocketServer:
|
||||||
try:
|
try:
|
||||||
message = message.split("OKAY:")[1]
|
message = message.split("OKAY:")[1]
|
||||||
message = json.loads(message)
|
message = json.loads(message)
|
||||||
except Exception :
|
except Exception:
|
||||||
continue # TODO more logging
|
continue # TODO more logging
|
||||||
elif command == "POS":
|
elif command == "POS":
|
||||||
try:
|
try:
|
||||||
message = message.split(":", 2)[2]
|
message = message.split(":", 2)[2]
|
||||||
except Exception :
|
except Exception:
|
||||||
continue
|
continue
|
||||||
elif command == "QUIT":
|
elif command == "QUIT":
|
||||||
self.quit()
|
self.quit()
|
||||||
|
|
Loading…
Reference in a new issue