[Bf-blender-cvs] [106a9b89f19] shot-tools-development: Loading production configuration

Jeroen Bakker noreply at git.blender.org
Fri Jan 15 12:09:35 CET 2021


Commit: 106a9b89f19ac90f485ce2b068b0608760282834
Author: Jeroen Bakker
Date:   Fri Jan 15 09:22:34 2021 +0100
Branches: shot-tools-development
https://developer.blender.org/rB106a9b89f19ac90f485ce2b068b0608760282834

Loading production configuration

The configuration of the production is now loaded from the production itself.

===================================================================

M	shot-builder/shot_builder/operators.py
M	shot-builder/shot_builder/project.py
A	shot-builder/shot_builder/sys_utils.py

===================================================================

diff --git a/shot-builder/shot_builder/operators.py b/shot-builder/shot_builder/operators.py
index d3a5e8d6313..e37da531fe5 100644
--- a/shot-builder/shot_builder/operators.py
+++ b/shot-builder/shot_builder/operators.py
@@ -12,10 +12,16 @@ class SHOTBUILDER_OT_NewShotFile(bpy.types.Operator):
 
     production_root: bpy.props.StringProperty(
         name="Production Root",
-        description="Root of the production.",
+        description="Root of the production",
         subtype='DIR_PATH',
     )
 
+    production_name: bpy.props.StringProperty(
+        name="Production",
+        description="Name of the production to create a shot file for",
+        options=set()
+    )
+
     shot_id: bpy.props.StringProperty(
         name="Shot ID",
         description="Shot ID of the shot to build",
@@ -35,6 +41,7 @@ class SHOTBUILDER_OT_NewShotFile(bpy.types.Operator):
         ensure_loaded_production(context)
         production = get_active_production()
         self.production_root = str(production.path)
+        self.production_name = production.name
         
         return context.window_manager.invoke_props_dialog(self, width = 400)
     
@@ -44,6 +51,9 @@ class SHOTBUILDER_OT_NewShotFile(bpy.types.Operator):
 
     def draw(self, context):
         layout = self.layout
+        row = layout.row()
+        row.enabled = False
+        row.prop(self, "production_name")
         layout.prop(self, "shot_id")
         layout.prop(self, "task_type")
     
\ No newline at end of file
diff --git a/shot-builder/shot_builder/project.py b/shot-builder/shot_builder/project.py
index 71151a13ebf..33328b7bcdf 100644
--- a/shot-builder/shot_builder/project.py
+++ b/shot-builder/shot_builder/project.py
@@ -20,11 +20,13 @@
 
 import pathlib
 import logging
+import importlib
 from typing import *
 
 import bpy
 
 from shot_builder.task_type import *
+from shot_builder.sys_utils import *
 
 
 logger = logging.getLogger(__name__)
@@ -33,11 +35,19 @@ logger = logging.getLogger(__name__)
 class Production():
     """
     Class containing data and methods for a production.
+
+    # Data members #
+    path: contains the path to the root of the production.
+    task_types: contains a list of `TaskType`s that are defined for this
+        production. By default the task_types are prefilled with anim and light.
+    name: human readable name of the production.
+
     """
     def __init__(self, production_path: pathlib.Path):
         self.path = production_path
         self.task_types = []
         self.task_types.extend([TaskType('anim'), TaskType('light')])
+        self.name = "Unnamed production"
 
     def get_task_types_items(self) -> list:
         """
@@ -48,6 +58,14 @@ class Production():
             (task_type.name, task_type.name, task_type.name)
             for task_type in self.task_types
         ]
+
+    # TODO: what is the typing for a module. Unable to use `: module`
+    def _load_config(self, main_config_mod):
+        self.name = getattr(main_config_mod, "PRODUCTION_NAME", self.name)
+        task_types = getattr(main_config_mod, "TASK_TYPES", None)
+        if task_types:
+            self.task_types = [TaskType(task_type) for task_type in task_types]
+
     
 
 _PRODUCTION: Optional[Production] = None
@@ -137,6 +155,13 @@ def __load_production_configuration(context: bpy.types.Context,
                                     production_path: pathlib.Path) -> bool:
     global _PRODUCTION
     _PRODUCTION = Production(production_path)
+    paths = [production_path/"shot-builder"]
+    with SystemPathInclude(paths) as _include:
+        import config as production_config
+        importlib.reload(production_config)
+        _PRODUCTION._load_config(production_config)
+        pass
+
     return False
 
 
diff --git a/shot-builder/shot_builder/sys_utils.py b/shot-builder/shot_builder/sys_utils.py
new file mode 100644
index 00000000000..fa3a9dc5781
--- /dev/null
+++ b/shot-builder/shot_builder/sys_utils.py
@@ -0,0 +1,57 @@
+# ##### BEGIN GPL LICENSE BLOCK #####
+#
+#  This program is free software; you can redistribute it and/or
+#  modify it under the terms of the GNU General Public License
+#  as published by the Free Software Foundation; either version 2
+#  of the License, or (at your option) any later version.
+#
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#  GNU General Public License for more details.
+#
+#  You should have received a copy of the GNU General Public License
+#  along with this program; if not, write to the Free Software Foundation,
+#  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# ##### END GPL LICENSE BLOCK #####
+
+# <pep8 compliant>
+
+import sys
+import pathlib
+from typing import List
+
+class SystemPathInclude:
+
+    """
+    Resource class to temporary include system paths to `sys.paths`.
+
+    Usage:
+        ```
+        paths = [pathlib.Path("/home/guest/my_python_scripts")]
+        with SystemPathInclude(paths) as t:
+            import my_module
+            reload(my_module)
+        ```
+
+    It is possible to nest multiple SystemPathIncludes.
+    """
+    def __init__(self, paths_to_add: List[pathlib.Path]):
+        # TODO: Check if all paths exist and are absolute.
+        self.__paths = paths_to_add
+        self.__original_sys_path = None
+
+    def __enter__(self):
+        self.__original_sys_path = sys.path
+        for path_to_add in self.__paths:
+            # Do not add paths that are already in the sys path.
+            # Report this to the logger as this might indicate wrong usage.
+            path_to_add_str = str(path_to_add)
+            if path_to_add_str in self.__original_sys_path:
+                logger.warn(f"{path_to_add_str} already added to `sys.path`")
+                continue
+            sys.path.append(path_to_add_str)
+    
+    def __exit__(self, exc_type, exc_value, exc_traceback):
+        sys.path = self.__original_sys_path



More information about the Bf-blender-cvs mailing list