Esempio n. 1
0
    def post_processing(self, args):
        file_path = os.path.join(args["outputDir"],
                                 str(args["jobID"]) + CATROBAT_FILE_EXT)
        if not os.path.isfile(file_path):
            yield self._connection.send_message(
                Request(
                    Request.Command.JOB_FAILED, {
                        Request.ARGS_JOB_ID:
                        args["jobID"],
                        Request.ARGS_MSG:
                        "Cannot transfer file! File does not exist!"
                    }))
            return

        file_size = os.path.getsize(file_path)
        with open(file_path, 'rb') as fp:
            file_hash = hashlib.sha256(fp.read()).hexdigest()
            args = {
                Request.ARGS_JOB_ID: args["jobID"],
                Request.ARGS_FILE_SIZE: file_size,
                Request.ARGS_FILE_HASH: file_hash
            }
            yield self._connection.send_message(
                Request(Request.Command.JOB_FINISHED, args))

            # File transfer ready (reply)
            data = json.loads((yield self._connection.read_message()).rstrip())
            if not Reply.is_valid(data):
                raise Exception("Invalid reply!")
            reply = Reply(data[Reply.KEY_RESULT], data[Reply.KEY_MSG])
            if not reply.result:
                _logger.error("[%s]: %s" % (SERVER, reply.msg))
                raise Exception("File transfer failed!")
            _logger.info('[%s]: "%s"' % (SERVER, reply.msg))

            fp.seek(0, 0)
            _logger.info("[%s]: Sending..." % CLIENT)
            byte_buffer = fp.read(BUFFER_SIZE)
            while byte_buffer:
                yield self._connection.send_message(byte_buffer,
                                                    logging_enabled=False)
                byte_buffer = fp.read(BUFFER_SIZE)
            _logger.info("[%s]: Done Sending..." % CLIENT)

            # File transfer finished (reply)
            data = json.loads((yield self._connection.read_message()).rstrip())
            if not Reply.is_valid(data):
                raise Exception("Invalid reply!")
            reply = Reply(data[Reply.KEY_RESULT], data[Reply.KEY_MSG])
            if not reply.result:
                _logger.error("[%s]: %s" % (SERVER, reply.msg))
                raise Exception("File transfer failed!")
            _logger.info('[%s]: "%s"' % (SERVER, reply.msg))
    def post_processing(self, args):
        file_path = os.path.join(args["outputDir"], str(args["jobID"]) + CATROBAT_FILE_EXT)
        if not os.path.isfile(file_path):
            yield self._connection.send_message(Request(Request.Command.JOB_FAILED, {
                Request.ARGS_JOB_ID: args["jobID"],
                Request.ARGS_MSG: "Cannot transfer file! File does not exist!"
            }))
            return

        file_size = os.path.getsize(file_path)
        with open(file_path, 'rb') as fp:
            file_hash = hashlib.sha256(fp.read()).hexdigest()
            args = {
                Request.ARGS_JOB_ID: args["jobID"],
                Request.ARGS_FILE_SIZE: file_size,
                Request.ARGS_FILE_HASH: file_hash
            }
            yield self._connection.send_message(Request(Request.Command.JOB_FINISHED, args))

            # File transfer ready (reply)
            data = json.loads((yield self._connection.read_message()).rstrip())
            if not Reply.is_valid(data):
                raise Exception("Invalid reply!")
            reply = Reply(data[Reply.KEY_RESULT], data[Reply.KEY_MSG])
            if not reply.result:
                _logger.error("[%s]: %s" % (SERVER, reply.msg))
                raise Exception("File transfer failed!")
            _logger.info('[%s]: "%s"' % (SERVER, reply.msg))

            fp.seek(0, 0)
            _logger.info("[%s]: Sending..." % CLIENT)
            byte_buffer = fp.read(BUFFER_SIZE)
            while byte_buffer:
                yield self._connection.send_message(byte_buffer, logging_enabled=False)
                byte_buffer = fp.read(BUFFER_SIZE)
            _logger.info("[%s]: Done Sending..." % CLIENT)

            # File transfer finished (reply)
            data = json.loads((yield self._connection.read_message()).rstrip())
            if not Reply.is_valid(data):
                raise Exception("Invalid reply!")
            reply = Reply(data[Reply.KEY_RESULT], data[Reply.KEY_MSG])
            if not reply.result:
                _logger.error("[%s]: %s" % (SERVER, reply.msg))
                raise Exception("File transfer failed!")
            _logger.info('[%s]: "%s"' % (SERVER, reply.msg))
 def receive_greeting(self):
     data = json.loads((yield self._connection.read_message()).rstrip())
     if not Reply.is_valid(data):
         raise Exception("Invalid reply!")
     reply = Reply(data[Reply.KEY_RESULT], data[Reply.KEY_MSG])
     if not reply.result:
         _logger.error("[%s]: %s" % (SERVER, reply.msg))
         raise Exception("Greeting failed!")
     _logger.info('[%s]: "%s"' % (SERVER, reply.msg))
 def receive_greeting(self):
     data = json.loads((yield self._connection.read_message()).rstrip())
     if not Reply.is_valid(data):
         raise Exception("Invalid reply!")
     reply = Reply(data[Reply.KEY_RESULT], data[Reply.KEY_MSG])
     if not reply.result:
         _logger.error("[%s]: %s" % (SERVER, reply.msg))
         raise Exception("Greeting failed!")
     _logger.info('[%s]: "%s"' % (SERVER, reply.msg))
Esempio n. 5
0
    def authenticate(self):
        _logger.debug('[%s]: Start authentication' % CLIENT)
        request = Request(Request.Command.AUTH, { Request.ARGS_AUTH_KEY: self._auth_key})
        yield self._connection.send_message(request, logging_enabled=False) # do not log key!

        data = json.loads((yield self._connection.read_message()).rstrip())
        if not Reply.is_valid(data):
            raise Exception("Invalid reply!")
        reply = Reply(data[Reply.KEY_RESULT], data[Reply.KEY_MSG])
        if not reply.result:
            _logger.error("[%s]: %s" % (SERVER, reply.msg))
            raise Exception("Authentication failed!")
        _logger.info('[%s]: "%s"' % (SERVER, reply.msg))
Esempio n. 6
0
    def send_job_conversion_finished_notification(self, job_ID, exit_code):
        # Job finished (request)
        _logger.debug('[%s]: Sending job finished notification' % CLIENT)
        args = { Request.ARGS_JOB_ID: job_ID, Request.ARGS_RESULT: exit_code, Request.ARGS_MSG: "Job finished" }
        yield self._connection.send_message(Request(Request.Command.JOB_CONVERSION_FINISHED_NOTIFICATION, args))

        # Job finished (reply)
        data = json.loads((yield self._connection.read_message()).rstrip())
        if not Reply.is_valid(data):
            raise Exception("Invalid reply!")
        reply = Reply(data[Reply.KEY_RESULT], data[Reply.KEY_MSG])
        if not reply.result:
            _logger.error("[%s]: %s" % (SERVER, reply.msg))
            raise Exception("Job finished notification failed!")
        _logger.info('[%s]: "%s"' % (SERVER, reply.msg))
 def send_job_started_notification(self, job_ID, title, image_URL):
     _logger.debug('[%s]: Sending job started notification' % CLIENT)
     args = {
         Request.ARGS_JOB_ID: job_ID,
         Request.ARGS_IMAGE_URL: image_URL,
         Request.ARGS_TITLE: json_encode(title)[1:-1],
         Request.ARGS_MSG: "Job started"
     }
     request = Request(Request.Command.JOB_STARTED_NOTIFICATION, args)
     yield self._connection.send_message(request)
     # Job started (reply)
     data = json.loads((yield self._connection.read_message()).rstrip())
     if not Reply.is_valid(data):
         raise Exception("Invalid reply!")
     reply = Reply(data[Reply.KEY_RESULT], data[Reply.KEY_MSG])
     if not reply.result:
         _logger.error("[%s]: %s" % (SERVER, reply.msg))
         raise Exception("Job started notification failed!")
     _logger.info('[%s]: "%s"' % (SERVER, reply.msg))
 def send_job_started_notification(self, job_ID, title, image_URL):
     _logger.debug('[%s]: Sending job started notification' % CLIENT)
     args = {
         Request.ARGS_JOB_ID: job_ID,
         Request.ARGS_IMAGE_URL: image_URL,
         Request.ARGS_TITLE: title,
         Request.ARGS_MSG: "Job started"
     }
     request = Request(Request.Command.JOB_STARTED_NOTIFICATION, args)
     yield self._connection.send_message(request)
     # Job started (reply)
     data = json.loads((yield self._connection.read_message()).rstrip())
     if not Reply.is_valid(data):
         raise Exception("Invalid reply!")
     reply = Reply(data[Reply.KEY_RESULT], data[Reply.KEY_MSG])
     if not reply.result:
         _logger.error("[%s]: %s" % (SERVER, reply.msg))
         raise Exception("Job started notification failed!")
     _logger.info('[%s]: "%s"' % (SERVER, reply.msg))