MCPcopy Create free account
hub / github.com/omkarcloud/botasaurus / JSONStorageBackend

Class JSONStorageBackend

bota/src/bota/package_storage.py:26–67  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

24 self.raise_dummy_exception()
25
26class JSONStorageBackend(BasicStorageBackend):
27 def __init__(self) -> None:
28 self.refresh()
29
30 def refresh(self):
31 self.json_path = get_cache_file_path()
32 self.json_data = {}
33
34 if not os.path.isfile(self.json_path):
35 self.commit_to_disk()
36
37 with open(self.json_path, "r") as json_file:
38 self.json_data = json.load(json_file)
39
40 def commit_to_disk(self):
41 with open(self.json_path, "w") as json_file:
42 json.dump(self.json_data, json_file, indent=4)
43
44 def get_item(self, key: str, default = None) -> str:
45 if key in self.json_data:
46 return self.json_data[key]
47 return default
48
49
50 def items(self):
51 return self.json_data
52
53 def set_item(self, key: str, value: any) -> None:
54 self.json_data[key] = value
55 self.commit_to_disk()
56
57 def remove_item(self, key: str) -> None:
58 if key in self.json_data:
59 self.json_data.pop(key)
60 self.commit_to_disk()
61
62
63 def clear(self) -> None:
64 if os.path.isfile(self.json_path):
65 os.remove(self.json_path)
66 self.json_data = {}
67 self.commit_to_disk()
68
69class _LocalStorage:
70 def __init__(self) -> None:

Callers 1

__init__Method · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected