Exemplo n.º 1
0
 def validate_xively_section(self):
     """
     This function validates the xively section out of the configuration
     """
     # TODO: implement xively section validation
     # xively_section = self.json_config._xively
     EventLogger.warning("Xively validation is not yet supported")
 def validate_xively_section(self):
     """
     This function validates the xively section out of the configuration
     """
     # TODO: implement xively section validation
     # xively_section = self.json_config._xively
     EventLogger.warning("Xively validation is not yet supported")
Exemplo n.º 3
0
    def _job(self):
        try:
            # check for datalogger object
            if AbstractJob._job(self):
                return

            EventLogger.debug(self._job_name + " Started")
            csv_writer = CSVWriter(self._datalogger.csv_file_name)

            while True:
                if not self._datalogger.data_queue[self.name].empty():
                    csv_data = self._get_data_from_queue()
                    #EventLogger.debug(self._job_name + " -> " + str(csv_data))
                    if not csv_writer.write_data_row(csv_data):
                        EventLogger.warning(self._job_name + " Could not write csv row!")

                if not self._exit_flag and self._datalogger.data_queue[self.name].empty():
                    time.sleep(self._datalogger.job_sleep)

                if self._exit_flag and self._datalogger.data_queue[self.name].empty():
                    exit_return_value = csv_writer.close_file()
                    if exit_return_value:
                        EventLogger.debug(self._job_name + " Closed his csv_writer")
                    else:
                        EventLogger.debug(
                            self._job_name + " Could NOT close his csv_writer! EXIT_RETURN_VALUE=" + str(exit))
                    EventLogger.debug(self._job_name + " Finished")

                    self._remove_from_data_queue()
                    break

        except Exception as e:
            EventLogger.critical(self._job_name + " " + str(e))
            self.stop()
Exemplo n.º 4
0
 def _remove_from_data_queue(self):
     try:
         self._datalogger.data_queue.pop(self.name)
     except KeyError as key_err:
         EventLogger.warning("Job:" + self.name +
                             " was not in the DataQueue! -> " +
                             str(key_err))
Exemplo n.º 5
0
    def btn_save_config_clicked(self):
        """
            Opens a FileSelectionDialog and saves the current config.
        """
        conf = GuiConfigHandler.create_config_file(self)
        fn = QtGui.QFileDialog.getSaveFileName(self,
                                               'Save  Config-File',
                                               os.getcwd(),
                                               filter='*.json')

        if fn == "":
            # cancel
            EventLogger.debug("Cancelled load Config.")
            return

        try:
            with open(fn, 'w') as outfile:
                json.dump(conf, outfile, sort_keys=True, indent=2)
        except Exception as e1:
            EventLogger.warning("Load Config - Exception: " + str(e1))
            QMessageBox.warning(
                self, 'Error',
                'Could not save the Config-File! Look at the Log-File for further information.',
                QMessageBox.Ok)
            return

        QMessageBox.information(self, 'Success', 'Config-File saved!',
                                QMessageBox.Ok)
        EventLogger.info("Config-File saved to: " + str(fn))
Exemplo n.º 6
0
    def btn_load_config_clicked(self):
        """
            Opens a FileSelectionDialog and loads the selected config.
        """
        fn = QtGui.QFileDialog.getOpenFileName(self, "Open Config-File...", os.getcwd(), "JSON-Files (*.json)")

        if fn == "":
            # cancel
            EventLogger.debug("Cancelled save Config.")
            return

        config_json = None
        try:
            with codecs.open(fn, 'r', 'UTF-8') as content_file:
                try:
                    config_json = json.load(content_file)

                except ValueError as e:
                    EventLogger.warning("Load Config - Cant parse the configuration file: " + str(e))
        except Exception as e1:
            EventLogger.warning("Load Config - Exception: " + str(e1))
            return

        EventLogger.info("Loaded Config-File from: " + str(fn))

        # devices
        config_blueprint = GuiConfigHandler.load_devices(config_json)
        if config_blueprint is None:
            return

        self.create_tree_items(config_blueprint)
        # general_section
        from brickv.data_logger.configuration_validator import ConfigurationReader

        self.update_setup_tab(config_json[ConfigurationReader.GENERAL_SECTION])
Exemplo n.º 7
0
    def _job(self):
        try:
            # check for datalogger object
            if AbstractJob._job(self):
                return

            EventLogger.debug(self._job_name + " Started")
            csv_writer = CSVWriter(self._datalogger.csv_file_name)

            while True:
                if not self._datalogger.data_queue[self.name].empty():
                    csv_data = self._get_data_from_queue()
                    #EventLogger.debug(self._job_name + " -> " + str(csv_data))
                    if not csv_writer.write_data_row(csv_data):
                        EventLogger.warning(self._job_name + " Could not write csv row!")

                if not self._exit_flag and self._datalogger.data_queue[self.name].empty():
                    time.sleep(self._datalogger.job_sleep)

                if self._exit_flag and self._datalogger.data_queue[self.name].empty():
                    exit_return_value = csv_writer.close_file()
                    if exit_return_value:
                        EventLogger.debug(self._job_name + " Closed his csv_writer")
                    else:
                        EventLogger.debug(
                            self._job_name + " Could NOT close his csv_writer! EXIT_RETURN_VALUE=" + str(exit))
                    EventLogger.debug(self._job_name + " Finished")

                    self._remove_from_data_queue()
                    break

        except Exception as e:
            EventLogger.critical(self._job_name + " " + str(e))
            self.stop()
Exemplo n.º 8
0
 def _job(self):
     # check for datalogger object
     if self._datalogger is None:
         EventLogger.warning(
             self.name +
             " started but did not get a DataLogger Object! No work could be done."
         )
         return True
     return False
Exemplo n.º 9
0
 def __init__(self,
              datalogger=None,
              group=None,
              name="XivelyJob",
              args=(),
              kwargs=None,
              verbose=None):
     super(XivelyJob, self).__init__()
     EventLogger.warning(self._job_name + " Is not supported!")
     raise Exception("XivelyJob not yet implemented!")
def prevent_key_error(dict_src, key):
    """
    This function returns an empty array if there is no such
    section in the configuration file
    key -- section key
    """
    result = []
    try:
        result = dict_src[key]
    except KeyError:
        EventLogger.warning("json configuration file has no [" + key + "] section")
    return result
Exemplo n.º 11
0
def prevent_key_error(dict_src, key):
    """
    This function returns an empty array if there is no such
    section in the configuration file
    key -- section key
    """
    result = []
    try:
        result = dict_src[key]
    except KeyError:
        EventLogger.warning("json configuration file has no [" + key +
                            "] section")
    return result
Exemplo n.º 12
0
    def create_tree_items(self, blueprint):
        """
            Create the device tree with the given blueprint.
            Shows all possible devices, if the view_all Flag is True.
        """
        self.tree_devices.clear()
        self.tree_devices.setSortingEnabled(False)

        try:
            for dev in blueprint:
                self.__add_item_to_tree(dev)
            EventLogger.debug("Device Tree created.")

        except Exception as e:
            EventLogger.warning("DeviceTree - Exception while creating the Tree: " + str(e))

        self.tree_devices.sortItems(0, QtCore.Qt.AscendingOrder)
        self.tree_devices.setSortingEnabled(True)
Exemplo n.º 13
0
    def create_tree_items(self, blueprint):
        """
            Create the device tree with the given blueprint.
            Shows all possible devices, if the view_all Flag is True.
        """
        self.tree_devices.clear()
        self.tree_devices.setSortingEnabled(False)

        try:
            for dev in blueprint:
                self.__add_item_to_tree(dev)
            EventLogger.debug("Device Tree created.")

        except Exception as e:
            EventLogger.warning(
                "DeviceTree - Exception while creating the Tree: " + str(e))

        self.tree_devices.sortItems(0, QtCore.Qt.AscendingOrder)
        self.tree_devices.setSortingEnabled(True)
Exemplo n.º 14
0
    def initialize_loggable_devices(self):
        """
        This function creates the actual objects for each device out of the configuration
        """
        # start the timers
        for device in self._config['devices']:
            if len(device['uid']) == 0:
                EventLogger.warning('Ignoring "{0}" with empty UID'.format(device['name']))
                continue

            try:
                decoded_uid = base58decode(device['uid'])
            except:
                EventLogger.warning('Ignoring "{0}" with invalid UID: {1}'.format(device['name'], device['uid']))
                continue

            if decoded_uid < 1 or decoded_uid > 0xFFFFFFFF:
                EventLogger.warning('Ignoring "{0}" with out-of-range UID: {1}'.format(device['name'], device['uid']))
                continue

            try:
                loggable_device = DeviceImpl(device, self)
                loggable_device.start_timer()
            except Exception as e:
                msg = "A critical error occur: " + str(e)
                self.stop()
                raise DataLoggerException(DataLoggerException.DL_CRITICAL_ERROR, msg)

            self.loggable_devices.append(loggable_device)

        self.apply_options()
Exemplo n.º 15
0
    def btn_load_config_clicked(self):
        """
            Opens a FileSelectionDialog and loads the selected config.
        """
        fn = QtGui.QFileDialog.getOpenFileName(self, "Open Config-File...",
                                               os.getcwd(),
                                               "JSON-Files (*.json)")

        if fn == "":
            # cancel
            EventLogger.debug("Cancelled save Config.")
            return

        config_json = None
        try:
            with codecs.open(fn, 'r', 'UTF-8') as content_file:
                try:
                    config_json = json.load(content_file)

                except ValueError as e:
                    EventLogger.warning(
                        "Load Config - Cant parse the configuration file: " +
                        str(e))
        except Exception as e1:
            EventLogger.warning("Load Config - Exception: " + str(e1))
            return

        EventLogger.info("Loaded Config-File from: " + str(fn))

        # devices
        config_blueprint = GuiConfigHandler.load_devices(config_json)
        if config_blueprint is None:
            return

        self.create_tree_items(config_blueprint)
        # general_section
        from brickv.data_logger.configuration_validator import ConfigurationReader

        self.update_setup_tab(config_json[ConfigurationReader.GENERAL_SECTION])
Exemplo n.º 16
0
    def btn_save_config_clicked(self):
        """
            Opens a FileSelectionDialog and saves the current config.
        """
        conf = GuiConfigHandler.create_config_file(self)
        fn = QtGui.QFileDialog.getSaveFileName(self, 'Save  Config-File', os.getcwd(), filter='*.json')

        if fn == "":
            # cancel
            EventLogger.debug("Cancelled load Config.")
            return

        try:
            with open(fn, 'w') as outfile:
                json.dump(conf, outfile, sort_keys=True, indent=2)
        except Exception as e1:
            EventLogger.warning("Load Config - Exception: " + str(e1))
            QMessageBox.warning(self, 'Error',
                                'Could not save the Config-File! Look at the Log-File for further information.',
                                QMessageBox.Ok)
            return

        QMessageBox.information(self, 'Success', 'Config-File saved!', QMessageBox.Ok)
        EventLogger.info("Config-File saved to: " + str(fn))
Exemplo n.º 17
0
    def initialize_loggable_devices(self):
        """
        This function creates the actual objects for each device out of the configuration
        """
        # start the timers
        for device in self._config['devices']:
            if len(device['uid']) == 0:
                EventLogger.warning('Ignoring "{0}" with empty UID'.format(
                    device['name']))
                continue

            try:
                decoded_uid = base58decode(device['uid'])
            except:
                EventLogger.warning(
                    'Ignoring "{0}" with invalid UID: {1}'.format(
                        device['name'], device['uid']))
                continue

            if decoded_uid < 1 or decoded_uid > 0xFFFFFFFF:
                EventLogger.warning(
                    'Ignoring "{0}" with out-of-range UID: {1}'.format(
                        device['name'], device['uid']))
                continue

            try:
                loggable_device = DeviceImpl(device, self)
                loggable_device.start_timer()
            except Exception as e:
                msg = "A critical error occur: " + str(e)
                self.stop()
                raise DataLoggerException(
                    DataLoggerException.DL_CRITICAL_ERROR, msg)

            self.loggable_devices.append(loggable_device)

        self.apply_options()
Exemplo n.º 18
0
 def _remove_from_data_queue(self):
     try:
         self._datalogger.data_queue.pop(self.name)
     except KeyError as key_err:
         EventLogger.warning("Job:" + self.name + " was not in the DataQueue! -> " + str(key_err))
Exemplo n.º 19
0
 def __init__(self, datalogger=None, group=None, name="XivelyJob", args=(), kwargs=None, verbose=None):
     super(XivelyJob, self).__init__()
     EventLogger.warning(self._job_name + " Is not supported!")
     raise Exception("XivelyJob not yet implemented!")
Exemplo n.º 20
0
 def _job(self):
     # check for datalogger object
     if self._datalogger is None:
         EventLogger.warning(self.name + " started but did not get a DataLogger Object! No work could be done.")
         return True
     return False
Exemplo n.º 21
0
 def _job(self):
     EventLogger.warning(self._job_name + " Is not supported!")
     raise Exception("XivelyJob._job not yet implemented!")
Exemplo n.º 22
0
 def _job(self):
     EventLogger.warning(self._job_name + " Is not supported!")
     raise Exception("XivelyJob._job not yet implemented!")