From 6d5221b2c991351f3cc65e8b33be7429e6c64c67 Mon Sep 17 00:00:00 2001 From: Swann Martinez Date: Thu, 4 Jul 2019 18:24:12 +0200 Subject: [PATCH] feat: replication progress --- __init__.py | 3 +- client.py | 12 +++++-- replication.py | 97 +++++++++++++++++++++++++------------------------- 3 files changed, 60 insertions(+), 52 deletions(-) diff --git a/__init__.py b/__init__.py index 3abb8ee..3dcf13b 100644 --- a/__init__.py +++ b/__init__.py @@ -22,7 +22,8 @@ from . import environment DEPENDENCIES = { "zmq", "umsgpack", - "yaml" + "yaml", + "esper" } diff --git a/client.py b/client.py index bf008ab..b8c1c70 100644 --- a/client.py +++ b/client.py @@ -12,7 +12,7 @@ from random import randint import zmq import json -from . import environment, helpers, message +from . import environment,replication, helpers, message from .libs import dump_anything, umsgpack CONNECT_TIMEOUT = 2 @@ -98,6 +98,15 @@ class Client(object): id, str) else id), (address.encode() if isinstance( address, str) else address), b'%d' % port]) + def replicate(self, py_object): + """Entry point for python object replication + - Create object replication structure + - Add it to the distributed hash table + """ + pass + # node = Factory(py_object) + + # self.store def init(self): """ Scene initialisation @@ -129,7 +138,6 @@ class Client(object): def add(self, key, value=None): """Set new value in distributed hash table - Sends [SET][key][value] to the agent """ self.serial_feed.put(key) diff --git a/replication.py b/replication.py index a40770a..2bf86fd 100644 --- a/replication.py +++ b/replication.py @@ -13,35 +13,39 @@ import zmq logger = logging.getLogger(__name__) logging.basicConfig(level=logging.DEBUG) + class ReplicatedDatablock(object): """ Datablock used for replication """ uuid = None # key (string) - data = None # data blob pointer = None # dcc data reference + data = None # data blob (json) + deps = [] - def __init__(self, owner=None, data=None): + def __init__(self, owner=None, data=None): self.uuid = str(uuid4()) assert(owner) + self.pointer = data def push(self, socket): """ - Here send data over the wire + Here send data over the wire: + - serialize the data + - send them as a multipart frame """ pass @classmethod def pull(cls, socket): """ - Here we reeceive data from the wire + Here we reeceive data from the wire: + - read data from the socket + - reconstruct an instance """ - uuid, owner, body = socket.recv_multipart(zmq.NOBLOCK) - key = key.decode() if key else None - id = id if id else None - body = umsgpack.unpackb(body) if body else None + pass def store(self, dict, persistent=False): """ @@ -56,64 +60,59 @@ class ReplicatedDatablock(object): dict[self.uuid] = self pass - def decode_data(self): + def deserialize(self): """ I want to apply changes into the DCC """ raise NotImplementedError - def encode_data(self): + def serialize(self): """ I want to load data from DCC """ raise NotImplementedError -class RpTest(ReplicatedDatablock): - def decode_data(self): - test_data = {} + +import bpy, mathutils - -# class RpObject(ReplicatedDatablock): -# def decode_data(self): -# try: -# if self.pointer is None: -# pointer = None +class RepObject(ReplicatedDatablock): + def deserialize(self): + try: + if self.pointer is None: + pointer = None -# # Object specific constructor... -# if data["data"] in bpy.data.meshes.keys(): -# pointer = bpy.data.meshes[data["data"]] -# elif data["data"] in bpy.data.lights.keys(): -# pointer = bpy.data.lights[data["data"]] -# elif data["data"] in bpy.data.cameras.keys(): -# pointer = bpy.data.cameras[data["data"]] -# elif data["data"] in bpy.data.curves.keys(): -# pointer = bpy.data.curves[data["data"]] -# elif data["data"] in bpy.data.armatures.keys(): -# pointer = bpy.data.armatures[data["data"]] -# elif data["data"] in bpy.data.grease_pencils.keys(): -# pointer = bpy.data.grease_pencils[data["data"]] -# elif data["data"] in bpy.data.curves.keys(): -# pointer = bpy.data.curves[data["data"]] + # Object specific constructor... + if self.data["data"] in bpy.data.meshes.keys(): + pointer = bpy.data.meshes[self.data["data"]] + elif self.data["data"] in bpy.data.lights.keys(): + pointer = bpy.data.lights[self.data["data"]] + elif self.data["data"] in bpy.data.cameras.keys(): + pointer = bpy.data.cameras[self.data["data"]] + elif self.data["data"] in bpy.data.curves.keys(): + pointer = bpy.data.curves[self.data["data"]] + elif self.data["data"] in bpy.data.armatures.keys(): + pointer = bpy.data.armatures[self.data["data"]] + elif self.data["data"] in bpy.data.grease_pencils.keys(): + pointer = bpy.data.grease_pencils[self.data["data"]] + elif self.data["data"] in bpy.data.curves.keys(): + pointer = bpy.data.curves[self.data["data"]] -# self.pointer = bpy.data.objects.new(data["name"], pointer) + self.pointer = bpy.data.objects.new(self.data["name"], pointer) -# self.pointer.matrix_world = mathutils.Matrix(data["matrix_world"]) + self.pointer.matrix_world = mathutils.Matrix(self.data["matrix_world"]) -# self.pointer.id = data['id'] + self.pointer.id = self.data['id'] -# client = bpy.context.window_manager.session.username + client = bpy.context.window_manager.session.username -# if self.pointer.id == client or self.pointer.id == "Common": -# self.pointer.hide_select = False -# else: -# self.pointer.hide_select = True + if self.pointer.id == client or self.pointer.id == "Common": + self.pointer.hide_select = False + else: + self.pointer.hide_select = True -# except Exception as e: -# logger.error("Object {} loading error: {} ".format(data["name"], e)) + except Exception as e: + logger.error("Object {} loading error: {} ".format(self.data["name"], e)) -# def encode_data(self): -# self.data = dump_datablock(self.pointer, 1) - - -o = BpyObject("toto") \ No newline at end of file + def deserialize(self): + self.data = dump_datablock(self.pointer, 1)