From a99eee7873aa841271a7fac8a1c7762385aafffc Mon Sep 17 00:00:00 2001 From: Nick Alberelli Date: Wed, 19 Jul 2023 11:44:14 -0400 Subject: [PATCH 1/8] Blender Kitsu: Checker Test Operators --- .../addons/blender_kitsu/__init__.py | 4 ++ .../addons/blender_kitsu/checker/__init__.py | 19 +++++++ .../addons/blender_kitsu/checker/ops.py | 49 +++++++++++++++++++ 3 files changed, 72 insertions(+) create mode 100644 scripts-blender/addons/blender_kitsu/checker/__init__.py create mode 100644 scripts-blender/addons/blender_kitsu/checker/ops.py diff --git a/scripts-blender/addons/blender_kitsu/__init__.py b/scripts-blender/addons/blender_kitsu/__init__.py index 50c14db9..45c92b5f 100644 --- a/scripts-blender/addons/blender_kitsu/__init__.py +++ b/scripts-blender/addons/blender_kitsu/__init__.py @@ -28,6 +28,7 @@ from blender_kitsu import ( bkglobals, types, cache, + checker, models, playblast, propsdata, @@ -78,6 +79,7 @@ if _need_reload: ui = importlib.reload(ui) sqe.reload() util = importlib.reload(util) + checker = importlib.reload(checker) generic.reload() auth.reload() context.reload() @@ -89,6 +91,7 @@ def register(): lookdev.register() prefs.register() cache.register() + checker.register() props.register() sqe.register() generic.register() @@ -111,6 +114,7 @@ def unregister(): generic.unregister() sqe.unregister() props.unregister() + checker.unregister() cache.unregister() prefs.unregister() lookdev.unregister() diff --git a/scripts-blender/addons/blender_kitsu/checker/__init__.py b/scripts-blender/addons/blender_kitsu/checker/__init__.py new file mode 100644 index 00000000..66621b13 --- /dev/null +++ b/scripts-blender/addons/blender_kitsu/checker/__init__.py @@ -0,0 +1,19 @@ +import importlib +from blender_kitsu.checker import ops + + +# ---------REGISTER ----------. + + +def reload(): + global ops + + ops = importlib.reload(ops) + + +def register(): + ops.register() + + +def unregister(): + ops.unregister() diff --git a/scripts-blender/addons/blender_kitsu/checker/ops.py b/scripts-blender/addons/blender_kitsu/checker/ops.py new file mode 100644 index 00000000..188679e7 --- /dev/null +++ b/scripts-blender/addons/blender_kitsu/checker/ops.py @@ -0,0 +1,49 @@ +import bpy + + +class KITSU_OT_test_op(bpy.types.Operator): + bl_idname = "kitsu.test_op" + bl_label = 'test' + + text: bpy.props.StringProperty(name='test', default='') + + def execute(self, context): + if self.text != "test": + self.report({'ERROR'}, "Failure") + return {'CANCELLED'} + self.report({'INFO'}, "Success") + return {'FINISHED'} + + +class KITSU_OT_convention_checker(bpy.types.Operator): + bl_idname = "kitsu.convention_checker" + bl_label = 'Convention Checker' + + def execute(self, context): + # TODO read types out of json File + # TODO check operator exists before execution + # INFO python3 -m json.tool file.json to 'pretty print' json + try: + bpy.ops.kitsu.test_op() + except RuntimeError as ex: + ex + self.report({'INFO'}, "CONFIRMED FAILURE") + else: + self.report({'INFO'}, "CONFIRMED SUCCESS") + return {'FINISHED'} + + +classes = [ + KITSU_OT_test_op, + KITSU_OT_convention_checker, +] + + +def register(): + for cls in classes: + bpy.utils.register_class(cls) + + +def unregister(): + for cls in reversed(classes): + bpy.utils.unregister_class(cls) -- 2.30.2 From d44d492c7a0a297089c4bc3ddbcd4d2add7f2d87 Mon Sep 17 00:00:00 2001 From: Nick Alberelli Date: Wed, 19 Jul 2023 11:44:14 -0400 Subject: [PATCH 2/8] Blender_Kitsu: Checker Create Test Data --- scripts-blender/addons/blender_kitsu/checker/test.json | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 scripts-blender/addons/blender_kitsu/checker/test.json diff --git a/scripts-blender/addons/blender_kitsu/checker/test.json b/scripts-blender/addons/blender_kitsu/checker/test.json new file mode 100644 index 00000000..90aaf27e --- /dev/null +++ b/scripts-blender/addons/blender_kitsu/checker/test.json @@ -0,0 +1,5 @@ +{ + "anim": [ + "bpy.ops.kitsu.test_op()" + ] +} \ No newline at end of file -- 2.30.2 From efec4a089b551a33d20f7d6c1202d0cc973a714a Mon Sep 17 00:00:00 2001 From: Nick Alberelli Date: Wed, 19 Jul 2023 11:44:15 -0400 Subject: [PATCH 3/8] Blender Kitsu: Test Reading Checker Data from JSON --- .../addons/blender_kitsu/checker/ops.py | 35 ++++++++++++++----- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/scripts-blender/addons/blender_kitsu/checker/ops.py b/scripts-blender/addons/blender_kitsu/checker/ops.py index 188679e7..d33e88db 100644 --- a/scripts-blender/addons/blender_kitsu/checker/ops.py +++ b/scripts-blender/addons/blender_kitsu/checker/ops.py @@ -1,11 +1,13 @@ import bpy +import json +from bpy.ops import op_as_string class KITSU_OT_test_op(bpy.types.Operator): bl_idname = "kitsu.test_op" bl_label = 'test' - text: bpy.props.StringProperty(name='test', default='') + text: bpy.props.StringProperty(name='test', default='test') def execute(self, context): if self.text != "test": @@ -20,16 +22,31 @@ class KITSU_OT_convention_checker(bpy.types.Operator): bl_label = 'Convention Checker' def execute(self, context): - # TODO read types out of json File # TODO check operator exists before execution # INFO python3 -m json.tool file.json to 'pretty print' json - try: - bpy.ops.kitsu.test_op() - except RuntimeError as ex: - ex - self.report({'INFO'}, "CONFIRMED FAILURE") - else: - self.report({'INFO'}, "CONFIRMED SUCCESS") + json_file = __file__.replace( + "ops.py", "test.json" + ) # TODO remove test file and replace with prefs path + with open(json_file, "r") as f: + data = json.load(f) + print(data) + + check_ops = [] + + for item in data: + if item == 'anim': + for op in data[item]: + # TODO Test if op is unavaliable + check_ops.append(op) + + for op in check_ops: + try: + exec(op) + except RuntimeError as ex: + args = ex.args[0].split(':') + self.report({args[0].upper()}, f"{op}:{args[1]}") + else: + self.report({'INFO'}, f"{op}: SUCCESS") return {'FINISHED'} -- 2.30.2 From 90e154f42db7f538dd1951a06ca96a48d619e1e2 Mon Sep 17 00:00:00 2001 From: Nick Alberelli Date: Wed, 19 Jul 2023 11:44:15 -0400 Subject: [PATCH 4/8] Blender Kitsu: Add Checker Config Dir to Addon Prefs --- scripts-blender/addons/blender_kitsu/prefs.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/scripts-blender/addons/blender_kitsu/prefs.py b/scripts-blender/addons/blender_kitsu/prefs.py index e2d2545e..53a9186f 100644 --- a/scripts-blender/addons/blender_kitsu/prefs.py +++ b/scripts-blender/addons/blender_kitsu/prefs.py @@ -331,6 +331,13 @@ class KITSU_addon_preferences(bpy.types.AddonPreferences): default="", ) + convention_config: bpy.props.StringProperty( # type: ignore + name="Convention Checker Config Directory", + options={"HIDDEN", "SKIP_SAVE"}, + description="Path to convention checker configuration file.", + subtype="DIR_PATH", + ) + session: Session = Session() tasks: bpy.props.CollectionProperty(type=KITSU_task) @@ -425,6 +432,13 @@ class KITSU_addon_preferences(bpy.types.AddonPreferences): box.row().prop(self, "shot_builder_action_prefix") box.row().prop(self, "user_exec_code") + # Convention Checker + box = layout.box() + box.label( + text="Convention Checker", + ) + box.row().prop(self, "convention_config") + # Misc settings. box = layout.box() box.label(text="Miscellaneous", icon="MODIFIER") -- 2.30.2 From 61de74a79de5a44db7df00b9fb5e1ea567534d71 Mon Sep 17 00:00:00 2001 From: Nick Alberelli Date: Wed, 19 Jul 2023 11:44:16 -0400 Subject: [PATCH 5/8] Blender Kitsu: Only run Checker if config file is valid --- .../addons/blender_kitsu/checker/ops.py | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/scripts-blender/addons/blender_kitsu/checker/ops.py b/scripts-blender/addons/blender_kitsu/checker/ops.py index d33e88db..881adcea 100644 --- a/scripts-blender/addons/blender_kitsu/checker/ops.py +++ b/scripts-blender/addons/blender_kitsu/checker/ops.py @@ -1,6 +1,8 @@ import bpy import json from bpy.ops import op_as_string +from pathlib import Path + class KITSU_OT_test_op(bpy.types.Operator): @@ -17,17 +19,30 @@ class KITSU_OT_test_op(bpy.types.Operator): return {'FINISHED'} +def get_config(): + addon_prefs = bpy.context.preferences.addons["blender_kitsu"].preferences + config_file = addon_prefs.convention_config + return Path(config_file).joinpath('convention_checker.json') + + class KITSU_OT_convention_checker(bpy.types.Operator): bl_idname = "kitsu.convention_checker" bl_label = 'Convention Checker' + @classmethod + def poll(cls, context: bpy.types.Context) -> bool: + config_file = get_config() + if not config_file.exists(): + cls.poll_message_set( + "Convention Checker config file not found. Check add-on preferences" + ) + return config_file.exists() + def execute(self, context): # TODO check operator exists before execution # INFO python3 -m json.tool file.json to 'pretty print' json - json_file = __file__.replace( - "ops.py", "test.json" - ) # TODO remove test file and replace with prefs path - with open(json_file, "r") as f: + config_file = get_config() + with open(config_file, "r") as f: data = json.load(f) print(data) -- 2.30.2 From 35399511f8d3d312a9eee3d424080a0e05a3081b Mon Sep 17 00:00:00 2001 From: Nick Alberelli Date: Wed, 19 Jul 2023 11:44:16 -0400 Subject: [PATCH 6/8] Blender Kitsu: Add Test UI for Convention Checker --- scripts-blender/addons/blender_kitsu/checker/ops.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/scripts-blender/addons/blender_kitsu/checker/ops.py b/scripts-blender/addons/blender_kitsu/checker/ops.py index 881adcea..2100bb0b 100644 --- a/scripts-blender/addons/blender_kitsu/checker/ops.py +++ b/scripts-blender/addons/blender_kitsu/checker/ops.py @@ -4,6 +4,18 @@ from bpy.ops import op_as_string from pathlib import Path +class KITSU_PT_convention_checker_temp_ui(bpy.types.Panel): + # TODO: Remove this UI, for Testing only + + bl_category = "Checker Test" + bl_label = "Convention Chekcer Test UI" + bl_space_type = "VIEW_3D" + bl_region_type = "UI" + + def draw(self, context: bpy.types.Context) -> None: + layout = self.layout + layout.operator("kitsu.convention_checker") + class KITSU_OT_test_op(bpy.types.Operator): bl_idname = "kitsu.test_op" @@ -68,6 +80,7 @@ class KITSU_OT_convention_checker(bpy.types.Operator): classes = [ KITSU_OT_test_op, KITSU_OT_convention_checker, + KITSU_PT_convention_checker_temp_ui, ] -- 2.30.2 From 3a501eb4c532ff92f0ba781765c94bd1edc6eb70 Mon Sep 17 00:00:00 2001 From: Nick Alberelli Date: Wed, 19 Jul 2023 11:44:17 -0400 Subject: [PATCH 7/8] Blender Kitsu: Update Checker TODOs --- scripts-blender/addons/blender_kitsu/checker/ops.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scripts-blender/addons/blender_kitsu/checker/ops.py b/scripts-blender/addons/blender_kitsu/checker/ops.py index 2100bb0b..77b0f0c5 100644 --- a/scripts-blender/addons/blender_kitsu/checker/ops.py +++ b/scripts-blender/addons/blender_kitsu/checker/ops.py @@ -61,9 +61,8 @@ class KITSU_OT_convention_checker(bpy.types.Operator): check_ops = [] for item in data: - if item == 'anim': + if item == 'anim': # TODO use current task type for op in data[item]: - # TODO Test if op is unavaliable check_ops.append(op) for op in check_ops: -- 2.30.2 From 6873892805988c0b5f7e3cc534c9ba6e5e7a5235 Mon Sep 17 00:00:00 2001 From: Nick Alberelli Date: Mon, 24 Jul 2023 14:44:44 +0200 Subject: [PATCH 8/8] Blender Kitsu: Fix Type --- scripts-blender/addons/blender_kitsu/checker/ops.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts-blender/addons/blender_kitsu/checker/ops.py b/scripts-blender/addons/blender_kitsu/checker/ops.py index 77b0f0c5..fa794a7b 100644 --- a/scripts-blender/addons/blender_kitsu/checker/ops.py +++ b/scripts-blender/addons/blender_kitsu/checker/ops.py @@ -14,7 +14,7 @@ class KITSU_PT_convention_checker_temp_ui(bpy.types.Panel): def draw(self, context: bpy.types.Context) -> None: layout = self.layout - layout.operator("kitsu.convention_checker") + layout.operator('kitsu.convention_checker') class KITSU_OT_test_op(bpy.types.Operator): -- 2.30.2