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

View File

@ -501,20 +501,12 @@ class SessionProps(bpy.types.PropertyGroup):
description='Session password',
subtype='PASSWORD'
)
internet_ip: bpy.props.StringProperty(
name="internet ip",
default="no found",
description='Internet interface ip',
)
user_snap_running: bpy.props.BoolProperty(
default=False
)
time_snap_running: bpy.props.BoolProperty(
default=False
)
is_host: bpy.props.BoolProperty(
default=False
)
def get_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)
from replication.exception import NonAuthorizedOperationError, ContextError
from replication.interface import session
from replication.porcelain import apply, add, commit
from replication import porcelain
from . import operators, utils
from .presence import (UserFrustumWidget, UserNameWidget, UserSelectionWidget,
@ -115,7 +115,7 @@ class ApplyTimer(Timer):
if node_ref.state == FETCHED:
try:
apply(session.repository, node)
porcelain.apply(session.repository, node)
except Exception as e:
logging.error(f"Fail to apply {node_ref.uuid}")
traceback.print_exc()
@ -123,7 +123,7 @@ class ApplyTimer(Timer):
if node_ref.bl_reload_parent:
for parent in session.repository.get_parents(node):
logging.debug("Refresh parent {node}")
apply(session.repository,
porcelain.apply(session.repository,
parent.uuid,
force=True)
@ -168,7 +168,7 @@ class DynamicRightSelectTimer(Timer):
if registered_gp.owner == settings.username:
gp_node = session.repository.get_node(annotation_gp.uuid)
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)
elif self._annotating:

View File

@ -111,8 +111,6 @@ class SESSION_PT_settings(bpy.types.Panel):
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:
info_msg = "Waiting for the session to start."