]> git.armaanb.net Git - lightcards.git/blobdiff - lightcards/config.py
Fix sidebar showing wrong side of card
[lightcards.git] / lightcards / config.py
index 56f72617a72d0d529b45a95d68afd249a5a7a534..04cfdf99627f108ccc12fafb0d0506d3c194d919 100644 (file)
@@ -13,32 +13,26 @@ class ConfigException(BaseException):
         sys.exit(4)
 
 
-def find_file(file):
+def read_file(file):
+    config = {}
     file = str(file)
+    files = []
     local_xdg = f"{os.path.expanduser('~')}/{os.environ.get('XDG_CACHE_HOME')}/lightcards/config.py"
     local = f"{os.path.expanduser('~')}/.config/lightcards/config.py"
     world = "/etc/lightcards/config.py"
-    world_default = "/usr/share/doc/lightcards/config.py"
-    local_default = (
-        f"{os.path.expanduser('~')}/.local/share/doc/lightcards/config.py"
-    )
-
-    if os.path.exists(file):
-        return file
-    elif os.path.exists(local_xdg):
-        return local_xdg
-    elif os.path.exists(local):
-        return local
-    elif os.path.exists(world):
-        return world
-    elif os.path.exists(world_default):
-        return world_default
-    elif os.path.exists(local_default):
-        return local_default
 
+    if os.path.exists(world):
+        files.append(world)
+    if os.path.exists(local_xdg):
+        files.append(local_xdg)
+    if os.path.exists(local):
+        files.append(local)
 
-def read_file(file):
-    config = {}
-    exec(Path(str(find_file(file))).read_text(), {}, config)
+    files.append(file)
+    if not os.path.exists(file):
+        raise ConfigException(f'"{file}": No such file or directory') from None
+
+    for f in files:
+        exec(Path(str(f)).read_text(), {}, config)
 
     return config