refactor: update procelain import

This commit is contained in:
Swann 2021-04-21 21:30:43 +02:00
parent 00d5e622af
commit 0e73af4d49
No known key found for this signature in database
GPG Key ID: E1D3641A7C43AACB
4 changed files with 24 additions and 37 deletions

View File

@ -48,7 +48,7 @@ from replication.constants import (COMMITED, FETCHED, RP_COMMON, STATE_ACTIVE,
from replication.protocol import DataTranslationProtocol from replication.protocol import DataTranslationProtocol
from replication.exception import ContextError, NonAuthorizedOperationError from replication.exception import ContextError, NonAuthorizedOperationError
from replication.interface import session from replication.interface import session
from replication.porcelain import add, apply, commit from replication import porcelain
from replication.repository import Repository from replication.repository import Repository
from . import io_bpy, environment, timers, ui, utils from . import io_bpy, environment, timers, ui, utils
@ -190,35 +190,34 @@ class SessionStartOperator(bpy.types.Operator):
handler.setFormatter(formatter) handler.setFormatter(formatter)
bpy_protocol = io_bpy.get_data_translation_protocol() bpy_protocol = io_bpy.get_data_translation_protocol()
# init the factory with supported types # Check if supported_datablocks are up to date before starting the
# the session
for impl in bpy_protocol.implementations.values(): for impl in bpy_protocol.implementations.values():
if impl.__name__ not in settings.supported_datablocks: if impl.__name__ not in settings.supported_datablocks:
logging.info(f"{impl.__name__} not found, \ logging.info(f"{impl.__name__} not found, \
regenerate type settings...") regenerate type settings...")
settings.generate_supported_types() settings.generate_supported_types()
# Ensure blender 2.8 compatibility
if bpy.app.version[1] >= 91: if bpy.app.version[1] >= 91:
python_binary_path = sys.executable python_binary_path = sys.executable
else: else:
python_binary_path = bpy.app.binary_path_python python_binary_path = bpy.app.binary_path_python
repo = Repository(
data_protocol=bpy_protocol,
user=settings.username)
# Host a session # Host a session
if self.host: if self.host:
if settings.init_method == 'EMPTY': if settings.init_method == 'EMPTY':
utils.clean_scene() utils.clean_scene()
runtime_settings.is_host = True
runtime_settings.internet_ip = environment.get_ip()
try: try:
# Init repository # Init repository
for scene in bpy.data.scenes: for scene in bpy.data.scenes:
add(repo, scene) porcelain.add(repo, scene)
# Create an empty repository
repo = Repository(
data_protocol=bpy_protocol)
session.host( session.host(
repository= repo, repository= repo,
@ -317,7 +316,7 @@ class SessionInitOperator(bpy.types.Operator):
utils.clean_scene() utils.clean_scene()
for scene in bpy.data.scenes: for scene in bpy.data.scenes:
add(session.repository, scene) porcelain.add(session.repository, scene)
session.init() session.init()
@ -589,7 +588,7 @@ class SessionApply(bpy.types.Operator):
logging.debug(f"Running apply on {self.target}") logging.debug(f"Running apply on {self.target}")
try: try:
node_ref = session.repository.get_node(self.target) node_ref = session.repository.get_node(self.target)
apply(session.repository, porcelain.apply(session.repository,
self.target, self.target,
force=True, force=True,
force_dependencies=self.reset_dependencies) force_dependencies=self.reset_dependencies)
@ -597,7 +596,7 @@ class SessionApply(bpy.types.Operator):
for parent in session.repository.get_parents(self.target): for parent in session.repository.get_parents(self.target):
logging.debug(f"Refresh parent {parent}") logging.debug(f"Refresh parent {parent}")
apply(session.repository, porcelain.apply(session.repository,
parent.uuid, parent.uuid,
force=True) force=True)
except Exception as e: except Exception as e:
@ -622,7 +621,7 @@ class SessionCommit(bpy.types.Operator):
def execute(self, context): def execute(self, context):
try: try:
commit(session.repository, uuid=self.target) porcelain.commit(session.repository, uuid=self.target)
session.push(self.target) session.push(self.target)
return {"FINISHED"} return {"FINISHED"}
except Exception as e: except Exception as e:
@ -651,7 +650,7 @@ class ApplyArmatureOperator(bpy.types.Operator):
if node_ref.state == FETCHED: if node_ref.state == FETCHED:
try: try:
apply(session.repository, node) porcelain.apply(session.repository, node)
except Exception as e: except Exception as e:
logging.error("Fail to apply armature: {e}") logging.error("Fail to apply armature: {e}")
@ -824,8 +823,6 @@ class SessionLoadSaveOperator(bpy.types.Operator, ImportHelper):
def execute(self, context): def execute(self, context):
from replication.repository import Repository from replication.repository import Repository
# TODO: add filechecks
try: try:
f = gzip.open(self.filepath, "rb") f = gzip.open(self.filepath, "rb")
db = pickle.load(f) db = pickle.load(f)
@ -919,7 +916,7 @@ def update_external_dependencies():
node = session.repository.get_node(node_id) node = session.repository.get_node(node_id)
if node and node.owner in [session.id, RP_COMMON] \ if node and node.owner in [session.id, RP_COMMON] \
and node.has_changed(): and node.has_changed():
commit(session.repository, node_id) porcelain.commit(session.repository, node_id)
session.push(node_id, check_data=False) session.push(node_id, check_data=False)
def sanitize_deps_graph(remove_nodes: bool = False): def sanitize_deps_graph(remove_nodes: bool = False):
@ -992,7 +989,7 @@ def depsgraph_evaluation(scene):
if node.state == UP: if node.state == UP:
try: try:
if node.has_changed(): if node.has_changed():
commit(session.repository, node.uuid) porcelain.commit(session.repository, node.uuid)
session.push(node.uuid, check_data=False) session.push(node.uuid, check_data=False)
except ReferenceError: except ReferenceError:
logging.debug(f"Reference error {node.uuid}") logging.debug(f"Reference error {node.uuid}")
@ -1008,9 +1005,9 @@ def depsgraph_evaluation(scene):
if ref: if ref:
ref.resolve() ref.resolve()
else: else:
scn_uuid = add(session.repository, update.id) scn_uuid = porcelain.add(session.repository, update.id)
commit(session.repository, scn_uuid) porcelain.commit(session.repository, scn_uuid)
push(session.repository) porcelain.push(session.repository)
def register(): def register():
from bpy.utils import register_class from bpy.utils import register_class

View File

@ -501,20 +501,12 @@ class SessionProps(bpy.types.PropertyGroup):
description='Session password', description='Session password',
subtype='PASSWORD' subtype='PASSWORD'
) )
internet_ip: bpy.props.StringProperty(
name="internet ip",
default="no found",
description='Internet interface ip',
)
user_snap_running: bpy.props.BoolProperty( user_snap_running: bpy.props.BoolProperty(
default=False default=False
) )
time_snap_running: bpy.props.BoolProperty( time_snap_running: bpy.props.BoolProperty(
default=False default=False
) )
is_host: bpy.props.BoolProperty(
default=False
)
def get_preferences(): def get_preferences():
return bpy.context.preferences.addons[__package__].preferences return bpy.context.preferences.addons[__package__].preferences

View File

@ -24,7 +24,7 @@ from replication.constants import (FETCHED, RP_COMMON, STATE_ACTIVE,
STATE_SRV_SYNC, STATE_SYNCING, UP) STATE_SRV_SYNC, STATE_SYNCING, UP)
from replication.exception import NonAuthorizedOperationError, ContextError from replication.exception import NonAuthorizedOperationError, ContextError
from replication.interface import session from replication.interface import session
from replication.porcelain import apply, add, commit from replication import porcelain
from . import operators, utils from . import operators, utils
from .presence import (UserFrustumWidget, UserNameWidget, UserSelectionWidget, from .presence import (UserFrustumWidget, UserNameWidget, UserSelectionWidget,
@ -115,7 +115,7 @@ class ApplyTimer(Timer):
if node_ref.state == FETCHED: if node_ref.state == FETCHED:
try: try:
apply(session.repository, node) porcelain.apply(session.repository, node)
except Exception as e: except Exception as e:
logging.error(f"Fail to apply {node_ref.uuid}") logging.error(f"Fail to apply {node_ref.uuid}")
traceback.print_exc() traceback.print_exc()
@ -123,7 +123,7 @@ class ApplyTimer(Timer):
if node_ref.bl_reload_parent: if node_ref.bl_reload_parent:
for parent in session.repository.get_parents(node): for parent in session.repository.get_parents(node):
logging.debug("Refresh parent {node}") logging.debug("Refresh parent {node}")
apply(session.repository, porcelain.apply(session.repository,
parent.uuid, parent.uuid,
force=True) force=True)
@ -168,7 +168,7 @@ class DynamicRightSelectTimer(Timer):
if registered_gp.owner == settings.username: if registered_gp.owner == settings.username:
gp_node = session.repository.get_node(annotation_gp.uuid) gp_node = session.repository.get_node(annotation_gp.uuid)
if gp_node.has_changed(): if gp_node.has_changed():
commit(session.repository, gp_node.uuid) porcelain.commit(session.repository, gp_node.uuid)
session.push(gp_node.uuid, check_data=False) session.push(gp_node.uuid, check_data=False)
elif self._annotating: elif self._annotating:

View File

@ -111,8 +111,6 @@ class SESSION_PT_settings(bpy.types.Panel):
row= layout.row() row= layout.row()
if current_state in [STATE_ACTIVE] and runtime_settings.is_host:
info_msg = f"LAN: {runtime_settings.internet_ip}"
if current_state == STATE_LOBBY: if current_state == STATE_LOBBY:
info_msg = "Waiting for the session to start." info_msg = "Waiting for the session to start."