Skip to content

Commit

Permalink
Reload will report if config couldn't be parsed and the service keeps…
Browse files Browse the repository at this point in the history
… running. (#46)

Authored-by: Nina Alexandra Klama <[email protected]>
  • Loading branch information
NAKlama authored Jun 6, 2024
1 parent a8755fe commit 1bc4f60
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions fanctrl.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ def __init__(self, path):

def reload(self):
with open(self.path, "r") as fp:
self.data = json.load(fp)
try:
self.data = json.load(fp)
except json.JSONDecodeError:
return False
return True

def getStrategies(self):
return self.data["strategies"].keys()
Expand Down Expand Up @@ -161,10 +165,12 @@ def bindSocket(self):
if args.list_strategies:
client_socket.sendall('\n'.join(self.configuration.getStrategies()).encode())
if args.reload:
self.configuration.reload()
if self.overwrittenStrategy is not None:
self.overwriteStrategy(self.overwrittenStrategy.name)
client_socket.sendall("Success".encode())
if self.configuration.reload():
if self.overwrittenStrategy is not None:
self.overwriteStrategy(self.overwrittenStrategy.name)
client_socket.sendall("Success".encode())
else:
client_socket.sendall("Error: Config file could not be parsed due to JSON Error".encode())
except:
pass
finally:
Expand Down

0 comments on commit 1bc4f60

Please sign in to comment.