Skip to content

Commit

Permalink
misc cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
rsnodgrass committed Feb 25, 2024
1 parent a186e2a commit f6e6b06
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions pyavcontrol/library/yaml_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
import logging
import os
import pathlib
from abc import ABC, abstractmethod
from abc import ABC
from concurrent.futures import ThreadPoolExecutor
from typing import List, Set
from typing import List

import yaml

from . import DeviceModelSummary
from .. import DeviceModelLibrary
from ..const import DEFAULT_MODEL_LIBRARIES
from .model import DeviceModel

LOG = logging.getLogger(__name__)
Expand Down Expand Up @@ -40,20 +39,14 @@ def __init__(self, library_dirs: List[str]):
def load_model(self, model_id: str) -> DeviceModel | None:
if '/' in model_id:
LOG.error(f"Invalid model '{model_id}': cannot contain / in identifier")
return None

model_def = None
for path in self._dirs:
model_file = f'{path}/{model_id}.yaml'
model_def = _load_yaml_file(model_file)
if model_def:
break

if not model_def:
LOG.warning(f"Could not find model '{model_id}' in the library")
return None
if model_def := _load_yaml_file(f'{path}/{model_id}.yaml'):
return DeviceModel(model_id, model_def)

model = DeviceModel(model_id, model_def)
return model
LOG.warning(f"Could not find model '{model_id}' in the YAML library")
return None

def _all_library_yaml_files(self) -> list[str]:
yaml_files = []
Expand Down

0 comments on commit f6e6b06

Please sign in to comment.