Blender Kitsu: Refactor Shot Builder #183

Merged
Nick Alberelli merged 55 commits from TinyNick/blender-studio-pipeline:feature/shot-builder-2 into main 2023-12-21 23:58:21 +01:00
Showing only changes of commit 04f368b45f - Show all commits

View File

@ -11,6 +11,7 @@ from .core import (
set_resolution_and_fps, set_resolution_and_fps,
set_frame_range, set_frame_range,
link_task_type_output_collections, link_task_type_output_collections,
remove_all_data,
) )
from .editorial import editorial_export_get_latest from .editorial import editorial_export_get_latest
@ -45,6 +46,67 @@ def get_tasks_for_shot(
return [('NONE', "No Tasks Found", '')] return [('NONE', "No Tasks Found", '')]
class KITSU_OT_save_shot_builder_hooks(bpy.types.Operator):
bl_idname = "kitsu.save_shot_builder_hooks"
bl_label = "Save Shot Builder Hook File"
bl_description = "Save hook.py file to `your_project/svn/pro/assets/scripts/shot-builder` directory. Hooks are used to customize shot builder behaviour."
def execute(self, context: bpy.types.Context):
addon_prefs = prefs.addon_prefs_get(context)
project = cache.project_active_get()
if addon_prefs.session.is_auth() is False:
self.report(
{'ERROR'},
"Must be logged into Kitsu to continue. \nCheck login status in 'Blender Kitsu' addon preferences.",
)
return {'CANCELLED'}
if project.id == "":
self.report(
{'ERROR'},
"Operator is not able to determine the Kitsu production's name. \nCheck project is selected in 'Blender Kitsu' addon preferences.",
)
return {'CANCELLED'}
if not addon_prefs.is_project_root_valid:
self.report(
{'ERROR'},
"Operator is not able to determine the project root directory. \nCheck project root directiory is configured in 'Blender Kitsu' addon preferences.",
)
return {'CANCELLED'}
root_dir = prefs.project_root_dir_get(context)
config_dir = root_dir.joinpath("pro/assets/scripts/shot-builder")
if not config_dir.exists():
config_dir.mkdir(parents=True)
hook_file_path = config_dir.joinpath("hooks.py")
if hook_file_path.exists():
self.report(
{'WARNING'},
"File already exists, cannot overwrite",
)
return {'CANCELLED'}
config_dir = Path(__file__).parent
example_hooks_path = config_dir.joinpath("hook_examples/hooks.py")
if not example_hooks_path.exists():
self.report(
{'ERROR'},
"Cannot find example hook file",
)
return {'CANCELLED'}
with example_hooks_path.open() as source:
# Read contents
contents = source.read()
# Write contents to target file
with hook_file_path.open('w') as target:
target.write(contents)
self.report({'INFO'}, f"Hook File saved to {hook_file_path}")
return {'FINISHED'}
class KITSU_OT_build_new_shot(bpy.types.Operator): class KITSU_OT_build_new_shot(bpy.types.Operator):
bl_idname = "kitsu.build_new_shot" bl_idname = "kitsu.build_new_shot"
bl_label = "Build New Shot" bl_label = "Build New Shot"
@ -200,7 +262,7 @@ class KITSU_OT_build_new_shot(bpy.types.Operator):
return {"FINISHED"} return {"FINISHED"}
classes = (KITSU_OT_build_new_shot,) classes = (KITSU_OT_build_new_shot, KITSU_OT_save_shot_builder_hooks)
def register(): def register():