-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugin_handler.py
More file actions
44 lines (34 loc) · 1.41 KB
/
plugin_handler.py
File metadata and controls
44 lines (34 loc) · 1.41 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# -*- coding: utf-8 -*-
# Execute this file to see what plugins will be loaded.
# Implementation leans to Lex Toumbourou's example:
# https://lextoumbourou.com/blog/posts/dynamically-loading-modules-and-classes-in-python/
import os
import pkgutil
import sys
from typing import List
from venues.abstract_venue import AbstractVenue
def load_venue_plugins() -> List[AbstractVenue]:
"""
Read plugin directory and load found plugins.
Variable "blocklist" can be used to exclude loading certain plugins.
"""
blocklist = ["plugin_tiketti", "plugin_telakka"]
found_blocked = list()
loadedplugins = list()
pluginspathabs = os.path.join(os.path.dirname(__file__), "venues")
for loader, plugname, ispkg in \
pkgutil.iter_modules(path=[pluginspathabs]):
if plugname in sys.modules or plugname == "abstract_venue":
continue
if plugname in blocklist:
found_blocked.append(plugname.lstrip("plugin_"))
continue
plugpath = f"venues.{plugname}"
loadplug = __import__(plugpath, fromlist=[plugname])
classname = plugname.split("_")[1].title()
loadedclass = getattr(loadplug, classname)
instance = loadedclass()
loadedplugins.append(instance)
print(f"Loaded plugin: {instance.get_venue_name()}")
print("Blocked plugins: {}.\n".format(", ".join(found_blocked[1:])))
return loadedplugins