def __init__ (self, rc, msg=None):
        """
        Construct an :py:exc:`SCPError` object.

        """

        # get a nice custom error message
        super (SCPError, self).__init__ (
            "command failed with error %s: '%s'" % scamp.rc_to_string (rc))

        # save the response code
        self.rc      = rc
        self.rc_text = scamp.rc_to_string (rc)
        self.message = msg__author__ = 'stokesa6'
Ejemplo n.º 2
0
    def __init__(self, rc, msg=None):
        """
        Construct an :py:exc:`SCPError` object.

        """

        # get a nice custom error message
        super(SCPError, self).__init__("command failed with error %s: '%s'" %
                                       scamp.rc_to_string(rc))

        # save the response code
        self.rc = rc
        self.rc_text = scamp.rc_to_string(rc)
        self.message = msg__author__ = 'stokesa6'
    def send_scp_msg(self, msg, retries=10):
        """
        Dispatches the given packet and expects a response from the target
        machine.  Before the packet is sent, the destination co-ordinates and
        CPU index are altered to match the values internal to this class.

        :param SCPMessage msg: command packet to send to remote host
        :returns: :py:class:`SCPMessage` returned from the remote host
        :raises: SCPError

        """

        # update the message before sending
        msg.dst_cpu = self._cpu
        msg.dst_x = self._x
        msg.dst_y = self._y

        # get the response from the remote host
        sent_message = False
        resp = None
        self.next_seq_num()
        while not sent_message and retries > 0:
            try:
                self.send(msg)
                resp = self.receive()
                if ((resp.cmd_rc != scamp.RC_TIMEOUT)
                        and (resp.cmd_rc != scamp.RC_P2P_TIMEOUT)
                        and (resp.cmd_rc != scamp.RC_LEN)):
                    sent_message = True
                else:
                    logger.debug("Warning - response was {}, retrying".format(
                        scamp.rc_to_string(resp.cmd_rc)))
                    if resp.cmd_rc == scamp.RC_TIMEOUT:
                        self.no_timeout_retries += 1
                    elif resp.cmd_rc == scamp.RC_P2P_TIMEOUT:
                        self.no_p2ptimeout_retries += 1
                    elif resp.cmd_rc == scamp.RC_LEN:
                        self.no_len_retries += 1
                    retries -= 1
            except socket.timeout as e:
                logger.debug("Warning - timeout waiting for response")
                retries -= 1
        if not sent_message:
            raise SCPError(0,
                           "Failed to receive response after sending message")

        # deal with errors by making it someone else's problem!
        if resp.cmd_rc != scamp.RC_OK:
            raise SCPError(resp.cmd_rc, resp)
        else:
            return resp
    def send_scp_msg (self, msg, retries=10):
        """
        Dispatches the given packet and expects a response from the target
        machine.  Before the packet is sent, the destination co-ordinates and
        CPU index are altered to match the values internal to this class.

        :param SCPMessage msg: command packet to send to remote host
        :returns: :py:class:`SCPMessage` returned from the remote host
        :raises: SCPError

        """

        # update the message before sending
        msg.dst_cpu = self._cpu
        msg.dst_x   = self._x
        msg.dst_y   = self._y

        # get the response from the remote host
        sent_message = False
        resp = None
        self.next_seq_num()
        while not sent_message and retries > 0:
            try:
                self.send(msg)
                resp = self.receive()
                if ((resp.cmd_rc != scamp.RC_TIMEOUT) 
                        and (resp.cmd_rc != scamp.RC_P2P_TIMEOUT)
                        and (resp.cmd_rc != scamp.RC_LEN)):
                    sent_message = True
                else:
                    logger.debug("Warning - response was {}, retrying".format(
                            scamp.rc_to_string(resp.cmd_rc)))
                    if resp.cmd_rc == scamp.RC_TIMEOUT:
                        self.no_timeout_retries += 1
                    elif resp.cmd_rc == scamp.RC_P2P_TIMEOUT:
                        self.no_p2ptimeout_retries += 1
                    elif resp.cmd_rc == scamp.RC_LEN:
                        self.no_len_retries += 1
                    retries -= 1
            except socket.timeout as e:
                logger.debug("Warning - timeout waiting for response")
                retries -= 1
        if not sent_message:
            raise SCPError(0, "Failed to receive response after sending message")

        # deal with errors by making it someone else's problem!
        if resp.cmd_rc != scamp.RC_OK:
            raise SCPError(resp.cmd_rc, resp)
        else:
            return resp