mirror of
https://gitlab.com/crafty-controller/crafty-4.git
synced 2024-08-30 18:23:09 +00:00
Simplify helpers setting methods
This commit is contained in:
parent
0eac0721ea
commit
8e13b4e11d
@ -194,7 +194,6 @@ class Helpers:
|
||||
return cmd_out
|
||||
|
||||
def get_setting(self, key, default_return=False):
|
||||
|
||||
try:
|
||||
with open(self.settings_file, "r", encoding="utf-8") as f:
|
||||
data = json.load(f)
|
||||
@ -202,10 +201,8 @@ class Helpers:
|
||||
if key in data.keys():
|
||||
return data.get(key)
|
||||
|
||||
else:
|
||||
logger.error(f"Config File Error: setting {key} does not exist")
|
||||
Console.error(f"Config File Error: setting {key} does not exist")
|
||||
return default_return
|
||||
logger.error(f'Config File Error: Setting "{key}" does not exist')
|
||||
Console.error(f'Config File Error: Setting "{key}" does not exist')
|
||||
|
||||
except Exception as e:
|
||||
logger.critical(
|
||||
@ -217,22 +214,19 @@ class Helpers:
|
||||
|
||||
return default_return
|
||||
|
||||
def set_setting(self, key, new_value, default_return=False):
|
||||
|
||||
def set_setting(self, key, new_value):
|
||||
try:
|
||||
with open(self.settings_file, "r", encoding="utf-8") as f:
|
||||
data = json.load(f)
|
||||
|
||||
if key in data.keys():
|
||||
data[key] = new_value
|
||||
with open(self.settings_file, "w", encoding="utf-8") as f:
|
||||
json.dump(data, f, indent=2)
|
||||
return True
|
||||
|
||||
else:
|
||||
logger.error(f"Config File Error: setting {key} does not exist")
|
||||
Console.error(f"Config File Error: setting {key} does not exist")
|
||||
return default_return
|
||||
|
||||
with open(self.settings_file, "w", encoding="utf-8") as f:
|
||||
json.dump(data, f, indent=2)
|
||||
logger.error(f'Config File Error: Setting "{key}" does not exist')
|
||||
Console.error(f'Config File Error: Setting "{key}" does not exist')
|
||||
|
||||
except Exception as e:
|
||||
logger.critical(
|
||||
@ -241,6 +235,7 @@ class Helpers:
|
||||
Console.critical(
|
||||
f"Config File Error: Unable to read {self.settings_file} due to {e}"
|
||||
)
|
||||
return False
|
||||
|
||||
@staticmethod
|
||||
def get_local_ip():
|
||||
|
Loading…
Reference in New Issue
Block a user