Skip to content
Snippets Groups Projects
Commit 19e7a106 authored by moon2's avatar moon2 :speech_balloon:
Browse files

autostart settings: cleaner save/load mgmt

parent 16556990
No related branches found
No related tags found
1 merge request!690autostart settings: cleaner save/load mgmt
Pipeline #12927 passed
...@@ -35,12 +35,10 @@ def get_autostart(): ...@@ -35,12 +35,10 @@ def get_autostart():
try: try:
with open(_autostart_settings_path, "r") as f: with open(_autostart_settings_path, "r") as f:
_autostart_data = json.load(f) _autostart_data = json.load(f)
log.info("Found autostart settings")
except Exception as e: except Exception as e:
_autostart_data = {"slug": None, "name": None}
log.info("Could not find autostart settings: " + str(e)) log.info("Could not find autostart settings: " + str(e))
ret = {}
ret["slug"] = None
ret["name"] = None
return ret
return _autostart_data return _autostart_data
...@@ -51,12 +49,16 @@ def path_to_slug(path): ...@@ -51,12 +49,16 @@ def path_to_slug(path):
def set_autostart(path, name): def set_autostart(path, name):
if not utils.sd_card_plugged(): global _autostart_data
e = "no SD card found"
log.info("Could not save autostart settings: " + str(e))
data = {} data = {}
data["slug"] = path_to_slug(path) data["slug"] = path_to_slug(path)
data["name"] = name data["name"] = name
if data == _autostart_data:
return
if not utils.sd_card_plugged():
e = "no SD card found"
log.info("Could not save autostart settings: " + str(e))
return
save_fail = False save_fail = False
if not os.path.exists(_settings_dir): if not os.path.exists(_settings_dir):
try: try:
...@@ -71,7 +73,6 @@ def set_autostart(path, name): ...@@ -71,7 +73,6 @@ def set_autostart(path, name):
log.warning("Could not save autostart settings: " + str(e)) log.warning("Could not save autostart settings: " + str(e))
save_fail = True save_fail = True
if not save_fail: if not save_fail:
global _autostart_data
_autostart_data = data _autostart_data = data
log.info("Saved autostart settings") log.info("Saved autostart settings")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment