cmds.distro: Move all modules to lib

Functions abstracting the distribution are not only needed in the
context of the distro subcommand, but also by other code, so make the
bulk of the code abstracting the distribution available in some place
more universally useful than below cmds.distro.

This commit leaves the source files mostly unchanged. They are only
patched to fix import paths, so that functionality is preserved.
Refactoring the code from command-line API to library API will be
done by the next commit.

Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2026-03-05 11:38:29 +01:00
commit 7e7cee6d11
45 changed files with 44 additions and 42 deletions

View file

@ -2,13 +2,15 @@
import os, importlib
from ...lib.log import *
from ...lib.distros.Util import Util
from ..Cmd import Cmd as Base
from ..CmdDistro import CmdDistro
from .backend.Util import Util
class Cmd(Base): # export
from .backend.Backend import Backend
from ...lib.distros.Backend import Backend
def __init__(self, parent: CmdDistro, name: str, help: str) -> None:
super().__init__(parent, name, help)
@ -35,16 +37,16 @@ class Cmd(Base): # export
backend_id = 'redhat'
case 'opensuse' | 'suse':
backend_id = 'suse'
self.__backend_path = (
os.path.splitext(__name__)[0]
+ '.backend.'
+ backend_id
+ '.'
)
self.__backend_path = 'jw.pkg.lib.distros.' + backend_id + '.'
return self.__backend_path
def _instantiate(self, name: str, *args, **kwargs):
module = importlib.import_module(self._backend_path + name)
module_path = self._backend_path + name
try:
module = importlib.import_module(module_path)
except Exception as e:
log(ERR, f'Failed to import module {module_path} ({str(e)})')
raise
cls = getattr(module, name)
return cls(self, *args, **kwargs)