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 import os, importlib
from ...lib.log import *
from ...lib.distros.Util import Util
from ..Cmd import Cmd as Base from ..Cmd import Cmd as Base
from ..CmdDistro import CmdDistro from ..CmdDistro import CmdDistro
from .backend.Util import Util
class Cmd(Base): # export 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: def __init__(self, parent: CmdDistro, name: str, help: str) -> None:
super().__init__(parent, name, help) super().__init__(parent, name, help)
@ -35,16 +37,16 @@ class Cmd(Base): # export
backend_id = 'redhat' backend_id = 'redhat'
case 'opensuse' | 'suse': case 'opensuse' | 'suse':
backend_id = 'suse' backend_id = 'suse'
self.__backend_path = ( self.__backend_path = 'jw.pkg.lib.distros.' + backend_id + '.'
os.path.splitext(__name__)[0]
+ '.backend.'
+ backend_id
+ '.'
)
return self.__backend_path return self.__backend_path
def _instantiate(self, name: str, *args, **kwargs): 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) cls = getattr(module, name)
return cls(self, *args, **kwargs) return cls(self, *args, **kwargs)

View file

@ -3,10 +3,10 @@
from argparse import Namespace, ArgumentParser from argparse import Namespace, ArgumentParser
import re import re
from ...lib.Package import Package
from ...lib.distros.BeSelect import BeSelect
from ..CmdDistro import CmdDistro from ..CmdDistro import CmdDistro
from .lib.Package import Package
from .Cmd import Cmd from .Cmd import Cmd
from .backend.BeSelect import BeSelect
class CmdSelect(Cmd): # export class CmdSelect(Cmd): # export

View file

@ -7,7 +7,7 @@ from ..CmdPkg import CmdPkg as Parent
class Cmd(Base): # export class Cmd(Base): # export
from ..backend.Backend import Backend from ....lib.distros.Backend import Backend
def __init__(self, parent: Parent, name: str, help: str) -> None: def __init__(self, parent: Parent, name: str, help: str) -> None:
super().__init__(parent, name, help) super().__init__(parent, name, help)

View file

@ -3,7 +3,7 @@
from __future__ import annotations from __future__ import annotations
from typing import TYPE_CHECKING from typing import TYPE_CHECKING
from ....lib.util import run_sudo from ..util import run_sudo
if TYPE_CHECKING: if TYPE_CHECKING:
from ..Cmd import Cmd from ..Cmd import Cmd

View file

@ -4,7 +4,7 @@ import abc
from argparse import Namespace from argparse import Namespace
from .Backend import Backend as Base from .Backend import Backend as Base
from ..CmdDelete import CmdDelete as Parent from ..Cmd import Cmd as Parent
class BeDelete(Base): class BeDelete(Base):

View file

@ -4,7 +4,7 @@ import abc
from argparse import Namespace from argparse import Namespace
from .Backend import Backend as Base from .Backend import Backend as Base
from ..CmdDup import CmdDup as Parent from ..Cmd import Cmd as Parent
class BeDup(Base): class BeDup(Base):

View file

@ -4,7 +4,7 @@ import abc
from argparse import Namespace from argparse import Namespace
from .Backend import Backend as Base from .Backend import Backend as Base
from ..CmdInstall import CmdInstall as Parent from ..Cmd import Cmd as Parent
class BeInstall(Base): class BeInstall(Base):

View file

@ -5,11 +5,11 @@ from typing import Iterable, TYPE_CHECKING
import abc import abc
from ..lib.Package import Package from ..Package import Package
from .Backend import Backend as Base from .Backend import Backend as Base
if TYPE_CHECKING: if TYPE_CHECKING:
from ..CmdPkg import CmdPkg as Parent from ..Cmd import Cmd as Parent
class BePkg(Base): class BePkg(Base):

View file

@ -4,7 +4,7 @@ import abc
from argparse import Namespace from argparse import Namespace
from .Backend import Backend as Base from .Backend import Backend as Base
from ..CmdRebootRequired import CmdRebootRequired as Parent from ..Cmd import Cmd as Parent
class BeRebootRequired(Base): class BeRebootRequired(Base):

View file

@ -4,7 +4,7 @@ import abc
from argparse import Namespace from argparse import Namespace
from .Backend import Backend as Base from .Backend import Backend as Base
from ..CmdRefresh import CmdRefresh as Parent from ..Cmd import Cmd as Parent
class BeRefresh(Base): class BeRefresh(Base):

View file

@ -9,7 +9,7 @@ from typing import Iterable
from .Backend import Backend as Base from .Backend import Backend as Base
if TYPE_CHECKING: if TYPE_CHECKING:
from ..CmdSelect import CmdSelect as Parent from ..Cmd import Cmd as Parent
from .Package import Package from .Package import Package
class BeSelect(Base): class BeSelect(Base):

View file

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

View file

@ -3,7 +3,7 @@
from __future__ import annotations from __future__ import annotations
from typing import TYPE_CHECKING from typing import TYPE_CHECKING
from ....lib.util import run_sudo from ..util import run_sudo
if TYPE_CHECKING: if TYPE_CHECKING:
from ..Cmd import Cmd from ..Cmd import Cmd

View file

@ -3,8 +3,8 @@
from typing import Iterable from typing import Iterable
from argparse import Namespace from argparse import Namespace
from ...lib.Package import Package from ...Package import Package
from ...lib.rpm import list_files, query_packages from ...pm.dpkg import list_files, query_packages
from ...Cmd import Cmd from ...Cmd import Cmd
from ..BePkg import BePkg as Base from ..BePkg import BePkg as Base

View file

@ -3,7 +3,7 @@
import os import os
from argparse import Namespace from argparse import Namespace
from .....lib.log import * from ...log import *
from ...Cmd import Cmd from ...Cmd import Cmd
from ..BeRebootRequired import BeRebootRequired as Base from ..BeRebootRequired import BeRebootRequired as Base

View file

@ -3,8 +3,8 @@
from typing import Iterable from typing import Iterable
from argparse import Namespace from argparse import Namespace
from ...lib.Package import Package from ...Package import Package
from ...lib.rpm import query_packages from ...pm.dpkg import query_packages
from ...Cmd import Cmd from ...Cmd import Cmd
from ..BeSelect import BeSelect as Base from ..BeSelect import BeSelect as Base

View file

@ -1,7 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from ...Cmd import Cmd from ...Cmd import Cmd
from ...lib.dpkg import run_dpkg from ...pm.dpkg import run_dpkg
from ..Util import Util as Base from ..Util import Util as Base
class Util(Base): class Util(Base):

View file

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

View file

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

View file

@ -3,8 +3,8 @@
from typing import Iterable from typing import Iterable
from argparse import Namespace from argparse import Namespace
from ...lib.Package import Package from ...Package import Package
from ...lib.dpkg import list_files, query_packages from ...pm.rpm import list_files, query_packages
from ...Cmd import Cmd from ...Cmd import Cmd
from ..BePkg import BePkg as Base from ..BePkg import BePkg as Base

View file

@ -3,8 +3,8 @@
from typing import Iterable from typing import Iterable
from argparse import Namespace from argparse import Namespace
from ...lib.Package import Package from ...Package import Package
from ...lib.dpkg import query_packages from ...pm.rpm import query_packages
from ...Cmd import Cmd from ...Cmd import Cmd
from ..BeSelect import BeSelect as Base from ..BeSelect import BeSelect as Base

View file

@ -1,10 +1,10 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from .....lib.util import run_cmd from ...util import run_cmd
from ...Cmd import Cmd from ...Cmd import Cmd
from ..Util import Util as Base from ..Util import Util as Base
from ...lib.rpm import run_rpm from ...pm.rpm import run_rpm
class Util(Base): class Util(Base):

View file

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

View file

@ -2,9 +2,9 @@
from typing import Iterable from typing import Iterable
from ....lib.util import run_cmd, run_sudo from ..util import run_cmd, run_sudo
from .Package import Package, meta_tags from ..Package import Package, meta_tags
_meta_map: dict[str, str]|None = None _meta_map: dict[str, str]|None = None

View file

@ -2,9 +2,9 @@
from typing import Iterable from typing import Iterable
from ....lib.util import run_cmd, run_sudo from ..util import run_cmd, run_sudo
from .Package import Package, meta_tags from ..Package import Package, meta_tags
_meta_map: dict[str, str]|None = None _meta_map: dict[str, str]|None = None