def run(self): if self.isReady(): buffer = blender_cave.buffer.Buffer() buffer.command(self.SYNCHRONIZER) buffer.subBuffer(self._synchronizer.getBuffer()) self._send(buffer) self._select.run(False)
def getBuffer(self): buffer = blender_cave.buffer.Buffer() # Create new objects affectations ... newObjects = blender_cave.buffer.Buffer() while len(self._synchronizedObjectsToAdd) > 0: object = self._synchronizedObjectsToAdd.pop() objects_id = id(object) self._synchronizedObjects[objects_id] = object newObjects.itemID(objects_id) newObjects.string(object._synchronize_object_name) if not newObjects.isEmpty(): buffer.command(self.NEW_OBJECT) buffer.subBuffer(newObjects) # Then update objects attributs for objects_id, object in self._synchronizedObjects.items(): object_data_buffer = object.getSynchronizerBuffer() if (object_data_buffer is not None) and (not object_data_buffer.isEmpty()): buffer.command(self.OBJECT) buffer.itemID(objects_id) buffer.subBuffer(object_data_buffer) return buffer
def addBuffer(self, buffer_name, obj_buffer): if self._original: buffer = blender_cave.buffer.Buffer() buffer.string(buffer_name) buffer.subBuffer(obj_buffer) file = open(self._backup_filename, "ab") file.write(buffer._buffer) file.close()
def process(self, buffer): while not buffer.isEmpty(): command = buffer.command() if command == self.NEW_OBJECT: new_objects_buffer = buffer.subBuffer() while not new_objects_buffer.isEmpty(): objects_id = new_objects_buffer.itemID() objects_name = new_objects_buffer.string() for i in range(len(self._synchronizedObjectsToAdd)): if self._synchronizedObjectsToAdd[i]._synchronize_object_name == objects_name: object = self._synchronizedObjectsToAdd.pop(i) self._synchronizedObjects[objects_id] = object break elif command == self.OBJECT: objects_id = buffer.itemID() objectBuffer = buffer.subBuffer() if objects_id in self._synchronizedObjects: self._synchronizedObjects[objects_id].processSynchronizerBuffer(objectBuffer)
def process(self, buffer): while not buffer.isEmpty(): command = buffer.command() if command == self.NEW_OBJECT: new_objects_buffer = buffer.subBuffer() while not new_objects_buffer.isEmpty(): objects_id = new_objects_buffer.itemID() objects_name = new_objects_buffer.string() for i in range(len(self._synchronizedObjectsToAdd)): if self._synchronizedObjectsToAdd[ i]._synchronize_object_name == objects_name: object = self._synchronizedObjectsToAdd.pop(i) self._synchronizedObjects[objects_id] = object break elif command == self.OBJECT: objects_id = buffer.itemID() objectBuffer = buffer.subBuffer() if objects_id in self._synchronizedObjects: self._synchronizedObjects[ objects_id].processSynchronizerBuffer(objectBuffer)
def _processMessageFromMaster(self, peer): buffer = self._receiveFrom(peer) if buffer is None: self.quit("Lose connection from the master !") return while not buffer.isEmpty(): command = buffer.command() if command == self.EVERYBODY_HERE: self._switchToReady() elif command == self.QUIT: self._shutdown() self.quit(buffer.string()) elif command == self.SYNCHRONIZER: self._synchronizer.process(buffer.subBuffer()) else: raise blender_cave.exceptions.Controller("Unattended command (" + str(command) + ") from " + str(peer))
def _processMessageFromMaster(self, peer): buffer = self._receiveFrom(peer) if buffer is None: self.quit("Lose connection from the master !") return while not buffer.isEmpty(): command = buffer.command() if command == self.EVERYBODY_HERE: self._switchToReady() elif command == self.QUIT: self._shutdown() self.quit(buffer.string()) elif command == self.SYNCHRONIZER: self._synchronizer.process(buffer.subBuffer()) else: raise blender_cave.exceptions.Controller( "Unattended command (" + str(command) + ") from " + str(peer))
def __init__(self, parent, environ): super(ReloadBackupper, self).__init__(parent) self._backup_filename = environ.getEnvironment('rb_file') if self._backup_filename is None: self._backup_filename = os.path.join(tempfile.gettempdir(), 'blender_cave.!PID!.dat') self._backup_filename = self._backup_filename.replace('!PID!', str(os.getpid())) try: buffer = blender_cave.buffer.Buffer() file = open(self._backup_filename, "rb") buffer._buffer = file.read() file.close() self._buffers = {} while not buffer.isEmpty(): buffer_name = buffer.string() obj_buffer = buffer.subBuffer() self._buffers[buffer_name] = obj_buffer self._original = False except IOError: self._original = True file = open(self._backup_filename, "wb") file.close()