aboutsummaryrefslogtreecommitdiff
path: root/labbot/config.py
diff options
context:
space:
mode:
Diffstat (limited to 'labbot/config.py')
-rw-r--r--labbot/config.py34
1 files changed, 26 insertions, 8 deletions
diff --git a/labbot/config.py b/labbot/config.py
index 3e8bcba..10858ea 100644
--- a/labbot/config.py
+++ b/labbot/config.py
@@ -1,27 +1,45 @@
import os
import json
-from appdirs import user_config_dir
+from typing import List
+from appdirs import user_config_dir # type: ignore
+
+CONFIG_FILE = "config.json"
+
+def list_instances() -> List[str]:
+ instances = []
+ with os.scandir(config_dir()) as it:
+ for entry in it:
+ if entry.is_dir() and os.path.isfile(f"{entry.path}/{CONFIG_FILE}"):
+ instances.append(entry.name)
+ return instances
def config_dir() -> str:
- path = user_config_dir("labbot")
+ path: str = user_config_dir("labbot")
os.makedirs(path, exist_ok=True)
return path
-def write_config(name: str, data: dict) -> None:
- conf_path = os.path.join(config_dir(), f"{name}.json")
+def instance_config_dir(name) -> str:
+ path = os.path.join(config_dir(), name)
+
+ return path
+
+def write_instance_config(name: str, data: dict) -> None:
+ instance_path = instance_config_dir(name)
+ os.makedirs(instance_path, exist_ok=True)
+ conf_path = os.path.join(instance_path, CONFIG_FILE)
with open(conf_path, "w") as file:
json.dump(data, file)
- if data != read_config(name):
+ if data != read_instance_config(name):
raise ValueError("Config could not be saved properly")
-def read_config(name: str) -> dict:
- conf_path = os.path.join(config_dir(), f"{name}.json")
+def read_instance_config(name: str) -> dict:
+ conf_path = os.path.join(instance_config_dir(name), CONFIG_FILE)
try:
with open(conf_path, "r") as file:
return json.load(file)
except FileNotFoundError:
- return {} \ No newline at end of file
+ return {}