mirror of
https://github.com/MarioSpore/Grinch-AP.git
synced 2025-10-21 20:21:32 -06:00
make get_options a bit more refined
This commit is contained in:
16
Utils.py
16
Utils.py
@@ -172,20 +172,16 @@ def get_public_ipv4() -> str:
|
|||||||
return ip
|
return ip
|
||||||
|
|
||||||
|
|
||||||
_options = None
|
|
||||||
|
|
||||||
|
|
||||||
def get_options() -> dict:
|
def get_options() -> dict:
|
||||||
global _options
|
if not hasattr(get_options, "options"):
|
||||||
if _options:
|
|
||||||
return _options
|
|
||||||
else:
|
|
||||||
locations = ("options.yaml", "host.yaml",
|
locations = ("options.yaml", "host.yaml",
|
||||||
local_path("options.yaml"), local_path("host.yaml"))
|
local_path("options.yaml"), local_path("host.yaml"))
|
||||||
|
|
||||||
for location in locations:
|
for location in locations:
|
||||||
if os.path.exists(location):
|
if os.path.exists(location):
|
||||||
with open(location) as f:
|
with open(location) as f:
|
||||||
_options = parse_yaml(f.read())
|
get_options.options = parse_yaml(f.read())
|
||||||
return _options
|
break
|
||||||
raise FileNotFoundError(f"Could not find {locations[1]} to load options.")
|
else:
|
||||||
|
raise FileNotFoundError(f"Could not find {locations[1]} to load options.")
|
||||||
|
return get_options.options
|
||||||
|
|||||||
Reference in New Issue
Block a user