Commit 06d3b610 authored by Matias Guijarro's avatar Matias Guijarro

config: bliss plugin: try to find module name (snake style) from camel case class name

parent 4af22697
......@@ -5,6 +5,13 @@
# Copyright (c) 2015-2019 Beamline Control Unit, ESRF
# Distributed under the GNU LGPLv3. See LICENSE for more info.
import re
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()
def find_class(cfg_node, base_path="bliss.controllers"):
return find_class_and_node(cfg_node, base_path)[0]
......@@ -23,7 +30,12 @@ def find_class_and_node(cfg_node, base_path="bliss.controllers"):
# discover module and class name
module_name = "%s.%s" % (base_path, klass_name.lower())
module = __import__(module_name, fromlist=[""])
try:
module = __import__(module_name, fromlist=[""])
except ModuleNotFoundError:
module_name = "%s.%s" % (base_path, camel_case_to_snake_style(klass_name))
module = __import__(module_name, fromlist=[""])
try:
klass = getattr(module, klass_name)
except AttributeError:
......
......@@ -320,8 +320,6 @@ class SimulationCounter(Counter, LogMixin):
def __init__(self, name, config):
Counter.__init__(self, name)
session.get_current().map.register(self)
self.config = config
self.acq_device = None
self.scan_pars = None
......@@ -378,10 +376,3 @@ class SimulationCounter(Counter, LogMixin):
# If no controller, a warning is emited in `master_to_devices_mapping()`
# def controller(self):
# return None
# class or function ???
# * Receives config dict from beacon.
# * Returns object which is an instance of SimulationCounter to use in the session.
def simulation_counter(name, config):
return SimulationCounter(name, config)
-
name: sim_ct_gauss
plugin: bliss
class: simulation_counter
class: SimulationCounter
distribution: GAUSSIAN
mu_offset: 0.0
sigma_factor: 1.0
......@@ -10,7 +10,7 @@
-
name: sim_ct_gauss_noise
plugin: bliss
class: simulation_counter
class: SimulationCounter
distribution: GAUSSIAN
mu_offset: -1.0
sigma_factor: 0.4
......@@ -19,14 +19,14 @@
-
name: sim_ct_flat_12
plugin: bliss
class: simulation_counter
class: SimulationCounter
distribution: FLAT
height_factor: 12.0
noise_factor: 0.0
-
name: sim_ct_rand_12
plugin: bliss
class: simulation_counter
class: SimulationCounter
distribution: FLAT
height_factor: 12.0
noise_factor: 1.01
\ No newline at end of file
noise_factor: 1.01
Markdown is supported
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