1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
from glob import glob
import json
from pathlib import Path
from . import SoloTool
class FileSystemSessionManager:
def __init__(self, songPool: str, sessionPath: str):
self._songPool = Path(songPool)
self._sessionPath = Path(sessionPath)
def getSessions(self) -> list[str]:
return [Path(f).stem for f in glob(f"{self._sessionPath}/*.json")]
def loadSession(self, key: str, player=None) -> SoloTool:
with open(self._sessionPath / f"{key}.json", "r") as f:
session = json.load(f)
st = SoloTool(self._songPool, player=player)
for i, entry in enumerate(session):
songPath = entry["path"]
keyPoints = entry["key_points"]
st.addSong(songPath)
st._keyPoints[i] = keyPoints
return st
def saveSession(self, soloTool: SoloTool, key: str) -> None:
session = []
for i, song in enumerate(soloTool.songs):
entry = {
"path": song,
"key_points" : soloTool._keyPoints[i]
}
session.append(entry)
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)
|