# Path: pyfusion/conf/utils.py
# def kwarg_config_handler(component_type, component_name, **kwargs):
#     for config_var in pyfusion.config.pf_options(component_type, component_name):
#             if not config_var in kwargs.keys():
#                 kwargs[config_var] = pyfusion.config.pf_get(component_type,
#                                                    component_name, config_var)
#     return kwargs
# 
# def import_from_str(string_value):
#     # TODO: make shortcuts for loading from within pyfusion
#     split_val = string_value.split('.')
#     val_module = __import__('.'.join(split_val[:-1]),
#                             globals(), locals(),
#                             [split_val[-1]])
#     return val_module.__dict__[split_val[-1]]
# 
# def get_config_as_dict(component_type, component_name):
#     config_option_list = pyfusion.config.pf_options(component_type, component_name)
#     config_map = lambda x: (x, pyfusion.config.pf_get(component_type, component_name, x))
#     return dict(map(config_map, config_option_list))
# 
# Path: pyfusion/orm/utils.py
# def orm_register():
#     def reg_item(orm_func):
#         pyfusion.orm_manager.add_reg_func(orm_func)
#         return orm_func
#     return reg_item


from pyfusion.conf.utils import kwarg_config_handler, import_from_str, get_config_as_dict
from pyfusion.orm.utils import orm_register
    from sqlalchemy import Table, Column, Integer, String
    from sqlalchemy.orm import mapper
import pyfusion
        self.__dict__.update(kwargs)
        self.name = config_name

        #### attach acquisition
        if hasattr(self, 'acq_name'):
            acq_class_str = pyfusion.config.pf_get('Acquisition',
                                          self.acq_name, 'acq_class')
            self.acquisition = import_from_str(acq_class_str)(self.acq_name)
            # shortcut
            self.acq = self.acquisition
        else:
            pyfusion.logging.warning(
                "No acquisition class specified for device")



@orm_register()
def orm_load_devices(man):
    man.device_table = Table('devices', man.metadata,
                         Column('id', Integer, primary_key=True),
                         Column('name', String(32), unique=True),
                         Column('class_name', String(32), unique=True))

    #mapper(Device, man.device_table)
    mapper(Device, man.device_table,
           polymorphic_on=man.device_table.c.class_name, polymorphic_identity='Device')

def getDevice(device_name):
    """Find and instantiate Device (sub)class from config."""
    dev_class_str = pyfusion.config.pf_get('Device', device_name, 'dev_class')

# Path: pyfusion/conf/utils.py
# def kwarg_config_handler(component_type, component_name, **kwargs):
#     for config_var in pyfusion.config.pf_options(component_type, component_name):
#             if not config_var in kwargs.keys():
#                 kwargs[config_var] = pyfusion.config.pf_get(component_type,
#                                                    component_name, config_var)
#     return kwargs
# 
# def import_from_str(string_value):
#     # TODO: make shortcuts for loading from within pyfusion
#     split_val = string_value.split('.')
#     val_module = __import__('.'.join(split_val[:-1]),
#                             globals(), locals(),
#                             [split_val[-1]])
#     return val_module.__dict__[split_val[-1]]
# 
# def get_config_as_dict(component_type, component_name):
#     config_option_list = pyfusion.config.pf_options(component_type, component_name)
#     config_map = lambda x: (x, pyfusion.config.pf_get(component_type, component_name, x))
#     return dict(map(config_map, config_option_list))
# 
# Path: pyfusion/orm/utils.py
# def orm_register():
#     def reg_item(orm_func):
#         pyfusion.orm_manager.add_reg_func(orm_func)
#         return orm_func
#     return reg_item


# Path: pyfusion/devices/base.py
from pyfusion.conf.utils import kwarg_config_handler, import_from_str, get_config_as_dict
from pyfusion.orm.utils import orm_register
    from sqlalchemy import Table, Column, Integer, String
    from sqlalchemy.orm import mapper
import pyfusion

        self.__dict__.update(kwargs)
        self.name = config_name

        #### attach acquisition
        if hasattr(self, 'acq_name'):
            acq_class_str = pyfusion.config.pf_get('Acquisition',
                                          self.acq_name, 'acq_class')
            self.acquisition = import_from_str(acq_class_str)(self.acq_name)
            # shortcut
            self.acq = self.acquisition
        else:
            pyfusion.logging.warning(
                "No acquisition class specified for device")



@orm_register()
def orm_load_devices(man):
    man.device_table = Table('devices', man.metadata,
                         Column('id', Integer, primary_key=True),
                         Column('name', String(32), unique=True),
                         Column('class_name', String(32), unique=True))

    #mapper(Device, man.device_table)
    mapper(Device, man.device_table,
           polymorphic_on=man.device_table.c.class_name, polymorphic_identity='Device')

def getDevice(device_name):
    """Find and instantiate Device (sub)class from config."""
    dev_class_str = pyfusion.config.pf_get('Device', device_name, 'dev_class')

    return import_from_str(dev_class_str)(device_name)