diff options
author | Kevin O'Connor <kevin@koconnor.net> | 2018-02-03 12:53:11 -0500 |
---|---|---|
committer | Kevin O'Connor <kevin@koconnor.net> | 2018-02-03 12:53:11 -0500 |
commit | f4bfce260a2ea38209646957d7c423db5bb54faa (patch) | |
tree | 94bbfb8b1ce3555ccc1ef773f3e5399c7f141c7a /klippy/klippy.py | |
parent | 7e3adde542b178bb709d4de0a3dcb73e5c2afd43 (diff) | |
download | kutter-f4bfce260a2ea38209646957d7c423db5bb54faa.tar.gz kutter-f4bfce260a2ea38209646957d7c423db5bb54faa.tar.xz kutter-f4bfce260a2ea38209646957d7c423db5bb54faa.zip |
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 <kevin@koconnor.net>
Diffstat (limited to 'klippy/klippy.py')
-rw-r--r-- | klippy/klippy.py | 10 |
1 files changed, 8 insertions, 2 deletions
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'] |