mirror of
ssh://git.janware.com/janware/proj/jw-pkg
synced 2026-04-24 09:13:37 +02:00
cmds.distro.CmdSelect: Use select(filter)
Ditch the CmdSelect.filter_packages(), because Distro.select() now supports filtering out of the box. Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
fc6af091eb
commit
1646aaeb59
1 changed files with 3 additions and 10 deletions
|
|
@ -4,6 +4,7 @@ from argparse import Namespace, ArgumentParser
|
|||
import re
|
||||
|
||||
from ...lib.Package import Package
|
||||
from ...lib.PackageFilter import PackageFilterString
|
||||
from ..CmdDistro import CmdDistro
|
||||
from .Cmd import Cmd
|
||||
|
||||
|
|
@ -16,15 +17,7 @@ class CmdSelect(Cmd): # export
|
|||
super().add_arguments(parser)
|
||||
parser.add_argument("filter", help="Package filter string")
|
||||
|
||||
def filter_packages(self, filter: str, packages: list[Package]) -> list[Package]:
|
||||
# -- Poor man's parsing for now
|
||||
url_rx_str = re.sub(r'^\s*url\s*=~\s*', '', filter)
|
||||
if url_rx_str == filter:
|
||||
raise Exception(f'Unsupported filter string "{filter}"')
|
||||
url_rx = re.compile(url_rx_str)
|
||||
return [p for p in packages if re.search(url_rx, p.url) is not None]
|
||||
|
||||
async def _run(self, args: Namespace) -> None:
|
||||
# TODO: Semantics probably change heavily in the future
|
||||
for p in self.filter_packages(args.filter, await self.distro.select()):
|
||||
filter = PackageFilterString(args.filter) if args.filter else None
|
||||
for p in await self.distro.select(filter):
|
||||
print(p.name)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue