From bc3ed1737f61e82c81dab97cd31e092ce1b61bf9 Mon Sep 17 00:00:00 2001 From: Jan Lindemann Date: Fri, 17 Apr 2026 15:26:44 +0200 Subject: [PATCH] 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 --- src/python/jw/pkg/lib/base.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/python/jw/pkg/lib/base.py b/src/python/jw/pkg/lib/base.py index 793bd09e..81c232e5 100644 --- a/src/python/jw/pkg/lib/base.py +++ b/src/python/jw/pkg/lib/base.py @@ -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, + )