Last few pep issues.

This commit is contained in:
Matthew Stratford 2021-04-08 22:32:16 +01:00
parent 612478b777
commit 023cafad90
7 changed files with 29 additions and 26 deletions

View file

@ -9,6 +9,7 @@ from helpers.logging_manager import LoggingManager
from helpers.state_manager import StateManager
from controllers.controller import Controller
class MattchBox(Controller):
ser: Optional[serial.Serial]
port: Optional[str]
@ -86,7 +87,7 @@ class MattchBox(Controller):
self.sendToPlayer(int(line / 2), "PLAY")
elif line in [2, 4, 6]:
self.sendToPlayer(int(line / 2) - 1, "STOP")
except Exception :
except Exception:
continue
finally:
time.sleep(0.01)

View file

@ -19,7 +19,7 @@ class LoggingManager:
try:
# Try creating the directory.
os.mkdir(logpath)
except Exception :
except Exception:
print("Failed to create log directory.")
return
@ -30,7 +30,7 @@ class LoggingManager:
# Try creating the file.
file = open(filename, "x")
file.close()
except Exception :
except Exception:
print("Failed to create log file.")
return

View file

@ -28,7 +28,7 @@ def resolve_local_file_path(relative_path: str):
try:
# PyInstaller creates a temp folder and stores path in _MEIPASS
base_path: str = sys._MEIPASS
except Exception :
except Exception:
base_path = os.path.abspath(".")
return os.path.join(base_path, relative_path)

View file

@ -39,7 +39,7 @@ class StateManager:
try:
# Try creating the file.
open(self.filepath, "x")
except Exception :
except Exception:
self._log("Failed to create state file.", CRITICAL)
return
@ -67,7 +67,7 @@ class StateManager:
# Now feed the loaded state into the initialised state manager.
self.state = file_state
except Exception :
except Exception:
self._logException(
"Failed to parse state JSON. Resetting to default state."
)
@ -116,7 +116,7 @@ class StateManager:
]
try:
state_json = json.dumps(state_to_json, indent=2, sort_keys=True)
except Exception :
except Exception:
self._logException("Failed to dump JSON state.")
else:
with open(self.filepath, "w") as file:

View file

@ -42,6 +42,7 @@ from plan import PlanItem
# TODO ENUM
VALID_MESSAGE_SOURCES = ["WEBSOCKET", "UI", "CONTROLLER", "TEST", "ALL"]
class Player:
out_q: multiprocessing.Queue
last_msg: str
@ -81,7 +82,7 @@ class Player:
def isInit(self):
try:
mixer.music.get_busy()
except Exception :
except Exception:
return False
return True
@ -110,10 +111,10 @@ class Player:
position: float = self.state.state["pos"]
mixer.music.set_volume(0)
mixer.music.play(0)
except Exception :
except Exception:
try:
mixer.music.set_volume(1)
except Exception :
except Exception:
self.logger.log.exception(
"Failed to reset volume after attempting loaded test."
)
@ -148,7 +149,7 @@ class Player:
try:
mixer.music.play(0, pos)
self.state.update("pos_offset", pos)
except Exception :
except Exception:
self.logger.log.exception("Failed to play at pos: " + str(pos))
return False
self.state.update("paused", False)
@ -159,7 +160,7 @@ class Player:
def pause(self):
try:
mixer.music.pause()
except Exception :
except Exception:
self.logger.log.exception("Failed to pause.")
return False
@ -172,7 +173,7 @@ class Player:
position: float = self.state.state["pos_true"]
try:
self.play(position)
except Exception :
except Exception:
self.logger.log.exception(
"Failed to unpause from pos: " + str(position)
)
@ -186,7 +187,7 @@ class Player:
# if self.isPlaying or self.isPaused:
try:
mixer.music.stop()
except Exception :
except Exception:
self.logger.log.exception("Failed to stop playing.")
return False
self.state.update("pos", 0)
@ -203,7 +204,7 @@ class Player:
if self.isPlaying:
try:
self.play(pos)
except Exception :
except Exception:
self.logger.log.exception("Failed to seek to pos: " + str(pos))
return False
return True
@ -330,7 +331,7 @@ class Player:
self.logger.log.info("Loading file: " +
str(loaded_item.filename))
mixer.music.load(loaded_item.filename)
except Exception :
except Exception:
# We couldn't load that file.
self.logger.log.exception(
"Couldn't load file: " + str(loaded_item.filename)
@ -346,7 +347,7 @@ class Player:
"length", mixer.Sound(
loaded_item.filename).get_length() / 1000
)
except Exception :
except Exception:
self.logger.log.exception(
"Failed to update the length of item.")
return False
@ -362,7 +363,7 @@ class Player:
mixer.music.unload()
self.state.update("paused", False)
self.state.update("loaded_item", None)
except Exception :
except Exception:
self.logger.log.exception("Failed to unload channel.")
return False
return not self.isLoaded
@ -372,7 +373,7 @@ class Player:
mixer.quit()
self.state.update("paused", False)
self.logger.log.info("Quit mixer.")
except Exception :
except Exception:
self.logger.log.exception("Failed to quit mixer.")
def output(self, name: Optional[str] = None):
@ -387,7 +388,7 @@ class Player:
mixer.init(44100, -16, 2, 1024, devicename=name)
else:
mixer.init(44100, -16, 2, 1024)
except Exception :
except Exception:
self.logger.log.exception(
"Failed to init mixer with device name: " + str(name)
)

View file

@ -5,6 +5,7 @@ from os import _exit
from helpers.logging_manager import LoggingManager
class PlayerHandler:
logger: LoggingManager
@ -31,7 +32,7 @@ class PlayerHandler:
ui_to_q[channel].put(message)
if source in ["ALL", "CONTROLLER"]:
controller_to_q[channel].put(message)
except Exception :
except Exception:
pass
sleep(0.02)

View file

@ -11,6 +11,7 @@ from os import _exit
from helpers.logging_manager import LoggingManager
from websockets.server import Serve
class WebsocketServer:
threads = Future
@ -39,7 +40,7 @@ class WebsocketServer:
try:
asyncio.get_event_loop().run_forever()
except Exception :
except Exception:
# Sever died somehow, just quit out.
self.quit()
@ -52,7 +53,7 @@ class WebsocketServer:
print("Deleting websocket server")
self.quit()
async def websocket_handler(self, websocket, _):
async def websocket_handler(self, websocket, path):
self.baps_clients.add(websocket)
await websocket.send(
json.dumps({"message": "Hello", "serverName": self.server_name})
@ -84,7 +85,6 @@ class WebsocketServer:
self.logger.log.error(
"Client Disconncted {}, {}".format(websocket, e))
# TODO: Proper Logging
except Exception as e:
self.logger.log.exception(
"Exception handling messages from Websocket.\n{}".format(e)
@ -195,12 +195,12 @@ class WebsocketServer:
try:
message = message.split("OKAY:")[1]
message = json.loads(message)
except Exception :
except Exception:
continue # TODO more logging
elif command == "POS":
try:
message = message.split(":", 2)[2]
except Exception :
except Exception:
continue
elif command == "QUIT":
self.quit()