|
@@ -0,0 +1,84 @@
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+class Configure(object):
|
|
|
+ """
|
|
|
+ Configure BeeWatch from a dict
|
|
|
+ This class is inspired by logging.config
|
|
|
+ (https://github.com/python/cpython/blob/3.6/Lib/logging/config.py)
|
|
|
+ """
|
|
|
+ def __init__(self,config):
|
|
|
+ super(Configure,self).__init__()
|
|
|
+ self.configure(config)
|
|
|
+ self.config = {}
|
|
|
+ def configure(self,config):
|
|
|
+ config_keys = ["controllers","commands"]
|
|
|
+ for name,properties in config.pop("controllers"):
|
|
|
+ target = properties.pop("target")
|
|
|
+ if not callable(target):
|
|
|
+ target = self.str_to_callable(target)
|
|
|
+ self.retconf["controllers"][name] = target(**ctrl)
|
|
|
+ for name,function in config.pop("commands"):
|
|
|
+ if not callable(function):
|
|
|
+ function = self.str_to_callable()
|
|
|
+ self.retconf[commands][name] = function
|
|
|
+ def str_to_callable(self,dotted_str):
|
|
|
+ parts = dotted_str.split(".")
|
|
|
+ next_to_import = parts.pop(0)
|
|
|
+ converted = None
|
|
|
+ for p in parts:
|
|
|
+ if not hasattr(imported,p):
|
|
|
+ __import__(next_to_import)
|
|
|
+ converted = getattr(converted,p)
|
|
|
+ next_to_import += "." + p
|
|
|
+ return converted
|
|
|
+ for n in name:
|
|
|
+ used = used + '.' + n
|
|
|
+ try:
|
|
|
+ found = getattr(found, n)
|
|
|
+ except AttributeError:
|
|
|
+ __import__(used)
|
|
|
+ found = getattr(found, n)
|
|
|
+ return found
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|