mirror of
ssh://git.janware.com/janware/proj/jw-pkg
synced 2026-04-24 17:23:36 +02:00
cmds.distro.pkg.CmdMeta: Add class
Support distro pkg meta <package names ...>, returning meta information for the specified package names. Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
f55d3045e0
commit
0317f46a01
4 changed files with 45 additions and 9 deletions
|
|
@ -1,11 +1,11 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
from typing import TYPE_CHECKING
|
from typing import Iterable, TYPE_CHECKING
|
||||||
|
|
||||||
import abc
|
import abc
|
||||||
from typing import Iterable
|
|
||||||
|
|
||||||
|
from ..lib.Package import Package
|
||||||
from .Backend import Backend as Base
|
from .Backend import Backend as Base
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
|
|
@ -16,9 +16,16 @@ class BePkg(Base):
|
||||||
def __init__(self, parent: Parent):
|
def __init__(self, parent: Parent):
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
|
|
||||||
async def list_files(self, name: str) -> Iterable[str]:
|
async def files(self, name: str) -> Iterable[str]:
|
||||||
return await self._list_files(name)
|
return await self._files(name)
|
||||||
|
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
async def _list_files(self, name: str) -> Iterable[str]:
|
async def _files(self, name: str) -> Iterable[str]:
|
||||||
|
pass
|
||||||
|
|
||||||
|
async def meta_data(self, names: Iterable[str]) -> Iterable[Package]:
|
||||||
|
return await self._meta_data(names)
|
||||||
|
|
||||||
|
@abc.abstractmethod
|
||||||
|
async def _meta_data(self, names: Iterable[str]) -> Iterable[Package]:
|
||||||
pass
|
pass
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ from typing import Iterable
|
||||||
from argparse import Namespace
|
from argparse import Namespace
|
||||||
|
|
||||||
from ...lib.Package import Package
|
from ...lib.Package import Package
|
||||||
from ...lib.dpkg import list_files
|
from ...lib.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
|
||||||
|
|
||||||
|
|
@ -13,5 +13,8 @@ class Pkg(Base):
|
||||||
def __init__(self, parent: Cmd):
|
def __init__(self, parent: Cmd):
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
|
|
||||||
async def _list_files(self, name: str) -> Iterable[Package]:
|
async def _files(self, name: str) -> Iterable[str]:
|
||||||
return await list_files(name)
|
return await list_files(name)
|
||||||
|
|
||||||
|
async def _meta_data(self, names: Iterable[str]) -> Iterable[Package]:
|
||||||
|
return await query_packages(names)
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ from typing import Iterable
|
||||||
from argparse import Namespace
|
from argparse import Namespace
|
||||||
|
|
||||||
from ...lib.Package import Package
|
from ...lib.Package import Package
|
||||||
from ...lib.rpm import list_files
|
from ...lib.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
|
||||||
|
|
||||||
|
|
@ -13,5 +13,8 @@ class Pkg(Base):
|
||||||
def __init__(self, parent: Cmd):
|
def __init__(self, parent: Cmd):
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
|
|
||||||
async def _list_files(self, name: str) -> Iterable[Package]:
|
async def _files(self, name: str) -> Iterable[str]:
|
||||||
return await list_files(name)
|
return await list_files(name)
|
||||||
|
|
||||||
|
async def _meta_data(self, names: Iterable[str]) -> Iterable[Package]:
|
||||||
|
return await query_packages(names)
|
||||||
|
|
|
||||||
23
src/python/jw/pkg/cmds/distro/pkg/CmdMeta.py
Normal file
23
src/python/jw/pkg/cmds/distro/pkg/CmdMeta.py
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
from argparse import Namespace, ArgumentParser
|
||||||
|
|
||||||
|
from .Cmd import Cmd
|
||||||
|
from ..CmdPkg import CmdPkg
|
||||||
|
|
||||||
|
class CmdMeta(Cmd): # export
|
||||||
|
|
||||||
|
def __init__(self, parent: CmdPkg) -> None:
|
||||||
|
super().__init__(parent, 'meta', help="List package metadata")
|
||||||
|
|
||||||
|
def add_arguments(self, parser: ArgumentParser) -> None:
|
||||||
|
super().add_arguments(parser)
|
||||||
|
|
||||||
|
async def _run(self, args: Namespace) -> None:
|
||||||
|
for name in args.names:
|
||||||
|
packages = await self._backend.meta_data([name])
|
||||||
|
if packages:
|
||||||
|
assert len(packages) == 1
|
||||||
|
if len(args.names) > 1:
|
||||||
|
print(f'-- {name}')
|
||||||
|
print(packages[0])
|
||||||
Loading…
Add table
Add a link
Reference in a new issue