mirror of
ssh://git.janware.com/janware/proj/jw-pkg
synced 2026-04-25 17:45:55 +02:00
jw.pkg.cmds.distro.backend: Add module
Add directory to host distro backends. Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
0b6fb48485
commit
674e51a7b2
2 changed files with 39 additions and 0 deletions
35
src/python/jw/pkg/cmds/distro/backend/BackendCmd.py
Normal file
35
src/python/jw/pkg/cmds/distro/backend/BackendCmd.py
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
import os
|
||||||
|
|
||||||
|
from ....lib.util import run_cmd
|
||||||
|
from ..Cmd import Cmd
|
||||||
|
|
||||||
|
class BackendCmd:
|
||||||
|
|
||||||
|
def __init__(self, parent: Cmd):
|
||||||
|
self.__parent = parent
|
||||||
|
|
||||||
|
async def _sudo(self, cmd: list[str], mod_env: dict[str, str] = {}):
|
||||||
|
env: dict[str, str]|None = None
|
||||||
|
cmd_input: str|None = None
|
||||||
|
if mod_env:
|
||||||
|
env = os.environ.copy()
|
||||||
|
env.update(mod_env)
|
||||||
|
cmdline = []
|
||||||
|
if os.getuid() != 0:
|
||||||
|
cmdline.append('/usr/bin/sudo')
|
||||||
|
if env is not None:
|
||||||
|
cmdline.append('--preserve-env=' + ','.join(mod_env.keys()))
|
||||||
|
cmdline.extend(cmd)
|
||||||
|
if self.interactive:
|
||||||
|
cmd_input = "mode:interactive"
|
||||||
|
stdout, stderr = await run_cmd(*cmdline, throw=True, verbose=True, env=env, cmd_input=cmd_input)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def parent(self):
|
||||||
|
return self.__parent
|
||||||
|
|
||||||
|
@property
|
||||||
|
def interactive(self) -> bool:
|
||||||
|
return self.__parent.interactive
|
||||||
4
src/python/jw/pkg/cmds/distro/backend/Makefile
Normal file
4
src/python/jw/pkg/cmds/distro/backend/Makefile
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
TOPDIR = ../../../../../../..
|
||||||
|
|
||||||
|
include $(TOPDIR)/make/proj.mk
|
||||||
|
include $(JWBDIR)/make/py-mod.mk
|
||||||
Loading…
Add table
Add a link
Reference in a new issue