Ejemplo n.º 1
0
    def __init__(self, **kwargs):
        """Creates a new instance of NimbleResponseData."""
        NimbleData.__init__(self, **kwargs)

        self.response = kwargs.get('response', NimbleResponseData.SUCCESS_RESPONSE)
        self.error    = kwargs.get('error', None)
        self.warnings = kwargs.get('warnings', None)
Ejemplo n.º 2
0
    def __init__(self, **kwargs):
        """Creates a new instance of NimbleResponseData."""
        NimbleData.__init__(self, **kwargs)

        self.response = kwargs.get('response',
                                   NimbleResponseData.SUCCESS_RESPONSE)
        self.error = kwargs.get('error', None)
        self.warnings = kwargs.get('warnings', None)
Ejemplo n.º 3
0
    def __init__(self, **kwargs):
        """Creates a new instance of NimbleResponseData."""
        NimbleData.__init__(self, **kwargs)
        if 'response' in kwargs:
            self._response = kwargs['response']
        else:
            self._response = NimbleResponseData.SUCCESS_RESPONSE

        if 'error' in kwargs:
            self._error = kwargs['error']
        else:
            self._error = None
Ejemplo n.º 4
0
 def runPythonScript(self, script, **kwargs):
     return self._send(
         NimbleData(kind=DataKindEnum.PYTHON_SCRIPT,
                    payload={
                        'script': script,
                        'kwargs': kwargs
                    }))
Ejemplo n.º 5
0
 def runPythonScriptFile(self, path, **kwargs):
     return self._send(
         NimbleData(kind=DataKindEnum.PYTHON_SCRIPT_FILE,
                    payload={
                        'path': path,
                        'kwargs': kwargs
                    }))
Ejemplo n.º 6
0
 def runMayaCommand(self, command, *args, **kwargs):
     return self._send(
         NimbleData(kind=DataKindEnum.MAYA_COMMAND,
                    payload={
                        'command': str(command),
                        'kwargs': kwargs,
                        'args': args
                    }))
Ejemplo n.º 7
0
    def _createMessage(self):
        """Doc..."""
        d = NimbleData._createMessage(self)
        d['response'] = self.response

        if self.error:
            d['error'] = self.error

        return d
Ejemplo n.º 8
0
 def runCommand(self, command, *args, **kwargs):
     return self._send(
         NimbleData(kind=DataKindEnum.COMMAND,
                    payload={
                        'command':
                        command.toDict() if isinstance(
                            command, ImportedCommand) else str(command),
                        'kwargs':
                        kwargs,
                        'args':
                        args
                    }))
Ejemplo n.º 9
0
    def _createMessage(self):
        """Doc..."""
        d = NimbleData._createMessage(self)
        d['response'] = self.response

        if self.error:
            d['error'] = self.error

        if self.warnings:
            d['warnings'] = self.warnings

        return d
Ejemplo n.º 10
0
    def runPythonImport(self,
                        modulePackage,
                        methodName=None,
                        className=None,
                        runInMaya=None,
                        **kwargs):
        """ Executes the specified import through Nimble in the specified run mode.

            modulePackage:  (String) An absolute (dot-syntax) formatted import to the module you
                            wish to be executed. This module will be imported by Maya and must be
                            on its sys.path.

            [methodName]:   (String) An optional function name to be executed within the module. If
                            a class name is specified this method will be called on an instance of
                            the specified class. If no class name is specified the method will be
                            called directly on the module.

            [className]:    (String) An optional class name of a class to import within the
                            specified module. The class will be imported from the module and
                            instantiated.

            [runInMaya]:    If True the import will be executed within Maya. If False the import
                            will be executed outside of Maya on the remote end of the Nimble
                            connection. The default value of None will use the current global
                            setting, which can be set by the nimble.enablePythonTestMode()
                            top-level function and defaults to runInMaya = True, i.e. test mode
                            is disabled.

            Returns a NimbleResponseData object with the results of the script execution. """

        payload = {
            'module': modulePackage,
            'method': methodName,
            'class': className,
            'kwargs': kwargs
        }

        if NimbleEnvironment.inMaya():
            return MayaRouter.runPythonImport(payload)

        if (not NimbleEnvironment.TEST_REMOTE_MODE
            ) if runInMaya is None else runInMaya:
            return self._send(
                NimbleData(kind=DataKindEnum.PYTHON_IMPORT, payload=payload))
        else:
            return MayaRouter.runPythonImport(payload)
Ejemplo n.º 11
0
 def echo(self, message):
     return self._send(
         NimbleData(kind=DataKindEnum.ECHO, payload={'echo': message}))
Ejemplo n.º 12
0
 def _parseData(self, message, logLevel):
     cd = NimbleData.fromMessage(message)
     self._logData(cd, logLevel)
     return cd
Ejemplo n.º 13
0
    def _sendRemote(self, nimbleData):
        responseFlags = 0
        message       = u''
        retry         = NimbleEnvironment.REMOTE_RETRY_COUNT

        while retry > 0:
            try:
                self.open()
            except Exception as err:
                failure = [
                    '[ERROR | NIMBLE COMMUNICATION] Unable to open connection',
                    err ]
                retry -= 1
                if retry == 0:
                    if not nimble.quietFailure:
                        NimbleEnvironment.logError(failure[0], failure[1])
                    return None
                continue

            try:
                serialData = nimbleData.serialize()
            except Exception as err:
                failure = [
                    '[ERROR | NIMBLE COMMUNICATION] Unable to serialize data for transmission',
                    err ]
                if not nimble.quietFailure:
                    NimbleEnvironment.logError(failure[0], failure[1])
                return None

            try:
                self._chunk.clear()
                self._chunk.writeUint32(NimbleEnvironment.CONNECTION_FLAGS)
                self._chunk.writeString(serialData + NimbleEnvironment.TERMINATION_IDENTIFIER)
                self._socket.sendall(self._chunk.byteArray)
            except Exception as err:
                failure = [
                    '[ERROR | NIMBLE COMMUNICATION] Unable to send data',
                    err ]
                self.close()
                retry -= 1
                if retry == 0:
                    if not nimble.quietFailure:
                        NimbleEnvironment.logError(failure[0], failure[1])
                    return None
                continue

            try:
                self._chunk.clear()
                b = SocketUtils.receiveInChunks(
                    self._socket,
                    chunkSize=NimbleEnvironment.SOCKET_RESPONSE_CHUNK_SIZE)
                self._chunk.writeString(b)
                self._chunk.position = 0
                responseFlags  = self._chunk.readUint32()
                message        = StringUtils.strToUnicode(self._chunk.read(-1))

                # Break while loop on successful reading of the result
                if message is not None:
                    break

            except Exception as err:
                if not nimble.quietFailure:
                    NimbleEnvironment.logError(
                        '[ERROR | NIMBLE COMMUNICATION] Unable to read response', err)
                self.close()
                return None

        try:
            if not (responseFlags & ConnectionFlags.KEEP_ALIVE):
                self.close()
        except Exception as err:
            if not nimble.quietFailure:
                NimbleEnvironment.logError(
                    '[ERROR | NIMBLE COMMUNICATION] Unable to close connection', err)

        try:
            return NimbleData.fromMessage(message)
        except Exception as err:
            if not nimble.quietFailure:
                NimbleEnvironment.logError(
                    '[ERROR | NIMBLE COMMUNICATION] Response data parsing failure', err)
            return None
Ejemplo n.º 14
0
 def runMayaCommandBatch(self, commandList):
     return self._send(
         NimbleData(kind=DataKindEnum.MAYA_COMMAND_BATCH,
                    payload={'commands': commandList}))
Ejemplo n.º 15
0
 def runMelScript(self, script):
     return self._send(
         NimbleData(kind=DataKindEnum.MEL_SCRIPT,
                    payload={'script': script}))
Ejemplo n.º 16
0
    def _sendRemote(self, nimbleData):
        responseFlags = 0
        message = u''
        retry = NimbleEnvironment.REMOTE_RETRY_COUNT

        while retry > 0:
            try:
                self.open()
            except Exception as err:
                failure = [
                    '[ERROR | NIMBLE COMMUNICATION] Unable to open connection',
                    err
                ]
                retry -= 1
                if retry == 0:
                    if not nimble.quietFailure:
                        NimbleEnvironment.logError(failure[0], failure[1])
                    return None
                continue

            try:
                serialData = nimbleData.serialize()
            except Exception as err:
                failure = [
                    '[ERROR | NIMBLE COMMUNICATION] Unable to serialize data for transmission',
                    err
                ]
                if not nimble.quietFailure:
                    NimbleEnvironment.logError(failure[0], failure[1])
                return None

            try:
                self._chunk.clear()
                self._chunk.writeUint32(NimbleEnvironment.CONNECTION_FLAGS)
                self._chunk.writeString(
                    serialData + NimbleEnvironment.TERMINATION_IDENTIFIER)
                self._socket.sendall(self._chunk.byteArray)
            except Exception as err:
                failure = [
                    '[ERROR | NIMBLE COMMUNICATION] Unable to send data', err
                ]
                self.close()
                retry -= 1
                if retry == 0:
                    if not nimble.quietFailure:
                        NimbleEnvironment.logError(failure[0], failure[1])
                    return None
                continue

            try:
                self._chunk.clear()
                b = SocketUtils.receiveInChunks(
                    self._socket,
                    chunkSize=NimbleEnvironment.SOCKET_RESPONSE_CHUNK_SIZE)
                self._chunk.writeString(b)
                self._chunk.position = 0
                responseFlags = self._chunk.readUint32()
                message = StringUtils.strToUnicode(self._chunk.read(-1))

                # Break while loop on successful reading of the result
                if message is not None:
                    break

            except Exception as err:
                if not nimble.quietFailure:
                    NimbleEnvironment.logError(
                        '[ERROR | NIMBLE COMMUNICATION] Unable to read response',
                        err)
                self.close()
                return None

        try:
            if not (responseFlags & ConnectionFlags.KEEP_ALIVE):
                self.close()
        except Exception as err:
            if not nimble.quietFailure:
                NimbleEnvironment.logError(
                    '[ERROR | NIMBLE COMMUNICATION] Unable to close connection',
                    err)

        try:
            return NimbleData.fromMessage(message)
        except Exception as err:
            if not nimble.quietFailure:
                NimbleEnvironment.logError(
                    '[ERROR | NIMBLE COMMUNICATION] Response data parsing failure',
                    err)
            return None
Ejemplo n.º 17
0
 def _parseData(self, message, logLevel):
     data = NimbleData.fromMessage(message)
     self._logData(data, logLevel)
     return data
Ejemplo n.º 18
0
 def _parseData(self, message, logLevel):
     data = NimbleData.fromMessage(message)
     self._logData(data, logLevel)
     return data
Ejemplo n.º 19
0
 def ping(self, message=None):
     """Doc..."""
     return self._send(
         NimbleData(kind=DataKindEnum.PING, payload={'msg': message}))
Ejemplo n.º 20
0
 def addToMayaPythonPath(self, path):
     return self._send(
         NimbleData(kind=DataKindEnum.ADD_SYSTEM_PATH,
                    payload={'path': path}))
Ejemplo n.º 21
0
                    break

            except Exception, err:
                print '[ERROR] Nimble communication failure: Unable to read response'
                print err
                self.close()
                return None

        try:
            self.close()
        except Exception, err:
            print '[ERROR] Nimble communication failure: Unable to close connection'
            print err

        try:
            return NimbleData.fromMessage(message)
        except Exception, err:
            print 'Nimble communication data failure.'
            print err
            return None

#===================================================================================================
#                                                                               I N T R I N S I C

#___________________________________________________________________________________________________ __del__
    def __del__(self):
        try:
            self._socket.close()
        except Exception, err:
            pass