33 lines
936 B
Python
33 lines
936 B
Python
import pathlib
|
|
|
|
from . import core
|
|
|
|
path_storagedir = pathlib.Path()
|
|
|
|
class JS_API:
|
|
def __init__(self):
|
|
self.debug_mode = False
|
|
|
|
def load_data(self, key):
|
|
if not (path_storagedir / key).exists():
|
|
return None
|
|
|
|
with open(path_storagedir / key) as fd_datafile:
|
|
try:
|
|
return fd_datafile.read()
|
|
except Exception as exc:
|
|
core.log.error(f"problem loading {key} (from {path_storagedir}): {exc}")
|
|
return None
|
|
|
|
def save_data(self, key, data):
|
|
with open(path_storagedir / key, "w") as fd_datafile:
|
|
try:
|
|
fd_datafile.write(data)
|
|
except Exception as exc:
|
|
core.log.error(f"problem saving {key} (to {path_storagedir}): {exc}")
|
|
|
|
def delete_data(self, key):
|
|
if (path_storagedir / key).exists():
|
|
(path_storagedir / key).unlink()
|
|
|
|
api = JS_API() |