summaryrefslogtreecommitdiff
path: root/jimbrella
diff options
context:
space:
mode:
authorFrederick Yin <fkfd@fkfd.me>2021-10-28 22:06:48 +0800
committerFrederick Yin <fkfd@fkfd.me>2021-10-28 22:06:48 +0800
commit2a461c808553bd161c558fedcbd00f70c57d47a5 (patch)
tree14478193019ecfda10e2e78daec6738f38ac9912 /jimbrella
parentf378751a2b0ea4959f80e250afa8b2845f9f286b (diff)
Change arguments to AdminLog.log
Several keys of a monolithic dict are now discrete args
Diffstat (limited to 'jimbrella')
-rw-r--r--jimbrella/admin_log.py21
1 files changed, 13 insertions, 8 deletions
diff --git a/jimbrella/admin_log.py b/jimbrella/admin_log.py
index e30809e..d1c57c2 100644
--- a/jimbrella/admin_log.py
+++ b/jimbrella/admin_log.py
@@ -80,16 +80,21 @@ class AdminLog:
f.close()
return logs
- def log(self, entry: dict) -> None:
- """Serialize a log, and append it to the end of the log file."""
- # wait until database is locked for this write
- while not self.lockfile.lock():
- continue
+ def log(self, event: str, entry: dict, date=None, note="") -> None:
+ """Serialize a log, and append it to the end of the log file.
+
+ Arguments:
+ event | one of the events defined in the class docstring.
+ entry | information pertaining to the log entry.
+ date | if is None, defaults to `datetime.now()`.
+ note | optional note.
+ """
+ self.lockfile.lock()
with open(self.path, "a") as f: # append only
writer = csv.writer(f)
- event = entry["event"]
- line = [event, entry["date"].isoformat()]
+ date = date or datetime.now()
+ line = [event, date.isoformat()]
info = []
if event in ("TAKEAWAY", "GIVEBACK", "OVERDUE"):
info = [
@@ -115,7 +120,7 @@ class AdminLog:
]
line.extend(info)
- line.append(entry["note"])
+ line.append(note)
writer.writerow(line)
f.close()