Source code for spil.sid.read.finders.find_glob

"""
This file is part of SPIL, The Simple Pipeline Lib.

(C) copyright 2019-2023 Michael Haussmann, spil@xeo.info

SPIL is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

SPIL is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with SPIL.
If not, see <https://www.gnu.org/licenses/>.
"""
from __future__ import annotations
from typing import Iterator, List, overload, Optional

from typing_extensions import Literal

import itertools as it

from spil import Sid
from spil.sid.read.finder import Finder

from spil.util.log import debug, warning, error


[docs]class FindByGlob(Finder): """ Parent class for glob type searches: FindInFiles, FindInList, FindInConstants The search process is as follows: find(): - the search sid string is "unfolded" into a list of typed search Sids. do_find() - depending on the types of searches, defined by the search symbols ('>', ...), the search is delegated to a finder function. (currently either "sorted_search" or "star_search"). """ @overload def do_find(self, search_sids: List[Sid], as_sid: Literal[True]) -> Iterator[Sid]: # noqa ... @overload def do_find(self, search_sids: List[Sid], as_sid: Literal[False]) -> Iterator[str]: # noqa ... @overload def do_find( # noqa self, search_sids: List[Sid], as_sid: Optional[bool] ) -> Iterator[Sid] | Iterator[str]: ...
[docs] def do_find(self, search_sids, as_sid=True): # depending on input, select the right generator is_sorted_search = any([ssid.string.count(">") for ssid in search_sids]) if not search_sids: warning("Nothing Searchable. ") generator = () elif is_sorted_search: generator = self.sorted_search(search_sids, as_sid=as_sid) else: generator = self.star_search(search_sids, as_sid=as_sid) yield from generator
@overload def star_search( self, search_sids: List[Sid], as_sid: Literal[False], do_sort: bool = False ) -> Iterator[str]: ... @overload def star_search( self, search_sids: List[Sid], as_sid: Literal[True], do_sort: bool = False ) -> Iterator[Sid]: ... @overload def star_search( self, search_sids: List[Sid], as_sid: Optional[bool], do_sort: bool ) -> Iterator[str] | Iterator[Sid]: ... """ Problem: FTOT/S/SQ0001/SH0020/**/cache,maya?state=WIP&version=> Doesn't return FTOT/S/SQ0001/SH0020/ANI/V019/WIP/CAM/abc See tests/filesearch. """
if __name__ == "__main__": pass