lib.ExecContext.username: Add property

Add the property .username, backed by the protected _username()
callback. It should return the user run()'s cmd parameter is executed
as.

Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2026-04-19 14:03:31 +02:00
commit 9f756222fe
3 changed files with 15 additions and 4 deletions

View file

@ -2,7 +2,7 @@
from typing import Any
import os, abc, sys
import os, abc, sys, pwd
from enum import Flag, auto
from ..util import pretty_cmd
@ -128,8 +128,9 @@ class SSHClient(ExecContext):
def set_username(self, username: str) -> None:
self.__username = username
@property
def username(self) -> str|None:
def _username(self) -> str:
if self.__username is None:
return pwd.getpwuid(os.getuid()).pw_name
return self.__username
def ssh_client(*args, type: str|list[str]|None=None, **kwargs) -> SSHClient: # export