Separate into steps and wrap filesystem access

This commit is contained in:
Anton Osika
2023-05-06 20:11:17 +02:00
parent 026ac206c1
commit 15b353d975
13 changed files with 183 additions and 112 deletions

28
db.py Normal file
View File

@@ -0,0 +1,28 @@
from dataclasses import dataclass
import os
from pathlib import Path
class DB:
def __init__(self, path):
self.path = Path(path).absolute()
os.makedirs(self.path, exist_ok=True)
def __getitem__(self, key):
with open(self.path / key) as f:
return f.read()
def __setitem__(self, key, val):
with open(self.path / key, 'w') as f:
f.write(val)
# dataclass for all dbs:
@dataclass
class DBs:
memory: DB
logs: DB
identity: DB
input: DB
workspace: DB