lib.base.StatResult: Add type

Add the basic type StatResult. It is something akin to
os.stat_result, but with user and group string members instead of
st_uid and st_gid. The latter can't be expected to be stable across
remote contexts.

Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2026-04-17 15:26:44 +02:00
commit bc3ed1737f

View file

@ -28,3 +28,25 @@ class Result(NamedTuple):
self.stderr.decode(encoding, errors=errors) if self.stderr is not None else None,
self.status
)
class StatResult(NamedTuple):
mode: int
owner: str
group: str
size: int
atime: int
mtime: int
ctime: int
@classmethod
def from_os(cls, rhs: os.stat_result) -> StatResult:
import pwd, grp
return StatResult(
rhs.st_mode,
pwd.getpwuid(rhs.pw_uid).pw_name,
grp.getgrgid(gid).gr_name,
rhs.st_size,
rhs.st_mtime,
rhs.st_ctime,
)