Skip to content

Commit

Permalink
config.json: log writes with reason
Browse files Browse the repository at this point in the history
  • Loading branch information
wiedehopf committed May 1, 2024
1 parent b47d19d commit 1998ff8
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ def list_value_by_tags(tags, idx):
# now all the envs are loaded and reconciled with the data on file - which means we should
# actually write out the potentially updated values (e.g. when plain values were converted
# to lists)
write_values_to_config_json(self._d.envs)
write_values_to_config_json(self._d.envs, reason="Startup")

def update_boardname(self):
board = ""
Expand Down Expand Up @@ -715,7 +715,7 @@ def executerestore(self):
# this overwrites the value in the file we just restored with the current value of the running image,
# iow it doesn't restore that value from the backup
values[e.name] = e.value
write_values_to_config_json(values)
write_values_to_config_json(values, reason="execute_restore from .env")

# clean up the restore path
restore_path = pathlib.Path("/opt/adsb/config/restore")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def read_values_from_config_json():
# or the first run after an upgrade from a version that didn't use the config.json
print_err("WARNING: config.json doesn't exist, populating from .env")
values = read_values_from_env_file()
write_values_to_config_json(values)
write_values_to_config_json(values, reason="config.json didn't exist")

ret = {}
try:
Expand All @@ -26,9 +26,9 @@ def read_values_from_config_json():
return ret


def write_values_to_config_json(data: dict):
# print_err("writing .json file")
def write_values_to_config_json(data: dict, reason="no reason provided"):
try:
print_err(f"config.json write: {reason}")
fd, tmp = tempfile.mkstemp(dir=CONF_DIR)
with os.fdopen(fd, "w") as f:
json.dump(data, f, indent=2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def _get_value_from_file(self):
def _write_value_to_file(self, new_value):
values = read_values_from_config_json()
values[self._name] = new_value
write_values_to_config_json(values)
write_values_to_config_json(values, reason=f"{self._name} = {new_value}")

def __str__(self):
return f"Env({self._name}, {self._value})"
Expand Down

0 comments on commit 1998ff8

Please sign in to comment.