From 674e51a7b20641199eb3ff42e774f8c8c6699c69 Mon Sep 17 00:00:00 2001 From: Jan Lindemann Date: Tue, 27 Jan 2026 13:25:52 +0100 Subject: [PATCH] jw.pkg.cmds.distro.backend: Add module Add directory to host distro backends. Signed-off-by: Jan Lindemann --- .../jw/pkg/cmds/distro/backend/BackendCmd.py | 35 +++++++++++++++++++ .../jw/pkg/cmds/distro/backend/Makefile | 4 +++ 2 files changed, 39 insertions(+) create mode 100644 src/python/jw/pkg/cmds/distro/backend/BackendCmd.py create mode 100644 src/python/jw/pkg/cmds/distro/backend/Makefile diff --git a/src/python/jw/pkg/cmds/distro/backend/BackendCmd.py b/src/python/jw/pkg/cmds/distro/backend/BackendCmd.py new file mode 100644 index 00000000..65901491 --- /dev/null +++ b/src/python/jw/pkg/cmds/distro/backend/BackendCmd.py @@ -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 diff --git a/src/python/jw/pkg/cmds/distro/backend/Makefile b/src/python/jw/pkg/cmds/distro/backend/Makefile new file mode 100644 index 00000000..19fedac9 --- /dev/null +++ b/src/python/jw/pkg/cmds/distro/backend/Makefile @@ -0,0 +1,4 @@ +TOPDIR = ../../../../../../.. + +include $(TOPDIR)/make/proj.mk +include $(JWBDIR)/make/py-mod.mk