From 1dcde6cc9cb322b743e0b0355c697af869c2934a Mon Sep 17 00:00:00 2001 From: Eddy Pedroni Date: Wed, 16 Jul 2025 07:10:50 +0200 Subject: Session manager add song, interface, web UI tested --- solo-tool-project/src/solo_tool/session_manager.py | 31 +++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) (limited to 'solo-tool-project/src/solo_tool') 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) -- cgit v1.2.3