-
Notifications
You must be signed in to change notification settings - Fork 243
/
Copy path__init__.py
30 lines (23 loc) · 1.04 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import importlib
import inspect
import pathlib
from .adapters import WallpaperProvider
def _is_adapter(member) -> bool:
return (inspect.isclass(member)
and issubclass(member, WallpaperProvider)
and member != WallpaperProvider)
def _get_adapter_classes() -> [WallpaperProvider]:
"""
This methods reads all the modules in the adapters folder searching for
all the implementing wallpaper adapter classes
thanks for/adapted from https://github.com/cclauss/adapter_pattern/
"""
adapter_dir = pathlib.Path(__file__).resolve().parent / 'adapters'
for file in adapter_dir.iterdir():
if file.suffix.lower() == '.py' and not file.name.startswith('__'):
module = importlib.import_module('.' + file.name.split('.')[0], 'pokemonterminal.wallpaper.adapters')
for _, c in inspect.getmembers(module, _is_adapter):
yield c
def get_current_wallpaper_adapters() -> [WallpaperProvider]:
arr = _get_adapter_classes()
return [x for x in arr if x.is_compatible()]