diff options
author | Eddy Pedroni <epedroni@pm.me> | 2025-07-16 07:10:50 +0200 |
---|---|---|
committer | Eddy Pedroni <epedroni@pm.me> | 2025-07-16 07:10:50 +0200 |
commit | 1dcde6cc9cb322b743e0b0355c697af869c2934a (patch) | |
tree | e4cae31881e3eb129bcdc998dee706f8cda2a590 /solo-tool-project/src/solo_tool | |
parent | 1d42bfe5f7b3c671fc5b50e716c5e8aa68728fb3 (diff) |
Session manager add song, interface, web UI tested
Diffstat (limited to 'solo-tool-project/src/solo_tool')
-rw-r--r-- | solo-tool-project/src/solo_tool/session_manager.py | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/solo-tool-project/src/solo_tool/session_manager.py b/solo-tool-project/src/solo_tool/session_manager.py index 4fae19f..ece67d8 100644 --- a/solo-tool-project/src/solo_tool/session_manager.py +++ b/solo-tool-project/src/solo_tool/session_manager.py @@ -1,9 +1,28 @@ +from typing import BinaryIO, Protocol +from abc import abstractmethod from glob import glob import json from pathlib import Path from . import SoloTool -class FileSystemSessionManager: +class SessionManager(Protocol): + @abstractmethod + def getSessions(self) -> list[str]: + raise NotImplementedError + + @abstractmethod + def loadSession(self, key: str, player=None) -> SoloTool: + raise NotImplementedError + + @abstractmethod + def saveSession(self, soloTool: SoloTool, key: str) -> None: + raise NotImplementedError + + @abstractmethod + def addSong(self, name: str, content: BinaryIO) -> None: + raise NotImplementedError + +class _FileSystemSessionManager(SessionManager): def __init__(self, songPool: str, sessionPath: str): self._songPool = Path(songPool) self._sessionPath = Path(sessionPath) @@ -39,5 +58,11 @@ class FileSystemSessionManager: with open(self._sessionPath / f"{key}.json", "w") as f: json.dump(session, f) -def getSessionManager(songPool: str, sessionPath: str) -> FileSystemSessionManager: - return FileSystemSessionManager(songPool, sessionPath) + def addSong(self, name: str, content: BinaryIO): + from shutil import copyfileobj + newSong = self._songPool / name + with open(newSong, "wb") as f: + copyfileobj(content, f) + +def getSessionManager(songPool: str, sessionPath: str) -> SessionManager: + return _FileSystemSessionManager(songPool, sessionPath) |