mirror of
ssh://git.janware.com/janware/proj/jw-pkg
synced 2026-04-25 09:35:54 +02:00
lib.ExecContext.run(), .sudo(): Rename env
The name of the env parameter to ExecContext.run() and .sudo() is not descriptive enough for which environment is supposed to be modified and how, so rename and split it up as follows: - .run(): env -> mod_env - .sudo(): env -> mod_env_sudo and mod_env_cmd The parameters have the following meaning: - "mod_env*" means that the environment is modified, not replaced - "mod_env" and "mod_env_cmd" modify the environment "cmd" runs in - "mod_env_sudo" modifies the environment sudo runs in Fix the fallout of the API change all over jw-pkg. Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
9f756222fe
commit
54aecff8e4
9 changed files with 164 additions and 159 deletions
|
|
@ -16,7 +16,7 @@ class SSHClient(ExecContext):
|
|||
class Caps(Flag):
|
||||
LogOutput = auto()
|
||||
Interactive = auto()
|
||||
Env = auto()
|
||||
ModEnv = auto()
|
||||
Wd = auto()
|
||||
|
||||
def __init__(self, uri: str, caps: Caps=Caps(0), *args, **kwargs) -> None:
|
||||
|
|
@ -41,7 +41,7 @@ class SSHClient(ExecContext):
|
|||
wd: str|None,
|
||||
verbose: bool,
|
||||
cmd_input: bytes|None,
|
||||
env: dict[str, str]|None,
|
||||
mod_env: dict[str, str]|None,
|
||||
interactive: bool,
|
||||
log_prefix: str
|
||||
) -> Result:
|
||||
|
|
@ -53,7 +53,7 @@ class SSHClient(ExecContext):
|
|||
wd: str|None,
|
||||
verbose: bool,
|
||||
cmd_input: bytes|None,
|
||||
env: dict[str, str]|None,
|
||||
mod_env: dict[str, str]|None,
|
||||
interactive: bool,
|
||||
log_prefix: str
|
||||
) -> Result:
|
||||
|
|
@ -82,7 +82,7 @@ class SSHClient(ExecContext):
|
|||
if interactive and not self.__caps & self.Caps.Interactive:
|
||||
raise NotImplementedError('Interactive SSH is not yet implemented')
|
||||
|
||||
if env is not None and not self.__caps & self.Caps.Env:
|
||||
if mod_env is not None and not self.__caps & self.Caps.ModEnv:
|
||||
raise NotImplementedError('Passing an environment to SSH commands is not yet implemented')
|
||||
|
||||
ret = await self._run_ssh(
|
||||
|
|
@ -90,7 +90,7 @@ class SSHClient(ExecContext):
|
|||
wd=wd,
|
||||
verbose=verbose,
|
||||
cmd_input=cmd_input,
|
||||
env=env,
|
||||
mod_env=mod_env,
|
||||
interactive=interactive,
|
||||
log_prefix=log_prefix
|
||||
)
|
||||
|
|
@ -103,13 +103,6 @@ class SSHClient(ExecContext):
|
|||
|
||||
return ret
|
||||
|
||||
async def _sudo(self, cmd: list[str], mod_env: dict[str, str], opts: list[str], *args, **kwargs) -> Result:
|
||||
if self.username != 'root':
|
||||
cmd = ['sudo', *opts, *cmd]
|
||||
if mod_env:
|
||||
log(WARNING, f'Modifying environment over SSH is not implemented, ignored')
|
||||
return await self._run(cmd, *args, **kwargs)
|
||||
|
||||
@property
|
||||
def hostname(self) -> str|None:
|
||||
return self.__hostname
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue