Skip to content

Commit

Permalink
Update zero_trigger.py to load configuration file from home directory…
Browse files Browse the repository at this point in the history
… if it exists, otherwise create a symlink and load from specified file
  • Loading branch information
Nitnelav committed Jun 20, 2024
1 parent ed67bd7 commit 8cdc1ea
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions services/zero_trigger.py
Original file line number Diff line number Diff line change
Expand Up @@ -689,10 +689,21 @@ def unix_time(self):
action.required = True
args = parser.parse_args()
else:
with open(args.configuration_file, "r") as fp:
print("Load configuration file " + args.configuration_file)
cfg = json.load(fp)
args = types.SimpleNamespace(**(vars(args) | cfg))
from pathlib import Path
os.makedirs(Path.home() / ".noisesensor", exist_ok=True)
home_config_path = Path.home() / ".noisesensor" / "zerotrigger_config.json"
if home_config_path.exists():
print("Load configuration file " + str(home_config_path))
with open(home_config_path, "r") as fp:
cfg = json.load(fp)
args = types.SimpleNamespace(**(vars(args) | cfg))
else:
config_file_path = Path(args.configuration_file)
os.symlink(config_file_path.absolute(), home_config_path)
with open(config_file_path, "r") as fp:
print("Load configuration file " + args.configuration_file)
cfg = json.load(fp)
args = types.SimpleNamespace(**(vars(args) | cfg))
print("Configuration:\n" + json.dumps(vars(args),
sort_keys=False, indent=2))
trigger = TriggerProcessor(args)
Expand Down

0 comments on commit 8cdc1ea

Please sign in to comment.