reformat, add router shell intercept, and other tooling

This commit is contained in:
Didier Slof 2022-12-13 13:39:51 +01:00
parent 244a7d471d
commit 6591b66247
Signed by: didier
GPG key ID: 01E71F18AA4398E5
6 changed files with 57 additions and 1 deletions

28
tools/manager/savefile.py Normal file
View file

@ -0,0 +1,28 @@
import json
import os
class SaveFile(dict):
def __init__(self, file: str) -> None:
super().__init__()
self.path: str = file
_dir = os.path.dirname(self.path)
if not os.path.exists(_dir):
os.makedirs(_dir)
if os.path.exists(self.path):
with open(self.path, 'r') as f:
self.update(json.loads(f.read()))
else:
self.save()
def save(self):
with open(self.path, 'w+') as f:
f.write(json.dumps(self))
def __getitem__(self, key):
return super().__getitem__(key)
def __setitem__(self, key, value):
super().__setitem__(key, value)
self.save()