.lib.Result has grown enourmously in size and merits its own module. For now, reexport it from .lib.base to not break all code containing "from jw.lib.base import Result" Signed-off-by: Jan Lindemann <jan@janware.com>
40 lines
868 B
Python
40 lines
868 B
Python
from __future__ import annotations
|
|
|
|
from enum import Enum, auto
|
|
from typing import TYPE_CHECKING, NamedTuple, TypeAlias
|
|
|
|
from .Result import Result as Result
|
|
|
|
if TYPE_CHECKING:
|
|
import os
|
|
|
|
class InputMode(Enum):
|
|
Interactive = auto()
|
|
NonInteractive = auto()
|
|
OptInteractive = auto()
|
|
Auto = auto()
|
|
|
|
Input: TypeAlias = InputMode | bytes | str
|
|
|
|
class StatResult(NamedTuple):
|
|
mode: int
|
|
owner: str
|
|
group: str
|
|
size: int
|
|
atime: float
|
|
mtime: float
|
|
ctime: float
|
|
|
|
@classmethod
|
|
def from_os(cls, rhs: os.stat_result) -> StatResult:
|
|
import grp
|
|
import pwd
|
|
return StatResult(
|
|
rhs.st_mode,
|
|
pwd.getpwuid(rhs.st_uid).pw_name,
|
|
grp.getgrgid(rhs.st_gid).gr_name,
|
|
rhs.st_size,
|
|
rhs.st_atime,
|
|
rhs.st_mtime,
|
|
rhs.st_ctime,
|
|
)
|