diff --git a/.gitignore b/.gitignore index 46c58e9..64a209e 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ __pycache__/ *$py.classs *.blend1 .vscode +cache \ No newline at end of file diff --git a/__init__.py b/__init__.py index 93c7adc..7ed4fc3 100644 --- a/__init__.py +++ b/__init__.py @@ -1,15 +1,7 @@ -from pathlib import Path -import addon_utils -import random -import string -import subprocess -import sys -import os -import bpy bl_info = { - "name": "Multi-User ", - "author": "CUBE", + "name": "Multi-User", + "author": "CUBE CREATIVE", "description": "", "blender": (2, 80, 0), "location": "", @@ -18,13 +10,21 @@ bl_info = { } +import addon_utils +import random +import string +import sys +import os +import bpy +from . import environment + + +DEPENDENCIES = { + "zmq", + "umsgpack", + "PyYAML" +} -def module_can_be_imported(name): - try: - __import__(name) - return True - except ModuleNotFoundError: - return False # UTILITY FUNCTIONS def client_list_callback(scene, context): @@ -61,12 +61,6 @@ def randomColor(): return [r, v, b] -def get_package_install_directory(): - for path in sys.path: - if os.path.basename(path) in ("dist-packages", "site-packages"): - return path - - class SessionProps(bpy.types.PropertyGroup): username: bpy.props.StringProperty( name="Username", @@ -120,29 +114,8 @@ classes = { } -python_path = Path(bpy.app.binary_path_python) -cwd_for_subprocesses = python_path.parent -target = get_package_install_directory() - - -def install_pip(): - # pip can not necessarily be imported into Blender after this - get_pip_path = Path(__file__).parent / "libs" / "get-pip.py" - subprocess.run([str(python_path), str(get_pip_path)], cwd=cwd_for_subprocesses) - - -def install_package(name): - target = get_package_install_directory() - subprocess.run([str(python_path), "-m", "pip", "install", name, '--target', target], cwd=cwd_for_subprocesses) - - def register(): - if not module_can_be_imported("pip"): - install_pip() - - if not module_can_be_imported("zmq"): - subprocess.run([str(python_path), "-m", "pip", "install", - "zmq", '--target', target], cwd=cwd_for_subprocesses) + environment.setup(DEPENDENCIES) from . import operators from . import ui diff --git a/client.py b/client.py index ec1b945..bb25023 100644 --- a/client.py +++ b/client.py @@ -23,7 +23,7 @@ DUMP_AGENTS_NUMBER = 1 lock = threading.Lock() logger = logging.getLogger(__name__) -logging.basicConfig(level=logging.INFO) +logging.basicConfig(level=logging.DEBUG) instance = None @@ -52,6 +52,7 @@ def zpipe(ctx): class Client(object): + ctx = None pipe = None net_agent = None @@ -193,17 +194,6 @@ class Client(object): else: return 2 #State.SYNCING - # # return self.state - # if not self.is_busy(): - # self.pipe.send_multipart([b"STATE"]) - # try: - # reply = self.pipe.recv_multipart() - # except KeyboardInterrupt: - # return - # else: - # return umsgpack.unpackb(reply[0]) - # else: - # return None # SAVING FUNCTIONS def dump(self, filepath): diff --git a/environment.py b/environment.py new file mode 100644 index 0000000..267c4b6 --- /dev/null +++ b/environment.py @@ -0,0 +1,44 @@ +import sys +import subprocess +import os +from pathlib import Path +import bpy + +thirdPartyDir = os.path.dirname(os.path.abspath(__file__))+"/libs" +python_path = Path(bpy.app.binary_path_python) +cwd_for_subprocesses = python_path.parent +target = None + +def module_can_be_imported(name): + try: + __import__(name) + return True + except ModuleNotFoundError: + return False + + +def get_package_install_directory(): + for path in sys.path: + if os.path.basename(path) in ("dist-packages", "site-packages"): + return path + + +def install_pip(): + # pip can not necessarily be imported into Blender after this + get_pip_path = Path(__file__).parent / "libs" / "get-pip.py" + subprocess.run([str(python_path), str(get_pip_path)], cwd=cwd_for_subprocesses) + + +def install_package(name): + target = get_package_install_directory() + + subprocess.run([str(python_path), "-m", "pip", "install", + name, '--target', target], cwd=cwd_for_subprocesses) + +def setup(dependencies): + if not module_can_be_imported("pip"): + install_pip() + + for dep in dependencies: + if not module_can_be_imported(dep): + install_package(dep) diff --git a/helpers.py b/helpers.py index 7afd92c..0ddf152 100644 --- a/helpers.py +++ b/helpers.py @@ -14,7 +14,7 @@ BPY_TYPES = {'Texture': 'textures','Material': 'materials', 'GreasePencil': 'gre 'Scene': 'scenes', 'Light': 'lights', 'SunLight': 'lights', 'SpotLight': 'lights', 'AreaLight': 'lights', 'PointLight': 'lights', 'Camera': 'cameras', 'Action': 'actions', 'Armature': 'armatures', 'Grease Pencil': 'grease_pencils'} logger = logging.getLogger(__name__) -logging.basicConfig(level=logging.INFO) +logging.basicConfig(level=logging.DEBUG) # UTILITY FUNCTIONS def revers(d): l = [] diff --git a/message.py b/message.py index de2bfe4..0ff280b 100644 --- a/message.py +++ b/message.py @@ -9,7 +9,7 @@ except: import zmq logger = logging.getLogger(__name__) -logging.basicConfig(level=logging.INFO) +logging.basicConfig(level=logging.DEBUG) class Message(object): """