Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge latest nviz into Luma modifications

  • Loading branch information...
commit 4fdbb9d0f4fa1a2701d69aa5d3a23d3fdb0a6e29 2 parents d695449 + 9b4543b
Nathan Rusch authored
Showing with 82 additions and 14 deletions.
  1. +1 −0  .gitignore
  2. +39 −6 nukeCommandClient.py
  3. +42 −8 nukeCommandServer.py
1  .gitignore
View
@@ -0,0 +1 @@
+*.pyc
45 nukeCommandClient.py
View
@@ -23,6 +23,7 @@
# any flags or arguments).
NUKE_EXEC = 'Nuke'
+MAX_SOCKET_BYTES = 16384
class NukeConnectionError(StandardError):
pass
@@ -33,7 +34,7 @@ class NukeManagerError(NukeConnectionError):
class NukeServerError(NukeConnectionError):
pass
-class NukeConnection:
+class NukeConnection():
'''
If 'port' is specified, the client will attempt to connect
to a command server on that port, raising an exception
@@ -58,7 +59,7 @@ def __init__(self, port=None, host="localhost", instance=0):
if not self.test_connection():
raise NukeConnectionError("Could not connect to Nuke command server on port %d" % self._port)
self.is_active = True
-
+
def find_connection_port(self, start_port, end_port):
for port in range(start_port, end_port + 1):
self._port = port
@@ -90,8 +91,32 @@ def test_connection(self):
def get(self, item_type, item_id = -1, parameters = None):
try:
data = {'action': item_type, 'id': item_id, 'parameters': parameters}
- returnData = self.send(pickle.dumps(self.encode(data)))
+ encoded = pickle.dumps(self.encode(data))
+
+ if len(encoded) > MAX_SOCKET_BYTES:
+ encodedBits = []
+ while encoded:
+ encodedBits.append(encoded[:MAX_SOCKET_BYTES])
+ encoded = encoded[MAX_SOCKET_BYTES:]
+
+ for i in range(len(encodedBits)):
+ result = pickle.loads(self.send(pickle.dumps({'type': "NukeTransferPartialObject", 'part': i, 'part_count': len(encodedBits), 'data': encodedBits[i]})))
+ if i < (len(encodedBits) - 1):
+ if not (isinstance(result, dict) and 'type' in result and result['type'] == "NukeTransferPartialObjectRequest" and 'part' in result and result['part'] == i+1):
+ raise NukeConnectionError("Unexpected response to partial object")
+ else:
+ result = pickle.loads(self.send(encoded))
+
+ if isinstance(result, dict) and 'type' in result and result['type'] == "NukeTransferPartialObject":
+ data = result['data']
+ nextPart = 1
+ while nextPart < result['part_count']:
+ returnData = self.send(pickle.dumps({'type': "NukeTransferPartialObjectRequest", 'part': nextPart}))
result = pickle.loads(returnData)
+ data += result['data']
+ nextPart += 1
+
+ result = pickle.loads(data)
except Exception, e:
raise e
@@ -184,14 +209,22 @@ def decode(self, data):
def __getattr__(self, attrname):
return self.get_object_item(-1, attrname)
+ def __getitem__(self, itemname):
+ return self.__getattr__(itemname)
+
+ def __repr__(self):
+ return object.__repr__(self).replace("instance object", "NukeConnection instance")
+
+ def __str__(self):
+ return self.__repr__()
-class NukeObject:
+class NukeObject():
def __init__(self, connection, id):
self.__dict__['_id'] = id
self.__dict__['_connection'] = connection
def __getattr__(self, attrname):
- if attrname[0] in self.__dict__:
+ if attrname[0] == "_":
return self.__dict__[attrname]
else:
return self._connection.get_object_attribute(self._id, attrname)
@@ -352,4 +385,4 @@ def start_managed_nuke_server(manager_port=None):
if len(sys.argv) > 1:
manager_port = int(sys.argv[1].strip())
- start_managed_nuke_server(manager_port)
+ start_managed_nuke_server(manager_port)
50 nukeCommandServer.py
View
@@ -8,6 +8,8 @@
listTypes = [list, tuple, set, frozenset]
dictTypes = [dict]
+MAX_SOCKET_BYTES = 16384
+
class NukeConnectionError(StandardError):
pass
@@ -15,7 +17,7 @@ def nuke_command_server():
t = threading.Thread(None, NukeInternal)
t.setDaemon(True)
t.start()
-
+
class NukeInternal:
def __init__(self, port=None):
self._objects = {}
@@ -48,7 +50,7 @@ def __init__(self, port=None):
s.listen(backlog)
self.start_server(s)
-
+
def start_server(self, sock):
'''
Starts the main server loop
@@ -106,8 +108,7 @@ def encode(self, data):
def decode(self, data):
return self.decode_data(pickle.loads(data))
- def get(self, data_string):
- data = self.decode(data_string)
+ def get(self, data):
obj = self.get_object(data['id'])
params = data['parameters']
result = None
@@ -140,13 +141,46 @@ def get(self, data_string):
except Exception, e:
result = e
- encoded = self.encode(result)
+ return result
+
+ def receive(self, data_string):
+ data = self.decode(data_string)
+ if isinstance(data, dict) and 'type' in data and data['type'] == "NukeTransferPartialObjectRequest":
+ if data['part'] in self.partialObjects:
+ encoded = self.partialObjects[data['part']]
+ del self.partialObjects[data['part']]
return encoded
- def receive(self, data):
- return self.get(data)
+ if isinstance(data, dict) and 'type' in data and data['type'] == "NukeTransferPartialObject":
+ if data['part'] == 0:
+ self.partialData = ""
+ self.partialData += data['data']
+ if data['part'] == (data['part_count'] - 1):
+ data = pickle.loads(self.partialData)
+ else:
+ nextPart = data['part'] + 1
+ return pickle.dumps({'type': "NukeTransferPartialObjectRequest", 'part': nextPart})
+
+ encoded = self.encode(self.get(data))
+
+ if len(encoded) > MAX_SOCKET_BYTES:
+ encodedBits = []
+ while encoded:
+ encodedBits.append(encoded[:MAX_SOCKET_BYTES])
+ encoded = encoded[MAX_SOCKET_BYTES:]
+
+ self.partialObjects = {}
+ for i in range(len(encodedBits)):
+ self.partialObjects[i] = pickle.dumps({'type': "NukeTransferPartialObject", 'part': i, 'part_count': len(encodedBits), 'data': encodedBits[i]})
+
+ encoded = self.partialObjects[0]
+ del self.partialObjects[0]
+
+ return encoded
+
+
def get_object(self, id):
if id == -1:
return globals()
@@ -195,4 +229,4 @@ def manager_callback(self, status):
manager.send(self.encode((status, self.port)))
manager.close()
if not status:
- raise NukeConnectionError("Cannot find port to bind to")
+ raise NukeConnectionError("Cannot find port to bind to")
Please sign in to comment.
Something went wrong with that request. Please try again.