Skip to content

Commit

Permalink
fix daily log date
Browse files Browse the repository at this point in the history
  • Loading branch information
benderl committed Jan 20, 2024
1 parent ad43091 commit cf77b88
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions packages/helpermodules/update_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@


class UpdateConfig:
DATASTORE_VERSION = 35
DATASTORE_VERSION = 36
valid_topic = [
"^openWB/bat/config/configured$",
"^openWB/bat/set/charging_power_left$",
Expand Down Expand Up @@ -1135,7 +1135,9 @@ def convert_file(file):
for e in content["entries"]:
if type(e["date"]) is not str:
old_date = datetime.datetime.fromtimestamp(e["date"])
e["date"] = old_date.strftime('%H:$M')
# old version had a bug formatting "date" '$M' <-> '%M'
# e["date"] = old_date.strftime('%H:$M')
e["date"] = old_date.strftime('%H:%M')
if type(e["timestamp"]) is float:
e["timestamp"] = int(e["timestamp"])
jsonFile.seek(0)
Expand All @@ -1149,4 +1151,28 @@ def convert_file(file):
files = glob.glob(str(self.base_path / "data" / "daily_log") + "/*")
for file in files:
convert_file(file)
Pub().pub("openWB/system/datastore_version", 35)
# next upgrade only fixes a bug introduced in an earlier version of this method
# so we can skip upgrade_datastore_35() if this fixed version has run
Pub().pub("openWB/system/datastore_version", 36)

def upgrade_datastore_35(self) -> None:
def convert_file(file):
try:
with open(file, "r+") as jsonFile:
content = json.load(jsonFile)
for e in content["entries"]:
if type(e["date"]) is str and '$M' in e["date"]:
old_timestamp = datetime.datetime.fromtimestamp(e["timestamp"])
e["date"] = old_timestamp.strftime('%H:%M')
jsonFile.seek(0)
json.dump(content, jsonFile)
jsonFile.truncate()
log.debug(f"Format der Logdatei {file} aktualisiert.")
except FileNotFoundError:
pass
except Exception:
log.exception(f"Logfile {file} konnte nicht konvertiert werden.")
files = glob.glob(str(self.base_path / "data" / "daily_log") + "/*")
for file in files:
convert_file(file)
Pub().pub("openWB/system/datastore_version", 36)

0 comments on commit cf77b88

Please sign in to comment.