mirror of
ssh://git.janware.com/janware/proj/jw-pkg
synced 2026-04-24 09:13:37 +02:00
lib.PackageFilter: Add module
Add a package filter abstraction designed to replace the package filter string tossed around various functions througout jw-pkg. Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
dacea3a104
commit
33ff46e7b3
1 changed files with 26 additions and 0 deletions
26
src/python/jw/pkg/lib/PackageFilter.py
Normal file
26
src/python/jw/pkg/lib/PackageFilter.py
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
import abc, re
|
||||||
|
|
||||||
|
from .Package import Package
|
||||||
|
|
||||||
|
class PackageFilter(abc.ABC):
|
||||||
|
|
||||||
|
@abc.abstractmethod
|
||||||
|
def _match(self, package: Package) -> bool:
|
||||||
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
def match(self, package: Package) -> bool:
|
||||||
|
return self._match(package)
|
||||||
|
|
||||||
|
class PackageFilterString(PackageFilter):
|
||||||
|
|
||||||
|
def __init__(self, definition: str) -> None:
|
||||||
|
# -- Poor man's parsing for now
|
||||||
|
url_rx_str = re.sub(r'^\s*url\s*=~\s*', '', definition)
|
||||||
|
if url_rx_str == definition:
|
||||||
|
raise Exception(f'Unsupported filter string "{definition}"')
|
||||||
|
self.__definition = url_rx_str
|
||||||
|
|
||||||
|
def _match(self, package: Package) -> bool:
|
||||||
|
return re.search(self.__definition, package.url) is not None
|
||||||
Loading…
Add table
Add a link
Reference in a new issue