diff --git a/src/python/jw/pkg/cmds/distro/CmdPkg.py b/src/python/jw/pkg/cmds/distro/CmdPkg.py new file mode 100644 index 00000000..76c7619b --- /dev/null +++ b/src/python/jw/pkg/cmds/distro/CmdPkg.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- + +from argparse import Namespace, ArgumentParser + +from .Cmd import Cmd +from ..CmdDistro import CmdDistro + +class CmdPkg(Cmd): # export + + def __init__(self, parent: CmdDistro) -> None: + super().__init__(parent, 'pkg', help="Show package information") + self._add_subcommands() + + def add_arguments(self, parser: ArgumentParser) -> None: + super().add_arguments(parser) + parser.add_argument('--name', help='Package name') + + async def _run(self, args: Namespace) -> None: + return await self._backend.run(args) diff --git a/src/python/jw/pkg/cmds/distro/backend/BePkg.py b/src/python/jw/pkg/cmds/distro/backend/BePkg.py new file mode 100644 index 00000000..f917f5c2 --- /dev/null +++ b/src/python/jw/pkg/cmds/distro/backend/BePkg.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- + +from __future__ import annotations +from typing import TYPE_CHECKING + +import abc +from typing import Iterable + +from .Backend import Backend as Base + +if TYPE_CHECKING: + from ..CmdPkg import CmdPkg as Parent + +class BePkg(Base): + + def __init__(self, parent: Parent): + super().__init__(parent) + + async def list_files(self, name: str) -> Iterable[str]: + return await self._list_files(name) + + @abc.abstractmethod + async def _list_files(self, name: str) -> Iterable[str]: + pass diff --git a/src/python/jw/pkg/cmds/distro/backend/suse/Pkg.py b/src/python/jw/pkg/cmds/distro/backend/suse/Pkg.py new file mode 100644 index 00000000..34011dd1 --- /dev/null +++ b/src/python/jw/pkg/cmds/distro/backend/suse/Pkg.py @@ -0,0 +1,17 @@ +# -*- coding: utf-8 -*- + +from typing import Iterable +from argparse import Namespace + +from ...lib.Package import Package +from ...lib.rpm import list_files +from ...Cmd import Cmd +from ..BePkg import BePkg as Base + +class Pkg(Base): + + def __init__(self, parent: Cmd): + super().__init__(parent) + + async def _list_files(self, name: str) -> Iterable[Package]: + return await list_files(name) diff --git a/src/python/jw/pkg/cmds/distro/pkg/Cmd.py b/src/python/jw/pkg/cmds/distro/pkg/Cmd.py new file mode 100644 index 00000000..f7da8828 --- /dev/null +++ b/src/python/jw/pkg/cmds/distro/pkg/Cmd.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- + +from ..Cmd import Cmd as Base +from ..CmdPkg import CmdPkg as Parent + +class Cmd(Base): # export + + from ..backend.Backend import Backend + + def __init__(self, parent: Parent, name: str, help: str) -> None: + super().__init__(parent, name, help) + + @property + def _backend(self) -> Backend: + return self.parent._backend diff --git a/src/python/jw/pkg/cmds/distro/pkg/CmdLs.py b/src/python/jw/pkg/cmds/distro/pkg/CmdLs.py new file mode 100644 index 00000000..a7838843 --- /dev/null +++ b/src/python/jw/pkg/cmds/distro/pkg/CmdLs.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- + +from argparse import Namespace, ArgumentParser + +from .Cmd import Cmd +from ..CmdPkg import CmdPkg + +class CmdLs(Cmd): # export + + def __init__(self, parent: CmdPkg) -> None: + super().__init__(parent, 'ls', help="List package contents") + + def add_arguments(self, parser: ArgumentParser) -> None: + super().add_arguments(parser) + + async def _run(self, args: Namespace) -> None: + files = await self._backend.list_files(args.name) + print('\n'.join(files)) diff --git a/src/python/jw/pkg/cmds/distro/pkg/Makefile b/src/python/jw/pkg/cmds/distro/pkg/Makefile new file mode 100644 index 00000000..cf0c2a12 --- /dev/null +++ b/src/python/jw/pkg/cmds/distro/pkg/Makefile @@ -0,0 +1,5 @@ +TOPDIR = ../../../../../../.. +#PY_UPDATE_INIT_PY = false + +include $(TOPDIR)/make/proj.mk +include $(JWBDIR)/make/py-mod.mk