Skip to content

Commit cef56cf

Browse files
committed
Added Factory.get_elements_by_name() and Factory.get_elements_by_type()
1 parent d97f670 commit cef56cf

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

pyaml/configuration/factory.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# PyAML factory (construct AML objects from config files)
22
import importlib
33
from threading import Lock
4+
import fnmatch
45

56
from ..common.exception import PyAMLConfigException
67
from ..common.element import Element
@@ -162,6 +163,12 @@ def get_element(self, name:str):
162163
if name not in self._elements:
163164
raise PyAMLConfigException(f"element {name} not defined")
164165
return self._elements[name]
166+
167+
def get_elements_by_name(self,wildcard:str) -> list[Element]:
168+
return [e for k,e in self._elements.items() if fnmatch.fnmatch(k, wildcard)]
169+
170+
def get_elements_by_type(self,type) -> list[Element]:
171+
return [e for k,e in self._elements.items() if isinstance(e,type)]
165172

166173
def clear(self):
167174
self._elements.clear()

0 commit comments

Comments
 (0)