Commit 08a995d3 authored by Valentin Valls's avatar Valentin Valls
Browse files

Create alias for default BLISS plugin class loaded

parent 0394fe65
......@@ -9,6 +9,10 @@ import re
from importlib.util import find_spec
_ALIAS_TO_MODULE_NAME = {"Lima": "bliss.controllers.lima.lima_base"}
"""Alias defined for default BLISS controllers"""
def camel_case_to_snake_style(name):
s1 = re.sub("(.)([A-Z][a-z]+)", r"\1_\2", name)
return re.sub("([a-z0-9])([A-Z])", r"\1_\2", s1).lower()
......@@ -18,19 +22,27 @@ def find_class(cfg_node, base_path="bliss.controllers"):
return find_class_and_node(cfg_node, base_path)[0]
def find_class_and_node(cfg_node, base_path="bliss.controllers"):
klass_name, node = cfg_node.get_inherited_value_and_node("class")
if klass_name is None:
raise KeyError("class")
def resolve_module_name(klass_name, node, base_path):
if "package" in node:
module_name = node["package"]
result = node["package"]
elif "module" in node:
module_name = "%s.%s" % (base_path, node["module"])
module_name = node["module"]
result = "%s.%s" % (base_path, module_name)
elif base_path == "bliss.controllers" and klass_name in _ALIAS_TO_MODULE_NAME:
# For BLISS base class, there is alias to the right module
# In order to allow to move them without changing the configuration
result = _ALIAS_TO_MODULE_NAME.get(klass_name)
else:
# discover module and class name
module_name = "%s.%s" % (base_path, klass_name.lower())
result = "%s.%s" % (base_path, klass_name.lower())
return result
def find_class_and_node(cfg_node, base_path="bliss.controllers"):
klass_name, node = cfg_node.get_inherited_value_and_node("class")
if klass_name is None:
raise KeyError("class")
module_name = resolve_module_name(klass_name, node, base_path)
try:
module = __import__(module_name, fromlist=[""])
except ModuleNotFoundError as e:
......
......@@ -4,5 +4,3 @@
#
# Copyright (c) 2015-2020 Beamline Control Unit, ESRF
# Distributed under the GNU LGPLv3. See LICENSE for more info.
from .lima_base import Lima
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment