From 8f9d5aabf96792601453a947065cf64d011cfcf6 Mon Sep 17 00:00:00 2001 From: Swann Date: Thu, 1 Oct 2020 22:51:48 +0200 Subject: [PATCH] refactor: moved get_datablock_from_uuid to bl_datablock --- multi_user/bl_types/bl_datablock.py | 23 +++++++++++++++++++---- multi_user/bl_types/bl_material.py | 3 +-- multi_user/bl_types/bl_object.py | 1 - multi_user/bl_types/bl_scene.py | 1 - multi_user/utils.py | 13 ------------- 5 files changed, 20 insertions(+), 21 deletions(-) diff --git a/multi_user/bl_types/bl_datablock.py b/multi_user/bl_types/bl_datablock.py index 27d3f69..c7996e3 100644 --- a/multi_user/bl_types/bl_datablock.py +++ b/multi_user/bl_types/bl_datablock.py @@ -16,14 +16,16 @@ # ##### END GPL LICENSE BLOCK ##### +import logging +from collections.abc import Iterable + import bpy import mathutils -import logging +from replication.constants import DIFF_BINARY, UP +from replication.data import ReplicatedDatablock from .. import utils -from .dump_anything import Loader, Dumper -from replication.data import ReplicatedDatablock -from replication.constants import (UP, DIFF_BINARY) +from .dump_anything import Dumper, Loader def has_action(target): @@ -87,6 +89,19 @@ def load_driver(target_datablock, src_driver): loader.load(new_point, src_driver['keyframe_points'][src_point]) +def get_datablock_from_uuid(uuid, default, ignore=[]): + if not uuid: + return default + + for category in dir(bpy.data): + root = getattr(bpy.data, category) + if isinstance(root, Iterable) and category not in ignore: + for item in root: + if getattr(item, 'uuid', None) == uuid: + return item + return default + + class BlDatablock(ReplicatedDatablock): """BlDatablock diff --git a/multi_user/bl_types/bl_material.py b/multi_user/bl_types/bl_material.py index d9f6103..b0c83b1 100644 --- a/multi_user/bl_types/bl_material.py +++ b/multi_user/bl_types/bl_material.py @@ -21,9 +21,8 @@ import mathutils import logging import re -from ..utils import get_datablock_from_uuid from .dump_anything import Loader, Dumper -from .bl_datablock import BlDatablock +from .bl_datablock import BlDatablock, get_datablock_from_uuid NODE_SOCKET_INDEX = re.compile('\[(\d*)\]') diff --git a/multi_user/bl_types/bl_object.py b/multi_user/bl_types/bl_object.py index edc3e26..820b566 100644 --- a/multi_user/bl_types/bl_object.py +++ b/multi_user/bl_types/bl_object.py @@ -22,7 +22,6 @@ import bpy import mathutils from replication.exception import ContextError -from ..utils import get_datablock_from_uuid from .bl_datablock import BlDatablock from .dump_anything import Dumper, Loader from replication.exception import ReparentException diff --git a/multi_user/bl_types/bl_scene.py b/multi_user/bl_types/bl_scene.py index 1b9b78c..1cecf67 100644 --- a/multi_user/bl_types/bl_scene.py +++ b/multi_user/bl_types/bl_scene.py @@ -22,7 +22,6 @@ import mathutils from .dump_anything import Loader, Dumper from .bl_datablock import BlDatablock from .bl_collection import dump_collection_children, dump_collection_objects, load_collection_childrens, load_collection_objects -from ..utils import get_preferences from replication.constants import (DIFF_JSON, MODIFIED) from deepdiff import DeepDiff import logging diff --git a/multi_user/utils.py b/multi_user/utils.py index 75c1391..2c9c607 100644 --- a/multi_user/utils.py +++ b/multi_user/utils.py @@ -81,19 +81,6 @@ def resolve_from_id(id, optionnal_type=None): return None -def get_datablock_from_uuid(uuid, default, ignore=[]): - if not uuid: - return default - - for category in dir(bpy.data): - root = getattr(bpy.data, category) - if isinstance(root, Iterable) and category not in ignore: - for item in root: - if getattr(item, 'uuid', None) == uuid: - return item - return default - - def get_preferences(): return bpy.context.preferences.addons[__package__].preferences