jw/pkg/cmds/distro/CmdPkg: Add distro pkg ls

Add the distro subcommand class CmdPkg, together with a first
subcommand ls, which prints a list of files contained in a package.

Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2026-02-23 09:18:35 +01:00
commit 881a915098
6 changed files with 98 additions and 0 deletions

View file

@ -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)

View file

@ -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

View file

@ -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)

View file

@ -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

View file

@ -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))

View file

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