Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
rsnodgrass committed Feb 27, 2024
1 parent 05bafa4 commit bf27e1c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 21 deletions.
18 changes: 0 additions & 18 deletions pyavcontrol/library/__init__.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,6 @@
import re
from pyavcontrol.const import DEFAULT_MODEL_LIBRARIES
from pyavcontrol.library.base import DeviceModelSummary
from pyavcontrol.library.model import DeviceModel

def filter_models_by_regex(models: set[DeviceModelSummary], regex: str) -> set[DeviceModelSummary]:
"""
Filter the provided set of DeviceModelSummary down into only the ones that
match the given regular expression.
Returns:
dict of model summaries where the manufacturer or model name matches the
provided regular expression.
"""
matches = set()
rg = re.compile(regex)
for summary in models:
if rg.match(summary.manufacturer) or rg.match(summary.model_name) or rg.match(summary.model_id):
matches += summary
return matches

class DeviceModelLibrary:
@staticmethod
def create(library_dirs=DEFAULT_MODEL_LIBRARIES, event_loop=None):
Expand Down
17 changes: 17 additions & 0 deletions pyavcontrol/library/base.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import re
from abc import abstractmethod, ABC
from dataclasses import dataclass

Expand All @@ -9,6 +10,22 @@ class DeviceModelSummary:
model_name: str
model_id: str

def filter_models_by_regex(models: set[DeviceModelSummary], regex: str) -> set[DeviceModelSummary]:
"""
Filter the provided set of DeviceModelSummary down into only the ones that
match the given regular expression.
Returns:
dict of model summaries where the manufacturer or model name matches the
provided regular expression.
"""
matches = set()
rg = re.compile(regex)
for summary in models:
if rg.match(summary.manufacturer) or rg.match(summary.model_name) or rg.match(summary.model_id):
matches += summary
return matches

class DeviceModelLibraryBase(ABC):
@abstractmethod
def load_model(self, name: str) -> DeviceModel: # FIXME | None:
Expand Down
4 changes: 1 addition & 3 deletions pyavcontrol/library/yaml_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@

import yaml

from . import DeviceModelSummary
from .base import DeviceModelLibraryBase
from .. import DeviceModelLibrary
from .base import DeviceModelLibraryBase, DeviceModelSummary
from .model import DeviceModel

# TODO: investigate CUE (validation) or PKL as replacement/enhancements
Expand Down

0 comments on commit bf27e1c

Please sign in to comment.