Ejemplo n.º 1
0
    def writer(self):
        """ Reads from the socket and writes to the serial port. """
        while not self.__stopped:
            try:
                try:
                    data = self.__connection.recv(1024)
                    if not data:
                        LOGGER.info(
                            'Stopping maintenance mode due to no data.')
                        break
                    if data.startswith('exit'):
                        LOGGER.info('Stopping maintenance mode due to exit.')
                        break
                    self.__gateway_api.send_maintenance_data(data)
                except Exception as exception:
                    if System.handle_socket_exception(self.__connection,
                                                      exception, LOGGER):
                        continue
                    else:
                        break
            except:
                LOGGER.error('Exception in maintenance mode: %s\n',
                             traceback.format_exc())
                break

        self.__stopped = True
        self.__reader_thread.join()
Ejemplo n.º 2
0
    def _handle_connection(self):
        """
        Handles one incoming connection.
        """
        try:
            self._connection.settimeout(1)
            self._connection.sendall(
                'Activating maintenance mode, waiting for other actions to complete ...\n'
            )
            self._activate()
            self._connection.sendall('Connected\n')
            while self._maintenance_communicator.is_active():
                try:
                    try:
                        data = self._connection.recv(1024)
                        if not data:
                            logger.info(
                                'Stopping maintenance mode due to no data.')
                            break
                        if data.startswith('exit'):
                            logger.info(
                                'Stopping maintenance mode due to exit.')
                            break

                        self._maintenance_communicator.write(data)
                    except Exception as exception:
                        if System.handle_socket_exception(
                                self._connection, exception, logger):
                            continue
                        else:
                            logger.exception(
                                'Unexpected exception receiving connection data'
                            )
                            break
                except Exception:
                    logger.exception('Exception in maintenance mode')
                    break
        except InMaintenanceModeException:
            self._connection.sendall('Maintenance mode already active.\n')
        finally:
            self._deactivate()
            logger.info('Maintenance mode deactivated')
            self._connection.close()
            self._connection = None
Ejemplo n.º 3
0
    def writer(self):
        """ Reads from the socket and writes to the serial port. """
        while not self.__stopped:
            try:
                try:
                    data = self.__connection.recv(1024)
                    if not data:
                        LOGGER.info('Stopping maintenance mode due to no data.')
                        break
                    if data.startswith('exit'):
                        LOGGER.info('Stopping maintenance mode due to exit.')
                        break
                    self.__gateway_api.send_maintenance_data(data)
                except Exception as exception:
                    if System.handle_socket_exception(self.__connection, exception, LOGGER):
                        continue
                    else:
                        break
            except Exception:
                LOGGER.error('Exception in maintenance mode: %s\n', traceback.format_exc())
                break

        self.__stopped = True
        self.__reader_thread.join()