jw-pkg/src/python/jw/pkg/lib/ExecContext.py

33 lines
877 B
Python
Raw Normal View History

# -*- 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)