refactor: append all env related func to evnvironment.py
This commit is contained in:
parent
b7b62b0664
commit
42fa210cee
1
.gitignore
vendored
1
.gitignore
vendored
@ -4,3 +4,4 @@ __pycache__/
|
||||
*$py.classs
|
||||
*.blend1
|
||||
.vscode
|
||||
cache
|
59
__init__.py
59
__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",
|
||||
"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
|
||||
|
14
client.py
14
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):
|
||||
|
44
environment.py
Normal file
44
environment.py
Normal file
@ -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)
|
@ -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 = []
|
||||
|
@ -9,7 +9,7 @@ except:
|
||||
import zmq
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
|
||||
class Message(object):
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user