X-Git-Url: https://git.armaanb.net/?p=lightcards.git;a=blobdiff_plain;f=lightcards%2Fconfig.py;h=3c99dc263304795cfcee5b61791ba0a8fc7182ea;hp=56f72617a72d0d529b45a95d68afd249a5a7a534;hb=79afb3261a260272d0c3975eac67872a1c0b25df;hpb=dd109cb4a1b49f920e36e5732417c4a3d5582821 diff --git a/lightcards/config.py b/lightcards/config.py index 56f7261..3c99dc2 100644 --- a/lightcards/config.py +++ b/lightcards/config.py @@ -13,8 +13,10 @@ 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" @@ -23,22 +25,20 @@ def find_file(file): f"{os.path.expanduser('~')}/.local/share/doc/lightcards/config.py" ) + if os.path.exists(world_default): + files.append(world_default) + if os.path.exists(local_default): + files.append(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) 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 - + files.append(file) -def read_file(file): - config = {} - exec(Path(str(find_file(file))).read_text(), {}, config) + for f in files: + exec(Path(str(f)).read_text(), {}, config) return config