mirror of
ssh://git.janware.com/janware/proj/jw-pkg
synced 2026-04-25 09:35:54 +02:00
33 lines
877 B
Python
33 lines
877 B
Python
|
|
# -*- coding: utf-8 -*-
|
||
|
|
|
||
|
|
import abc
|
||
|
|
from typing import NamedTuple
|
||
|
|
|
||
|
|
class Result(NamedTuple):
|
||
|
|
|
||
|
|
stdout: str|None
|
||
|
|
stderr: str|None
|
||
|
|
status: int|None
|
||
|
|
|
||
|
|
class ExecContext(abc.ABC):
|
||
|
|
|
||
|
|
def __init__(self, interactive: bool=True):
|
||
|
|
self.__interactive = interactive
|
||
|
|
|
||
|
|
@property
|
||
|
|
def interactive(self):
|
||
|
|
return self.__interactive
|
||
|
|
|
||
|
|
@abc.abstractmethod
|
||
|
|
async def _run(self, *args, **kwargs) -> Result:
|
||
|
|
pass
|
||
|
|
|
||
|
|
async def run(self, *args, **kwargs) -> Result:
|
||
|
|
return await self._run(*args, **kwargs)
|
||
|
|
|
||
|
|
@abc.abstractmethod
|
||
|
|
async def _sudo(self, cmd: list[str], mod_env: dict[str, str] = {}, opts: list[str]=[], verbose=True) -> Result:
|
||
|
|
pass
|
||
|
|
|
||
|
|
async def sudo(self, cmd: list[str], mod_env: dict[str, str] = {}, opts: list[str]=[], verbose=True) -> Result:
|
||
|
|
return await self._sudo(cmd, mod_env, opts, verbose)
|