Files
multi-user/multi_user/environment.py

98 lines
2.4 KiB
Python
Raw Normal View History

2020-03-20 14:56:50 +01:00
# ##### 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 3 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, see <https://www.gnu.org/licenses/>.
#
# ##### END GPL LICENSE BLOCK #####
2019-09-30 16:43:12 +02:00
import collections
import logging
import os
2019-07-01 18:04:35 +02:00
import subprocess
import sys
from pathlib import Path
2020-06-17 22:11:20 +02:00
import socket
2020-07-13 15:12:15 +02:00
import re
import bpy
2020-07-13 15:12:15 +02:00
2020-11-20 22:06:08 +01:00
VERSION_EXPR = re.compile('\d+.\d+.\d+')
2020-06-17 22:11:20 +02:00
DEFAULT_CACHE_DIR = os.path.join(
os.path.dirname(os.path.abspath(__file__)), "cache")
2019-07-01 18:04:35 +02:00
rtypes = []
2019-07-01 18:04:35 +02:00
2020-06-17 22:11:20 +02:00
def module_can_be_imported(name: str) -> bool:
try:
__import__(name)
return True
except ModuleNotFoundError:
return False
def install_pip(python_path):
# pip can not necessarily be imported into Blender after this
subprocess.run([str(python_path), "-m", "ensurepip"])
2024-02-26 16:05:32 +01:00
def preload_modules():
from . import wheels
wheels.load_wheel_global("ordered_set", "ordered_set")
wheels.load_wheel_global("deepdiff", "deepdiff")
wheels.load_wheel_global("replication", "replication")
wheels.load_wheel_global("zmq", "pyzmq", match_platform=True)
2024-02-26 16:05:32 +01:00
2020-07-10 18:00:44 +02:00
2020-06-17 22:11:20 +02:00
def get_ip():
"""
Retrieve the main network interface IP.
"""
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(("8.8.8.8", 80))
ip = s.getsockname()[0]
s.close()
return ip
def check_dir(dir):
if not os.path.exists(dir):
os.makedirs(dir)
2019-07-01 18:04:35 +02:00
2020-06-17 22:11:20 +02:00
def setup_paths(paths: list):
""" Add missing path to sys.path
"""
for path in paths:
if path not in sys.path:
logging.debug(f"Adding {path} dir to the path.")
sys.path.insert(0, path)
def remove_paths(paths: list):
""" Remove list of path from sys.path
"""
for path in paths:
if path in sys.path:
logging.debug(f"Removing {path} dir from the path.")
sys.path.remove(path)
def register():
2024-02-26 16:05:32 +01:00
check_dir(DEFAULT_CACHE_DIR)
def unregister():
2024-02-26 16:05:32 +01:00
pass