#!/bin/env python3
from logging import getLogger
from logging.config import dictConfig
+from importlib import import_module
from toml import load
from howl.defaults import logger_config as DEFAULT_LOGGER_CONFIG
+from howl.Messenger import Messenger
# Parse commandline args
config_path = "./howl.toml"
except KeyError:
LOGGER_CONFIG = DEFAULT_LOGGER_CONFIG
# default fallback logging config
-finally :
+finally:
dictConfig(LOGGER_CONFIG)
# Init logger
logger = getLogger()
-# Load all accounts
-logger.debug(CONFIG)
+logger.debug("Loading up modules...")
+modules = {}
+
+# Load up modules
+for plugin in CONFIG["modules"]:
+ name = plugin['name']
+ class_name = plugin['class']
+ logger.debug(f"Installing plugin: [{name}]")
+ try:
+ module = import_module(name)
+ logger.debug(" -Loaded module")
+ class_object = getattr(module, class_name)
+ logger.debug(" -Loaded class")
+
+ if not Messenger in class_object.__bases__:
+ raise NotImplementedError
+ else:
+ logger.debug(" -Plugin-Class is valid!")
+ except Exception as err:
+ logger.debug(err)
+ logger.debug(f" -Failed to load {name}... Skiping it!")
+ else:
+ modules[name] = None
+ logger.debug(f" -Installed {name}")
+
+# Load all accounts
+logger.debug("Loading up accounts...")
+for account in CONFIG["accounts"]:
+ logger.debug(f" {account['name']}: Loading up module {account['module']}")
-[accounts]
-[accounts.sms]
-type = "twillio"
+[[modules]]
+name = "howl.sms"
+class = "TwilioSMS"
+
+[[accounts]]
+name = "sms"
+module = "twilio"
account = ""
token = ""
number = ""
-[options]
-[options.logger]
-version = 1
-
-[options.logger.root]
-handlers = ["console"]
-level = 10 #DEBUG
-
-[options.logger.formatters.brief]
-format = "%(name)-12s %(levelname)-8s %(message)s"
-
-[options.logger.handlers.console]
-class = "logging.StreamHandler"
-formatter = "brief"
-level = 10 #DEBUG
+[[accounts]]
+name = "bar"
+module = "mock"
+[options]
[options.editor]
path = "vim"
mode = "file"