refactor:test new apprach
This commit is contained in:
parent
5f7a7203eb
commit
06df92f868
44
data.py
44
data.py
@ -1,44 +0,0 @@
|
|||||||
import logging
|
|
||||||
import uuid
|
|
||||||
try:
|
|
||||||
from .libs import umsgpack
|
|
||||||
|
|
||||||
except:
|
|
||||||
# Server import
|
|
||||||
from libs import umsgpack
|
|
||||||
|
|
||||||
import zmq
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
|
||||||
logging.basicConfig(level=logging.DEBUG)
|
|
||||||
|
|
||||||
class Data(object):
|
|
||||||
"""
|
|
||||||
Datablock used for replication
|
|
||||||
|
|
||||||
"""
|
|
||||||
uuid = None # key (string)
|
|
||||||
owner = None # User (string)
|
|
||||||
data = None # data blob
|
|
||||||
|
|
||||||
def __init__(self, uuid=None, owner=None, data=None):
|
|
||||||
self.key = str(uuid.uuid4())
|
|
||||||
self.pointer = data
|
|
||||||
self.id = id
|
|
||||||
|
|
||||||
def send(self, socket):
|
|
||||||
"""
|
|
||||||
Here we serialize all kind of data
|
|
||||||
"""
|
|
||||||
pass
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def recv(cls, socket):
|
|
||||||
"""
|
|
||||||
Here we deserialize the data
|
|
||||||
|
|
||||||
"""
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -336,6 +336,17 @@ def dump(any, depth=1):
|
|||||||
dumper.depath = depth
|
dumper.depath = depth
|
||||||
return dumper.dump(any)
|
return dumper.dump(any)
|
||||||
|
|
||||||
|
def dump_datablock(datablock, depth):
|
||||||
|
if datablock:
|
||||||
|
dumper = Dumper()
|
||||||
|
dumper.type_subset = dumper.match_subset_all
|
||||||
|
dumper.depth = depth
|
||||||
|
|
||||||
|
datablock_type = datablock.bl_rna.name
|
||||||
|
key = "{}/{}".format(datablock_type, datablock.name)
|
||||||
|
data = dumper.dump(datablock)
|
||||||
|
|
||||||
|
return data
|
||||||
|
|
||||||
def load(dst, src):
|
def load(dst, src):
|
||||||
loader = Loader()
|
loader = Loader()
|
||||||
|
119
replication.py
Normal file
119
replication.py
Normal file
@ -0,0 +1,119 @@
|
|||||||
|
import logging
|
||||||
|
from .libs.dump_anything import dump_datablock
|
||||||
|
from uuid import uuid4
|
||||||
|
try:
|
||||||
|
from .libs import umsgpack
|
||||||
|
|
||||||
|
except:
|
||||||
|
# Server import
|
||||||
|
from libs import umsgpack
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
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
|
||||||
|
"""
|
||||||
|
pass
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def pull(cls, socket):
|
||||||
|
"""
|
||||||
|
Here we reeceive data from the wire
|
||||||
|
"""
|
||||||
|
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
|
||||||
|
|
||||||
|
def store(self, dict, persistent=False):
|
||||||
|
"""
|
||||||
|
I want to store my replicated data. Persistent means into the disk
|
||||||
|
If uuid is none we delete the key from the volume
|
||||||
|
"""
|
||||||
|
if self.uuid is not None:
|
||||||
|
if self.data == 'None':
|
||||||
|
logger.info("erasing key {}".format(self.uuid))
|
||||||
|
del dict[self.uuid]
|
||||||
|
else:
|
||||||
|
dict[self.uuid] = self
|
||||||
|
pass
|
||||||
|
|
||||||
|
def decode_data(self):
|
||||||
|
"""
|
||||||
|
I want to apply changes into the DCC
|
||||||
|
"""
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
|
|
||||||
|
def encode_data(self):
|
||||||
|
"""
|
||||||
|
I want to load data from DCC
|
||||||
|
"""
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
|
class RpTest(ReplicatedDatablock):
|
||||||
|
def decode_data(self):
|
||||||
|
test_data = {}
|
||||||
|
|
||||||
|
|
||||||
|
# class RpObject(ReplicatedDatablock):
|
||||||
|
# def decode_data(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"]]
|
||||||
|
|
||||||
|
# self.pointer = bpy.data.objects.new(data["name"], pointer)
|
||||||
|
|
||||||
|
# self.pointer.matrix_world = mathutils.Matrix(data["matrix_world"])
|
||||||
|
|
||||||
|
# self.pointer.id = data['id']
|
||||||
|
|
||||||
|
# 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
|
||||||
|
|
||||||
|
# except Exception as e:
|
||||||
|
# logger.error("Object {} loading error: {} ".format(data["name"], e))
|
||||||
|
|
||||||
|
# def encode_data(self):
|
||||||
|
# self.data = dump_datablock(self.pointer, 1)
|
||||||
|
|
||||||
|
|
||||||
|
o = BpyObject("toto")
|
16
test_replication.py
Normal file
16
test_replication.py
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
import unittest
|
||||||
|
import replication
|
||||||
|
|
||||||
|
class TestData(unittest.TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
self.map = {}
|
||||||
|
self.sample_data = replication.ReplicatedDatablock(owner="toto")
|
||||||
|
|
||||||
|
def test_create_replicated_data(self):
|
||||||
|
self.assertNotEqual(self.sample_data.uuid,None)
|
||||||
|
|
||||||
|
def test_push_replicated_data(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
Loading…
x
Reference in New Issue
Block a user