Skip to content

Commit

Permalink
Define order on log messages and use in web UI
Browse files Browse the repository at this point in the history
  • Loading branch information
ties committed Dec 11, 2023
1 parent cbe9c86 commit 8e83baa
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## 2023-12-11

* Add a stable sort for event log items and use it in the web
index page.
4 changes: 3 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
exclude MANIFEST.in
exclude poetry.lock
exclude .pre-commit-config.yaml
exclude .flake8
exclude .dockerignore
exclude Dockerfile
exclude nodemon.json

include poetry.lock
include CHANGELOG.md

global-exclude .gitkeep .gitignore .DS_Store

prune docs
Expand Down
5 changes: 1 addition & 4 deletions sagemcom_f3896_client/client.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import asyncio
import logging
import operator
import time
from contextlib import asynccontextmanager
from contextvars import ContextVar
Expand Down Expand Up @@ -173,9 +172,7 @@ async def modem_event_log(self) -> List[EventLogItem]:
async with self.__request("GET", "/rest/v1/cablemodem/eventlog") as resp:
res = await resp.json()
return sorted(
[EventLogItem.build(e) for e in res["eventlog"]],
key=operator.attrgetter("time"),
reverse=True,
(EventLogItem.build(e) for e in res["eventlog"]), reverse=True
)

async def modem_service_flows(self) -> List[ModemServiceFlowResult]:
Expand Down
8 changes: 7 additions & 1 deletion sagemcom_f3896_client/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,14 @@ def build(body: Dict[str, str]) -> "UserTokenResult":
)


@dataclass
@dataclass(order=True, frozen=True)
class EventLogItem:
"""Event log elements.
Sorted by time, priority, message (field order).
Is hashable because it's frozen.
"""

time: datetime.datetime
priority: Literal["error", "notice", "critical", "warning"]
message: str
Expand Down

0 comments on commit 8e83baa

Please sign in to comment.