config plugin: rename khoros to bliss

parent ca3c4df7
khoros
Bliss
======
The bliss control library.
\ No newline at end of file
from __future__ import absolute_import
def __find_class(cfg_node):
klass_name = cfg_node['class']
if 'package' in cfg_node:
module_name = cfg_node['package']
elif 'module' in cfg_node:
module_name = 'bliss.controllers.%s' % cfg_node['module']
else:
# discover module and class name
module_name = 'bliss.controllers.%s' % klass_name
try:
module = __import__(module_name, fromlist=[None])
except ImportError: # try in file in lower case
module_name = 'bliss.controllers.%s' % klass_name.lower()
module = __import__(module_name, fromlist=[None])
try:
klass = getattr(module, klass_name)
except AttributeError: # try with camelcase
klass_name = ''.join((x.capitalize() for x in klass_name.split('_')))
module = __import__(module_name, fromlist=[None])
klass = getattr(module, klass_name)
return klass
def create_objects_from_config_node(config, item_cfg_node):
klass = __find_class(item_cfg_node)
item_name = item_cfg_node["name"]
referenced_objects = dict()
for name, value in item_cfg_node.iteritems():
if isinstance(value, str) and value.startswith("$"):
# convert reference to item from config
item_cfg_node[name]=config.get(value)
referenced_objects[name]=item_cfg_node[name]
o = klass(item_name, item_cfg_node)
for name, object in referenced_objects.iteritems():
if hasattr(o, name):
continue
#raise RuntimeError("'%s` member would be shadowed by reference in yml config file." % name)
else:
setattr(o, name, object) #add_property(o, name, object)
return { item_name: o }
from __future__ import absolute_import
from warnings import warn
def __find_class(cfg_node):
klass_name = cfg_node['class']
warn('\nKhoros plugin is deprecated and will be removed soon. Use bliss plugin instead.', FutureWarning)
if 'package' in cfg_node:
module_name = cfg_node['package']
elif 'module' in cfg_node:
module_name = 'bliss.controllers.%s' % cfg_node['module']
else:
# discover module and class name
module_name = 'bliss.controllers.%s' % klass_name
try:
module = __import__(module_name, fromlist=[None])
except ImportError: # try in file in lower case
module_name = 'bliss.controllers.%s' % klass_name.lower()
module = __import__(module_name, fromlist=[None])
try:
klass = getattr(module, klass_name)
except AttributeError: # try with camelcase
klass_name = ''.join((x.capitalize() for x in klass_name.split('_')))
from .bliss import create_objects_from_config_node
module = __import__(module_name, fromlist=[None])
klass = getattr(module, klass_name)
return klass
def create_objects_from_config_node(config, item_cfg_node):
klass = __find_class(item_cfg_node)
item_name = item_cfg_node["name"]
referenced_objects = dict()
for name, value in item_cfg_node.iteritems():
if isinstance(value, str) and value.startswith("$"):
# convert reference to item from config
item_cfg_node[name]=config.get(value)
referenced_objects[name]=item_cfg_node[name]
o = klass(item_name, item_cfg_node)
for name, object in referenced_objects.iteritems():
if hasattr(o, name):
continue
#raise RuntimeError("'%s` member would be shadowed by reference in yml config file." % name)
else:
setattr(o, name, object) #add_property(o, name, object)
return { item_name: o }
......@@ -34,7 +34,7 @@ test_db = [('__init__.yml', 'synchrotron: ESRF\nbeamline: id30b\n'),
'-\n name: wcid30q\n class: wago\n controller_ip: 160.103.50.53\n mapping:\n -\n type: 750-517\n logical_names: _,_\n -\n type: 750-469\n logical_names: th_311_in, th_311_out\n -\n type: 750-469\n logical_names: th_111_in, th_111_out\n -\n type: 750-469\n logical_names: th_mask, _\n'),
('oh/transfocator.yml',
'name: tfmad\nclass: transfocator\ncontroller_ip: 160.103.50.57\nlenses: 7\npinhole: 2\n'),
('oh/__init__.yml', 'plugin: khoros\n'),
('oh/__init__.yml', 'plugin: bliss\n'),
('oh/bpms.yml',
'-\n name: wbvg\n class: tango_bpm\n uri: id30/id30b/wbvg\n-\n name: mbv1\n class: tango_bpm\n uri: id30/id30b/mbv1\n\n'),
('oh/motors/@iceid301/__init__.yml',
......@@ -81,13 +81,13 @@ class TestBeacon(unittest.TestCase):
self.assertEquals(self.cfg.get_config("m0").filename, "oh/motors/@iceid301/axes/m0.yml")
def testPlugin(self):
self.assertEquals(self.cfg.root["oh"].plugin, "khoros")
self.assertEquals(self.cfg.get_config("wcid30q").plugin, "khoros")
self.assertEquals(self.cfg.get_config("wbvg").plugin, "khoros")
self.assertEquals(self.cfg.get_config("mbv1").plugin, "khoros")
self.assertEquals(self.cfg.get_config("tfmad").plugin, "khoros")
self.assertEquals(self.cfg.get_config("m0").plugin, "khoros")
self.assertEquals(self.cfg.get_config("m1").plugin, "khoros")
self.assertEquals(self.cfg.root["oh"].plugin, "bliss")
self.assertEquals(self.cfg.get_config("wcid30q").plugin, "bliss")
self.assertEquals(self.cfg.get_config("wbvg").plugin, "bliss")
self.assertEquals(self.cfg.get_config("mbv1").plugin, "bliss")
self.assertEquals(self.cfg.get_config("tfmad").plugin, "bliss")
self.assertEquals(self.cfg.get_config("m0").plugin, "bliss")
self.assertEquals(self.cfg.get_config("m1").plugin, "bliss")
def testChildren(self):
root_node = self.cfg.root
......@@ -101,7 +101,7 @@ class TestBeacon(unittest.TestCase):
def test__init__(self):
root_node = self.cfg.root
self.assertEquals(root_node["beamline"], "id30b")
self.assertEquals(root_node["oh"]["plugin"], "khoros")
self.assertEquals(root_node["oh"]["plugin"], "bliss")
def test__init__arobase(self):
root_node = self.cfg.root
......
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