From f4bfce260a2ea38209646957d7c423db5bb54faa Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Sat, 3 Feb 2018 12:53:11 -0500 Subject: klippy: Introduce load_config_prefix() for modules that take parameters Use both load_config() and load_config_prefix() functions when dynamically loading a module from the extras directory - if the config section name has parameters in it then use load_config_prefix(). Signed-off-by: Kevin O'Connor --- klippy/klippy.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'klippy/klippy.py') diff --git a/klippy/klippy.py b/klippy/klippy.py index 12f82ebe..fba527a2 100644 --- a/klippy/klippy.py +++ b/klippy/klippy.py @@ -185,13 +185,19 @@ class Printer: def _try_load_module(self, config, section): if section in self.objects: return - module_name = section.split()[0] + module_parts = section.split() + module_name = module_parts[0] py_name = os.path.join(os.path.dirname(__file__), 'extras', module_name + '.py') if not os.path.exists(py_name): return mod = importlib.import_module('extras.' + module_name) - self.objects[section] = mod.load_config(config.getsection(section)) + init_func = 'load_config' + if len(module_parts) > 1: + init_func = 'load_config_prefix' + init_func = getattr(mod, init_func, None) + if init_func is not None: + self.objects[section] = init_func(config.getsection(section)) def _read_config(self): fileconfig = ConfigParser.RawConfigParser() config_file = self.start_args['config_file'] -- cgit v1.2.3-70-g09d2