Example #1
0
def start(cntx, resources, url):
    full_name = 'quactrl.rest.' + class_name
    Resource = get_class(full_name)

    app = App()
    app.add_resource(Resource(), name)
    app.run()
Example #2
0
 def construct_device_container(dev_definitions):
     devices = DynamicContainer()
     for definition in dev_definitions:
         provider =  _providers[definition['strategy']](
             get_class(definition['class']),
         )
         setattr(devices, definition['name'],)
     return devices
Example #3
0
 def Device(self):
     if not hasattr(self, '_Device'):
         device_class = self.pars.get('device_class')
         self._Device = None
         if device_class is not None:
             self._Device = get_class(device_class) if device_class else None
             self.kwargs = self.pars.get('kwargs', {})
     return self._Device
Example #4
0
    def Device(self):
        if not hasattr(self, '_Device'):
            device_class = self.pars.get('device_class')
            if device_class is None:
                self._Device, self.kwargs = self._find_Device()
            else:
                self._Device = get_class(device_class)
                self.kwargs = self.pars.get('kwargs', {})

        return self._Device
Example #5
0
    def __init__(self, module_name, connection_string=None, **kwargs):
        super().__init__()
        self.connection_string = connection_string
        self.module_name = 'quactrl.data.' + module_name

        self.db = get_class('{}.Db'.format(self.module_name))(
            connection_string, **kwargs)

        self.Session = providers.ThreadLocalSingleton(self.db.Session)
        self._load_repos()
Example #6
0
    def _inject_provider(self, dev_name):
        if not hasattr(self, dev_name):
            config = self._devices[dev_name]

            Provider = self._providers[config['strategy']]
            DeviceClass = get_class(config['class'])

            args = config.get('args', [])
            for index, value in enumerate(args):
                if type(value) is str and value and value[0] == '>':
                    args[index] = self._inject_provider(value[1:])

            kwargs = config.get('kwargs', {})
            for key in kwargs.keys():
                value = kwargs[key]
                if type(value) is str and value and value[0] == '>':
                    kwargs[key] = self._inject_provider(value[1:])

            setattr(self, dev_name, Provider(DeviceClass, *args, **kwargs))

        return getattr(self, dev_name)
Example #7
0
def test_get_class():
    assert get_class('tests.unit.helpers.test_init.FakeClass') == FakeClass
Example #8
0
    def _create_device(self, pars):
        class_name = pars.pop('class_name')

        Device = get_class(class_name)
        return Device(**pars)
Example #9
0
 def _get_class(self, name):
     full_class_name = '{}.{}Repo'.format(self.module_name, name)
     ResultClass = get_class(full_class_name)
     return ResultClass