Skip to content

Commit

Permalink
fix(config): fix breakage when using fallback config, improved config…
Browse files Browse the repository at this point in the history
… logic to be more flexible
  • Loading branch information
gerblesh committed Jul 5, 2023
1 parent f7966a0 commit f167dc9
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions ublue-update
Original file line number Diff line number Diff line change
Expand Up @@ -79,20 +79,23 @@ def load_config():

# search for the right config
config_path = ""
fallback_config_path = ""
for path in config_paths:
if os.path.isfile(path):
config_path = path
if config_path == "":
config_path = path
fallback_config_path = path
break

fallback_config = tomllib.load(open(fallback_config_path, "rb"))
config = tomllib.load(open(config_path, "rb"))
return config
return config, fallback_config

def load_value(key,value):
default_config_path = "/usr/etc/ublue-update/ublue-update.toml"
default = tomllib.load(os.open(default_config_path,"rb"))
fallback = fallback_config[key][value]
if key in config.keys():
return config[key].get(value, default)
return default
return config[key].get(value, fallback)
return fallback

def run_updates():
root_dir = "/etc/ublue-update.d/"
Expand All @@ -118,12 +121,15 @@ def run_updates():
else:
log.info(f"could not execute file {full_path}")

config = load_config()
config, fallback_config = load_config()

dbus_notify = load_value("notify","dbus_notify")
min_battery_percent = load_value("checks","battery_percent")
max_cpu_load = load_value("checks","cpu_load")

print(dbus_notify, min_battery_percent, max_cpu_load)

exit()
# setup logging
logging.basicConfig(
format="[%(asctime)s] %(name)s:%(levelname)s | %(message)s",
Expand Down

0 comments on commit f167dc9

Please sign in to comment.