Update writing stats dialog to work with new log file

This commit is contained in:
Veronica Berglyd Olsen
2023-06-13 17:29:15 +02:00
parent eba6783816
commit 1b85f782a6
3 changed files with 54 additions and 59 deletions
+15 -1
View File
@@ -27,7 +27,7 @@ import json
import logging
from time import time
from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, Iterator
from pathlib import Path
from novelwriter.error import logException
@@ -109,6 +109,20 @@ class NWSessionLog:
return True
def iterRecords(self) -> Iterator[dict]:
"""Iterate through all records in the log."""
sessFile = self._project.storage.getMetaFile(nwFiles.SESS_FILE)
if not isinstance(sessFile, Path):
return
try:
with open(sessFile, mode="r", encoding="utf-8") as fObj:
for line in fObj:
yield json.loads(line)
except Exception:
logger.error("Failed to process session stats file")
logException()
return
def createInitial(self, total: int) -> str:
"""Low level function to create the initial log file record."""
data = json.dumps({"type": "initial", "offset": total})