Beispiel #1
0
    def __init__(self, queue: Queue, thread_event: Event) -> None:
        Thread.__init__(self)
        self._observer_publish_queue = queue
        self._thread_ready = thread_event
        self._observer_notify_queue = Queue(maxsize=100)
        self.log = Logging(owner=__file__, config=True)

        self.config = ConfigurationParser().get_config()
        self.poll_interval = self.config["device_manager"]["poll_interval"]
        self.device_map_lock = Lock()
Beispiel #2
0
    def __init__(self) -> None:
        self.log = Logging(owner=__file__, config=True)
        self.config = ConfigurationParser().get_config()

        events = self.config['framework']['events']
        self.subject = Subject(events)

        self.observer_queue = Queue(maxsize=100)
        self._thread_started_event = Event()

        self.init_observers()
        self.attach_observers()
        self.start_observer_threats()
Beispiel #3
0
    def __init__(self, queue, thread_event: Event):
        Thread.__init__(self)
        self.config: dict = ConfigurationParser().get_config()
        self.log = Logging(owner=__file__, config=True)

        self._observer_notify_queue: Queue = Queue(maxsize=100)
        self._observer_publish_queue: Queue = queue
        self._thread_ready: Event = thread_event

        config = self.get_mqtt_config()
        self.mqtt_client = MqttClient(config=config,
                                      connect_callback=self.on_connect,
                                      message_callback=self.on_message)
        if not self.mqtt_client.connect():
            # todo: unscribcribe from subject
            self.log.critical("TODO: Unsubscribe itself form framework")
    def __init__(self,
                 owner,
                 log_mode='test',
                 min_log_lvl=LogLevels.debug,
                 config=False):
        self.config = ConfigurationParser().get_config()
        self.owner = self._path_leaf(path=owner)
        self.log_mode = log_mode
        self.min_log_lvl = min_log_lvl

        if config:
            self.log_mode = self.config['general']['logging_mode']
            self.min_log_lvl = self._get_log_lvl_from_config()

        if self.log_mode == 'db':
            self.db = DbLogging()
            self.db.connect()

        if self.log_mode == 'file':
            self.filename = self._get_filename()
class TestConfigurationParser(TestCase):
    conf_parser = ConfigurationParser()

    def test_get_path_to_conf_file(self):
        file_path = self.conf_parser._get_path_to_conf_file()
        is_file = path.isfile(file_path)
        self.assertTrue(is_file)

    def test_yml_to_dict_mock_conf_file(self):
        test_content = {'a': 123, 'b': 456}
        filename = 'test.yaml'
        yml_path = Path.cwd().joinpath(filename)
        with open(yml_path, 'w') as file:
            yaml.dump(test_content, file)
        result = self.conf_parser._yml_to_dict(file_path=yml_path)
        self.assertDictEqual(result, test_content)
        remove(yml_path)

    def test_as_named_tuple(self):
        config = self.conf_parser.as_named_tuple()
        is_named_tuple = isinstance_namedtuple(config)
        self.assertTrue(is_named_tuple)
Beispiel #6
0
 def __init__(self):
     self.config = ConfigurationParser().get_config()
     self.collection = None
     self.mongo_db = None
Beispiel #7
0
 def __init__(self, db_name: str) -> None:
     self.config = ConfigurationParser().get_config()
     self.log = Logging(owner=__file__, config=True)
     self.mongo_db = self.connect_to_db(db_name=db_name)