2023-08-31 11:17:19 +00:00
|
|
|
import os
|
2023-08-31 15:31:25 +00:00
|
|
|
from typing import Iterator
|
2023-08-31 11:17:19 +00:00
|
|
|
|
|
|
|
from ..settings import SETTINGS
|
2023-08-31 15:23:00 +00:00
|
|
|
from ._report import Report, ReportData
|
|
|
|
|
|
|
|
|
2023-08-31 15:31:25 +00:00
|
|
|
def _hwdata() -> Iterator[ReportData]:
|
2023-08-31 15:23:00 +00:00
|
|
|
def get_path_statvfs(path: os.PathLike) -> dict[str, float]:
|
|
|
|
sv = os.statvfs(path)
|
|
|
|
return {
|
|
|
|
"free": sv.f_bavail,
|
|
|
|
"total": sv.f_blocks,
|
|
|
|
}
|
|
|
|
|
2023-08-31 15:31:25 +00:00
|
|
|
yield from sorted([
|
2023-08-31 15:23:00 +00:00
|
|
|
ReportData.from_free_total(
|
|
|
|
name=str(path),
|
|
|
|
**get_path_statvfs(path),
|
|
|
|
) for path in SETTINGS.disk.paths
|
|
|
|
], key=lambda d: d.value, reverse=True)
|
2023-08-31 11:17:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
def disk() -> Report | None:
|
2023-08-31 15:23:00 +00:00
|
|
|
return Report.aggregate(
|
2023-08-31 11:17:19 +00:00
|
|
|
settings=SETTINGS.disk,
|
2023-08-31 15:31:25 +00:00
|
|
|
get_data=_hwdata,
|
2023-08-31 11:17:19 +00:00
|
|
|
)
|