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:
Jan Lindemann 2026-01-27 13:25:52 +01:00
commit 674e51a7b2
2 changed files with 39 additions and 0 deletions

View 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

View file

@ -0,0 +1,4 @@
TOPDIR = ../../../../../../..
include $(TOPDIR)/make/proj.mk
include $(JWBDIR)/make/py-mod.mk