Track created instances, show only ours in UI, v1.0.36
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
"""Трекер созданных инстансов — только те что породило приложение."""
|
||||
import json
|
||||
import os
|
||||
import threading
|
||||
|
||||
_LOCK = threading.Lock()
|
||||
_PATH = os.path.join(os.path.dirname(__file__), "..", "instances.json")
|
||||
|
||||
|
||||
def _load():
|
||||
try:
|
||||
with open(_PATH) as f:
|
||||
return json.load(f)
|
||||
except (FileNotFoundError, json.JSONDecodeError):
|
||||
return {}
|
||||
|
||||
|
||||
def _save(data):
|
||||
with open(_PATH, "w") as f:
|
||||
json.dump(data, f, indent=2)
|
||||
|
||||
|
||||
def add(instance_uid, svc_id, display_name):
|
||||
with _LOCK:
|
||||
data = _load()
|
||||
data[instance_uid] = {
|
||||
"svcId": svc_id,
|
||||
"displayName": display_name,
|
||||
"instanceUid": instance_uid,
|
||||
}
|
||||
_save(data)
|
||||
|
||||
|
||||
def remove(instance_uid):
|
||||
with _LOCK:
|
||||
data = _load()
|
||||
data.pop(instance_uid, None)
|
||||
_save(data)
|
||||
|
||||
|
||||
def list_all():
|
||||
with _LOCK:
|
||||
return list(_load().values())
|
||||
Reference in New Issue
Block a user