mirror of
ssh://git.janware.com/janware/proj/jw-pkg
synced 2026-04-24 09:13:37 +02:00
lib.ExecContext.create(): Add method
Add a class method to instantiate an ExecContext by its URI. Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
5f6ec5a182
commit
76b702f5b4
1 changed files with 22 additions and 2 deletions
|
|
@ -1,7 +1,12 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import abc
|
||||
from typing import NamedTuple
|
||||
from __future__ import annotations
|
||||
|
||||
import abc, re
|
||||
from typing import NamedTuple, TYPE_CHECKING
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from typing import Self
|
||||
|
||||
class Result(NamedTuple):
|
||||
|
||||
|
|
@ -93,3 +98,18 @@ class ExecContext(abc.ABC):
|
|||
|
||||
async def sudo(self, cmd: list[str], mod_env: dict[str, str] = {}, opts: list[str]=[], verbose: bool|None=None) -> Result:
|
||||
return await self._sudo(cmd, mod_env, opts, self._verbose(verbose))
|
||||
|
||||
@classmethod
|
||||
def create(cls, uri: str, *args, **kwargs) -> Self:
|
||||
tokens = re.split(r'://', uri)
|
||||
schema = tokens[0]
|
||||
match schema:
|
||||
case 'local':
|
||||
from .ec.Local import Local
|
||||
return Local(uri, *args, **kwargs)
|
||||
case 'ssh':
|
||||
from .SSHClient import ssh_client
|
||||
return ssh_client(uri, *args, **kwargs)
|
||||
case _:
|
||||
pass
|
||||
raise Exception(f'Can\'t create execution context for {uri} with unknown schema "{schema}"')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue