update tests
This commit is contained in:
22
SerializePropertyGroup.py
Normal file
22
SerializePropertyGroup.py
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
import sys
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
|
thirdPartyDir = "C:\\Users\\slumber\\repos\\phd\src\\2019_rcf\\libs"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if thirdPartyDir not in sys.path:
|
||||||
|
print('Adding local modules dir to the path')
|
||||||
|
sys.path.insert(0, thirdPartyDir)
|
||||||
|
|
||||||
|
|
||||||
|
import umsgpack
|
||||||
|
import bpy
|
||||||
|
import esper
|
||||||
|
from rna_xml import rna2xml
|
||||||
|
|
||||||
|
try:
|
||||||
|
umsgpack.packb((getattr(bpy.data,'objects')))
|
||||||
|
except:
|
||||||
|
pass
|
20
__init__.py
Normal file
20
__init__.py
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
import bpy
|
||||||
|
bl_info = {
|
||||||
|
"name": "Sprite preview",
|
||||||
|
"author": "Cube Animation",
|
||||||
|
"version": (1, 0),
|
||||||
|
"blender": (2, 80, 0),
|
||||||
|
"location": "Properties > Object > Sprite Components",
|
||||||
|
"description": "Manage sprite components in blender",
|
||||||
|
"warning": "",
|
||||||
|
"wiki_url": "",
|
||||||
|
"category": "Cube Animation",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def register():
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def unregister():
|
||||||
|
pass
|
66
dump_rna2xml.py
Normal file
66
dump_rna2xml.py
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
# ***** BEGIN GPL LICENSE BLOCK *****
|
||||||
|
#
|
||||||
|
# This program is free software; you can redistribute it and/or
|
||||||
|
# modify it under the terms of the GNU General Public License
|
||||||
|
# as published by the Free Software Foundation; either version 2
|
||||||
|
# of the License, or (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software Foundation,
|
||||||
|
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
#
|
||||||
|
# Contributor(s): Campbell Barton
|
||||||
|
#
|
||||||
|
# ***** END GPL LICENSE BLOCK *****
|
||||||
|
|
||||||
|
# <pep8 compliant>
|
||||||
|
|
||||||
|
# This script dumps rna into xml.
|
||||||
|
# useful for finding bugs in RNA api.
|
||||||
|
|
||||||
|
# Example usage
|
||||||
|
# blender some.blend --background -noaudio --python intern/tools/dump_rna2xml.py
|
||||||
|
|
||||||
|
import os
|
||||||
|
import bpy
|
||||||
|
import rna_xml
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
filename = os.path.splitext(bpy.data.filepath)[0] + ".xml"
|
||||||
|
|
||||||
|
file = open(filename, 'w')
|
||||||
|
|
||||||
|
if 1:
|
||||||
|
# blend file
|
||||||
|
rna_xml.rna2xml(file.write,
|
||||||
|
root_rna=bpy.data,
|
||||||
|
root_rna_skip={"window_managers"})
|
||||||
|
else:
|
||||||
|
# theme. just another test
|
||||||
|
rna_xml.rna2xml(file.write,
|
||||||
|
root_rna=bpy.context.user_preferences.themes[0],
|
||||||
|
method='ATTR')
|
||||||
|
|
||||||
|
file.close()
|
||||||
|
|
||||||
|
# read back to ensure this is valid!
|
||||||
|
from xml.dom.minidom import parse
|
||||||
|
xml_nodes = parse(filename)
|
||||||
|
print("Written:", filename)
|
||||||
|
|
||||||
|
# test reading back theme
|
||||||
|
if 1:
|
||||||
|
theme = xml_nodes.getElementsByTagName("Theme")[0]
|
||||||
|
rna_xml.xml2rna(theme,
|
||||||
|
root_rna=bpy.context.user_preferences.themes[0],)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
82
main.py
82
main.py
@ -1,62 +1,52 @@
|
|||||||
import net_systems
|
import net_systems
|
||||||
|
import replication_system
|
||||||
import net_components
|
import net_components
|
||||||
from libs.esper import esper
|
from libs.esper import esper
|
||||||
import zmq
|
import zmq
|
||||||
import sys
|
import sys
|
||||||
import argparse
|
import argparse
|
||||||
import time
|
import time
|
||||||
from zmq.asyncio import Context, ZMQEventLoop
|
|
||||||
import asyncio
|
|
||||||
|
|
||||||
Url = 'tcp://127.0.0.1:5555'
|
|
||||||
Ctx = Context()
|
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
|
||||||
def server():
|
|
||||||
print("Getting ready for hello world client. Ctrl-C to exit.\n")
|
|
||||||
socket = Ctx.socket(zmq.REP)
|
|
||||||
socket.bind(Url)
|
|
||||||
while True:
|
|
||||||
# Wait for next request from client
|
|
||||||
message = yield from socket.recv()
|
|
||||||
print("Received request: {}".format(message))
|
|
||||||
# Do some "work"
|
|
||||||
yield from asyncio.sleep(1)
|
|
||||||
# Send reply back to client
|
|
||||||
message = message.decode('utf-8')
|
|
||||||
message = '{}, world'.format(message)
|
|
||||||
message = message.encode('utf-8')
|
|
||||||
print("Sending reply: {}".format(message))
|
|
||||||
yield from socket.send(message)
|
|
||||||
|
|
||||||
|
|
||||||
# TODO: Implement a manager class for each aspect (ex: Network_Manager)
|
# TODO: Implement a manager class for each aspect (ex: Network_Manager)
|
||||||
# TODO: Is it right to implement server-client as ESC ?...
|
# TODO: Is it right to implement server-client as ESC ?...
|
||||||
def main():
|
def main():
|
||||||
args = sys.argv[1:]
|
# Argument parsing
|
||||||
if len(args) != 0:
|
parser = argparse.ArgumentParser(
|
||||||
sys.exit(__doc__)
|
description='Launch an instance of collaboration system')
|
||||||
|
parser.add_argument('-r', choices=list(net_components.Role),
|
||||||
|
type=net_components.Role, help='role for the instance ')
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
instance_role = args.r
|
||||||
|
instance_context = zmq.Context()
|
||||||
|
|
||||||
|
print("Starting a {} instance \n".format(instance_role))
|
||||||
|
|
||||||
|
# Create a World instance to hold everything:
|
||||||
|
world = esper.World()
|
||||||
|
|
||||||
|
# Instantiate a Processor (or more), and add them to the world:
|
||||||
|
world.add_processor(net_systems.SessionSystem())
|
||||||
|
world.add_processor(replication_system.ReplicationSystem())
|
||||||
|
|
||||||
|
# Instanciate a session entity
|
||||||
|
session = world.create_entity()
|
||||||
|
|
||||||
|
world.add_component(
|
||||||
|
session, net_components.NetworkInterface(context=instance_context))
|
||||||
|
world.add_component(
|
||||||
|
session, net_components.User(role=instance_role))
|
||||||
|
|
||||||
|
|
||||||
|
# A dummy main loop:
|
||||||
try:
|
try:
|
||||||
loop = asyncio.get_event_loop()
|
while True:
|
||||||
loop.run_until_complete(server())
|
# Call world.process() to run all Processors.
|
||||||
|
world.process()
|
||||||
|
time.sleep(1)
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
print('\nFinished (interrupted)')
|
return
|
||||||
sys.exit(0)
|
|
||||||
|
|
||||||
# Socket to talk to server
|
|
||||||
print("Connecting to hello world server...")
|
|
||||||
socket = context.socket(zmq.REQ)
|
|
||||||
socket.connect("tcp://localhost:5555")
|
|
||||||
|
|
||||||
# Do 10 requests, waiting each time for a response
|
|
||||||
for request in range(10):
|
|
||||||
print("Sending request %s ..." % request)
|
|
||||||
socket.send(b"Hello")
|
|
||||||
|
|
||||||
# Get the reply.
|
|
||||||
message = socket.recv()
|
|
||||||
print("Received reply %s [ %s ]" % (request, message))
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
52
main_old.py
52
main_old.py
@ -1,52 +0,0 @@
|
|||||||
import net_systems
|
|
||||||
import net_components
|
|
||||||
from libs.esper import esper
|
|
||||||
import zmq
|
|
||||||
import sys
|
|
||||||
import argparse
|
|
||||||
import time
|
|
||||||
|
|
||||||
# TODO: Implement a manager class for each aspect (ex: Network_Manager)
|
|
||||||
# TODO: Is it right to implement server-client as ESC ?...
|
|
||||||
def main():
|
|
||||||
# Argument parsing
|
|
||||||
parser = argparse.ArgumentParser(
|
|
||||||
description='Launch an instance of collaboration system')
|
|
||||||
parser.add_argument('-r', choices=list(net_components.Role),
|
|
||||||
type=net_components.Role, help='role for the instance ')
|
|
||||||
|
|
||||||
args = parser.parse_args()
|
|
||||||
|
|
||||||
instance_role = args.r
|
|
||||||
instance_context = zmq.Context()
|
|
||||||
|
|
||||||
print("Starting a {} instance \n".format(instance_role))
|
|
||||||
|
|
||||||
# Create a World instance to hold everything:
|
|
||||||
world = esper.World()
|
|
||||||
|
|
||||||
# Instantiate a Processor (or more), and add them to the world:
|
|
||||||
network_system = net_systems.NetworkSystem()
|
|
||||||
world.add_processor(network_system)
|
|
||||||
|
|
||||||
# Instanciate a session entity
|
|
||||||
session = world.create_entity()
|
|
||||||
|
|
||||||
world.add_component(
|
|
||||||
session, net_components.NetworkInterface(context=instance_context))
|
|
||||||
world.add_component(
|
|
||||||
session, net_components.User(role=instance_role))
|
|
||||||
|
|
||||||
|
|
||||||
# A dummy main loop:
|
|
||||||
try:
|
|
||||||
while True:
|
|
||||||
# Call world.process() to run all Processors.
|
|
||||||
world.process()
|
|
||||||
time.sleep(1)
|
|
||||||
except KeyboardInterrupt:
|
|
||||||
return
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
main()
|
|
@ -22,14 +22,12 @@ class User:
|
|||||||
self.role = role
|
self.role = role
|
||||||
|
|
||||||
class NetworkInterface:
|
class NetworkInterface:
|
||||||
def __init__(self, host="*",context=None, socket_type=zmq.REQ,protocol='tcp',port=5555):
|
def __init__(self, host="*",context=None, socket_type=zmq.REP,protocol='tcp',port=5555):
|
||||||
self.host = host
|
self.host = host
|
||||||
self.context = context
|
self.context = context
|
||||||
self.socket = context.socket(socket_type)
|
self.socket = context.socket(socket_type)
|
||||||
self.poller = zmq.Poller()
|
|
||||||
|
|
||||||
#TODO: Is this right to it here?
|
#TODO: Is this right to it here?
|
||||||
self.poller.register(self.socket, zmq.POLLIN)
|
|
||||||
print("{}://{}:{}".format(protocol,host,port))
|
print("{}://{}:{}".format(protocol,host,port))
|
||||||
self.socket.bind("tcp://*:5555")
|
self.socket.bind("tcp://*:5555")
|
||||||
|
|
||||||
|
@ -1,12 +1,14 @@
|
|||||||
import time
|
import time
|
||||||
|
import asyncio
|
||||||
|
|
||||||
import zmq
|
import zmq
|
||||||
|
import zmq.asyncio
|
||||||
|
|
||||||
import net_components
|
import net_components
|
||||||
from libs.esper import esper
|
from libs.esper import esper
|
||||||
|
|
||||||
|
|
||||||
class NetworkSystem(esper.Processor):
|
class SessionSystem(esper.Processor):
|
||||||
"""
|
"""
|
||||||
Handle Client-Server session managment
|
Handle Client-Server session managment
|
||||||
"""
|
"""
|
||||||
@ -20,21 +22,24 @@ class NetworkSystem(esper.Processor):
|
|||||||
def process(self):
|
def process(self):
|
||||||
# This will iterate over every Entity that has BOTH of these components:
|
# This will iterate over every Entity that has BOTH of these components:
|
||||||
for ent, (net_interface, user) in self.world.get_components(net_components.NetworkInterface,net_components.User):
|
for ent, (net_interface, user) in self.world.get_components(net_components.NetworkInterface,net_components.User):
|
||||||
if user.role is net_components.Role.CLIENT:
|
|
||||||
net_interface.socket.send(b"Waiting server response")
|
|
||||||
|
|
||||||
if user.role is net_components.Role.SERVER:
|
if user.role is net_components.Role.SERVER:
|
||||||
print("Server loops")
|
print("Server loops")
|
||||||
try:
|
try:
|
||||||
socks = dict(net_interface.poller.poll())
|
message = net_interface.socket.recv()
|
||||||
print("test")
|
print("test")
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
break
|
break
|
||||||
if net_interface.socket in socks:
|
|
||||||
message = net_interface.socket.recv()
|
|
||||||
|
|
||||||
print("test")
|
print("test")
|
||||||
# process task
|
|
||||||
|
|
||||||
|
if user.role is net_components.Role.CLIENT:
|
||||||
|
# Send reply back to client
|
||||||
|
socket.send(b"Hello")
|
||||||
|
|
||||||
|
@asyncio.coroutine
|
||||||
|
def recv_and_process():
|
||||||
|
sock = ctx.socket(zmq.PULL)
|
||||||
|
sock.bind(url)
|
||||||
|
msg = yield from sock.recv_multipart() # waits for msg to be ready
|
||||||
|
reply = yield from async_process(msg)
|
||||||
|
yield from sock.send_multipart(reply)
|
||||||
|
18
replication_system.py
Normal file
18
replication_system.py
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
import zmq
|
||||||
|
|
||||||
|
from libs.esper import esper
|
||||||
|
|
||||||
|
class ReplicationSystem(esper.Processor):
|
||||||
|
"""
|
||||||
|
Handle Client-Server session managment
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__()
|
||||||
|
# Initialize poll set
|
||||||
|
|
||||||
|
|
||||||
|
# TODO: Use zmq_poll..
|
||||||
|
async def process(self):
|
||||||
|
# This will iterate over every Entity that has BOTH of these components:
|
||||||
|
print("test")
|
BIN
test.blend
Normal file
BIN
test.blend
Normal file
Binary file not shown.
BIN
test_net.blend
Normal file
BIN
test_net.blend
Normal file
Binary file not shown.
Reference in New Issue
Block a user