Esempio n. 1
0
    def process_message(self, client, command, message):
        client.nextBlockSize = 0

        log_debug('RECEIVE: command: %s, message: %s' % (command, message))
        if command in self.commands:
            self.commands[command](client, command, message)

        client.nextBlockSize = 0
Esempio n. 2
0
 def send_message(self, client, command, message=''):
     log_debug('SEND COMMAND (server): command %s, message %s' %
               (command, message))
     reply = QByteArray()
     stream = QDataStream(reply, QIODevice.WriteOnly)
     stream.setVersion(QDataStream.Qt_4_2)
     stream.writeUInt32(0)
     stream << QString(command) << QString(message)
     stream.device().seek(0)
     stream.writeUInt32(reply.size() - SIZEOF_UINT32)
     client.write(reply)
Esempio n. 3
0
    def send_message(self, command, message):
        self.request = QByteArray()
        stream = QDataStream(self.request, QIODevice.WriteOnly)
        stream.setVersion(QDataStream.Qt_4_2)
        stream.writeUInt32(0)

        log_debug('SEND: command %s, message %s' % (command, message))
        stream << QString(command) << QString(message)

        stream.device().seek(0)
        stream.writeUInt32(self.request.size() - SIZEOF_UINT32)
        self.socket.write(self.request)
        self.nextBlockSize = 0
        self.request = None
Esempio n. 4
0
    def read_server(self):
        stream = QDataStream(self.socket)
        stream.setVersion(QDataStream.Qt_4_2)
        while True:
            if self.nextBlockSize == 0:
                if self.socket.bytesAvailable() < SIZEOF_UINT32:
                    break
                self.nextBlockSize = stream.readUInt32()
            if self.socket.bytesAvailable() < self.nextBlockSize:
                break
            command = QString()
            message = QString()
            stream >> command >> message
            log_debug('RECEIVE: command: %s, message:%s' % (command, message))

            self.process_message(command, message)
            self.nextBlockSize = 0
Esempio n. 5
0
        def copy(*values):

            if LOG:
                log_debug("Copy")

            temp_folder = "/tmp/temp_copy_files"
            unique_filename = str(uuid.uuid4())
            temp_filepath = os.path.join(temp_folder, unique_filename)

            if not os.path.exists(os.path.dirname(temp_filepath)):
                os.makedirs(os.path.dirname(temp_filepath))

            with open(temp_filepath, "w") as csv_fio:
                for lineValues in values:
                    csv_fio.write("%s\n" % "\t".join(str(v).replace("'", "") for v in lineValues))

            fd = open(temp_filepath, "r")
            self.cursor.copy_from(fd, self.tablename)
            #
            fd.close()

            os.remove(temp_filepath)
Esempio n. 6
0
 def _command_worker_add(self, command, message):
     assert command
     assert message
     log_debug('Add new worker')
     if str(message) not in self.workers:
         self.workers[str(message)] = DaemonWorker(name=str(message))
         log_debug('Added worker')
     else:
         log_debug('Worker already exist')
Esempio n. 7
0
    def _command_channel_add(self, command, message):
        assert command
        assert message
        assert self.workers
        log_debug('Add channel in random worker')
        # todo
        # параметры канала хранить где?
        message = str(message)
        if '___' in message:
            channel_name, properties = [x.strip() for x in message.split('___')]
            properties = eval(properties)
        else:
            channel_name = message.strip()
            properties = {}

        assert isinstance(properties, dict)
        assert channel_name
        assert isinstance(channel_name, str)

        if channel_name not in self.all_channels or True:
            self.all_channels.append(message)

            # todo
            # равномерно раскидываем каналы по воркерам
            min_channels = sys.maxsize
            min_worker = None
            for worker in self.workers.values():
                if worker.get_len_channels() < min_channels:
                    min_worker = worker
                    min_channels = worker.get_len_channels()

            assert isinstance(min_worker, DaemonWorker)
            min_worker.add_channel(chanName=channel_name,
                                   properties=properties)

            log_debug('Added channel')
        else:
            log_debug('Monitor already exist')
Esempio n. 8
0
 def _command_echo(self, command, message):
     log_debug('ECHO (command): %s' % message)
Esempio n. 9
0
 def socket_error(self):
     log_debug('Socker error')
Esempio n. 10
0
 def remove_connection(self, client):
     log_debug('Remove connection')
     assert client in self.users
     del self.users[client]
     log_debug('Stop remove connection')
Esempio n. 11
0
 def test(self):
     log_debug('hiiiii')
Esempio n. 12
0
 def _command_offline(self, client, command, message):
     log_debug('REMOVE USER: %s' % client)
     assert client in self.users
     del self.users[client]
     client.close()