[Bf-blender-cvs] [c0281f2530d] shot-tools-development: Added initial connector API

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


Commit: c0281f2530d2ecb2d77e307c7bc2815df9b003e5
Author: Jeroen Bakker
Date:   Fri Jan 15 12:03:25 2021 +0100
Branches: shot-tools-development
https://developer.blender.org/rBc0281f2530d2ecb2d77e307c7bc2815df9b003e5

Added initial connector API

Adds a DefaultConnector and a KitsuConnector. These connectors can be
used to retrieve task_types and shots from an external system.

The default connector is used as the default configuration when a
configuration key isn't defined.

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

M	shot-builder/shot_builder/__init__.py
A	shot-builder/shot_builder/connectors/__init__.py
A	shot-builder/shot_builder/connectors/connector.py
A	shot-builder/shot_builder/connectors/default.py
A	shot-builder/shot_builder/connectors/kitsu.py
M	shot-builder/shot_builder/operators.py
M	shot-builder/shot_builder/project.py
M	shot-builder/shot_builder/properties.py
A	shot-builder/shot_builder/shot.py
M	shot-builder/shot_builder/task_type.py
M	shot-builder/shot_builder/ui.py

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

diff --git a/shot-builder/shot_builder/__init__.py b/shot-builder/shot_builder/__init__.py
index d86836b54ea..f4ec69d0d0f 100644
--- a/shot-builder/shot_builder/__init__.py
+++ b/shot-builder/shot_builder/__init__.py
@@ -18,6 +18,13 @@
 
 # <pep8 compliant>
 
+from shot_builder.ui import *
+from shot_builder.connectors.kitsu import *
+from shot_builder.operators import *
+from shot_builder.properties import *
+import bpy
+
+
 bl_info = {
     'name': 'Shot Builder',
     "author": "Jeroen Bakker",
@@ -28,14 +35,9 @@ bl_info = {
     'category': 'Studio',
 }
 
-import bpy
-
-from shot_builder.properties import *
-from shot_builder.operators import *
-from shot_builder.ui import *
-
 
 classes = (
+    KitsuPreferences,
     ShotBuilderPreferences,
     SHOTBUILDER_OT_NewShotFile,
 )
diff --git a/shot-builder/shot_builder/__init__.py b/shot-builder/shot_builder/connectors/__init__.py
similarity index 50%
copy from shot-builder/shot_builder/__init__.py
copy to shot-builder/shot_builder/connectors/__init__.py
index d86836b54ea..b07da1ed8b9 100644
--- a/shot-builder/shot_builder/__init__.py
+++ b/shot-builder/shot_builder/connectors/__init__.py
@@ -16,38 +16,4 @@
 #
 # ##### END GPL LICENSE BLOCK #####
 
-# <pep8 compliant>
-
-bl_info = {
-    'name': 'Shot Builder',
-    "author": "Jeroen Bakker",
-    'version': (0, 1),
-    'blender': (2, 90, 0),
-    'location': 'Addon Preferences panel and file new menu',
-    'description': 'Shot builder production tool.',
-    'category': 'Studio',
-}
-
-import bpy
-
-from shot_builder.properties import *
-from shot_builder.operators import *
-from shot_builder.ui import *
-
-
-classes = (
-    ShotBuilderPreferences,
-    SHOTBUILDER_OT_NewShotFile,
-)
-
-
-def register():
-    for cls in classes:
-        bpy.utils.register_class(cls)
-    bpy.types.TOPBAR_MT_file_new.append(topbar_file_new_draw_handler)
-
-
-def unregister():
-    bpy.types.TOPBAR_MT_file_new.remove(topbar_file_new_draw_handler)
-    for cls in classes:
-        bpy.utils.unregister_class(cls)
+# <pep8 compliant>
\ No newline at end of file
diff --git a/shot-builder/shot_builder/connectors/connector.py b/shot-builder/shot_builder/connectors/connector.py
new file mode 100644
index 00000000000..0d228057565
--- /dev/null
+++ b/shot-builder/shot_builder/connectors/connector.py
@@ -0,0 +1,44 @@
+# ##### 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>
+from shot_builder.shot import Shot
+from shot_builder.task_type import TaskType
+from typing import List
+
+
+class Connector:
+    PRODUCTION_KEYS = set()
+    # Local imports for type-info
+    # TODO: Add type info (shot_builder.project.Production, shot_builder.properties.ShotBuilderPreferences)
+
+    def __init__(self, production, preferences):
+        self._production = production
+        self._preferences = preferences
+
+    def get_name(self) -> str:
+        raise NotImplementedError(
+            f"{self.__class__.__name__} does not support retrieval of production name")
+
+    def get_task_types(self) -> List[TaskType]:
+        raise NotImplementedError(
+            f"{self.__class__.__name__} does not support retrieval of task types")
+
+    def get_shots(self) -> List[Shot]:
+        raise NotImplementedError(
+            f"{self.__class__.__name__} does not support retrieval of shots")
diff --git a/shot-builder/shot_builder/__init__.py b/shot-builder/shot_builder/connectors/default.py
similarity index 51%
copy from shot-builder/shot_builder/__init__.py
copy to shot-builder/shot_builder/connectors/default.py
index d86836b54ea..e3479fcc9dc 100644
--- a/shot-builder/shot_builder/__init__.py
+++ b/shot-builder/shot_builder/connectors/default.py
@@ -17,37 +17,15 @@
 # ##### END GPL LICENSE BLOCK #####
 
 # <pep8 compliant>
+from shot_builder.shot import Shot
+from shot_builder.task_type import TaskType
+from shot_builder.connectors.connector import Connector
+from typing import List
 
-bl_info = {
-    'name': 'Shot Builder',
-    "author": "Jeroen Bakker",
-    'version': (0, 1),
-    'blender': (2, 90, 0),
-    'location': 'Addon Preferences panel and file new menu',
-    'description': 'Shot builder production tool.',
-    'category': 'Studio',
-}
 
-import bpy
+class DefaultConnector(Connector):
+    def get_shots(self) -> List[Shot]:
+        return []
 
-from shot_builder.properties import *
-from shot_builder.operators import *
-from shot_builder.ui import *
-
-
-classes = (
-    ShotBuilderPreferences,
-    SHOTBUILDER_OT_NewShotFile,
-)
-
-
-def register():
-    for cls in classes:
-        bpy.utils.register_class(cls)
-    bpy.types.TOPBAR_MT_file_new.append(topbar_file_new_draw_handler)
-
-
-def unregister():
-    bpy.types.TOPBAR_MT_file_new.remove(topbar_file_new_draw_handler)
-    for cls in classes:
-        bpy.utils.unregister_class(cls)
+    def get_task_types(self) -> List[TaskType]:
+        return [TaskType("anim"), TaskType("light")]
diff --git a/shot-builder/shot_builder/connectors/kitsu.py b/shot-builder/shot_builder/connectors/kitsu.py
new file mode 100644
index 00000000000..5c9e41852c6
--- /dev/null
+++ b/shot-builder/shot_builder/connectors/kitsu.py
@@ -0,0 +1,73 @@
+# ##### 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 bpy
+from typing import List
+from shot_builder.shot import Shot
+from shot_builder.connectors.connector import Connector
+import requests
+
+import logging
+
+logger = logging.getLogger(__name__)
+
+
+class KitsuError(Exception):
+    pass
+
+
+class KitsuPreferences(bpy.types.PropertyGroup):
+    username: bpy.props.StringProperty(
+        name="Username",
+        description="Username to connect to Kitsu",)
+    password: bpy.props.StringProperty(
+        name="Password",
+        description="Password to connect to Kitsu",
+        subtype='PASSWORD',)
+
+    def draw(self, layout: bpy.types.UILayout, context: bpy.types.Context):
+        layout.label(text="Kitsu")
+        layout.prop(self, "username")
+        layout.prop(self, "password")
+
+
+class KitsuConnector(Connector):
+    PRODUCTION_KEYS = {'KITSU_BACKEND', 'KITSU_PRODUCTION_ID'}
+
+    def __init__(self, **kwargs):
+        super().__init__(**kwargs)
+        self.__jwt_access_token = ""
+        self.__authorize()
+
+    def __authorize(self):
+        username = self._preferences.kitsu.username
+        password = self._preferences.kitsu.password
+        backend = self._production.config['KITSU_BACKEND']
+        logger.info(f"authorize {username} against {backend}")
+        response = requests.post(
+            url=f"{backend}/auth/login", data={'email': username, 'password': password})
+        if response.status_code != 200:
+            self.__jwt_access_token = ""
+            raise KitsuException(
+                f"unable to authorize (status code={response.status_code})")
+        json_response = response.json()
+        self.__jwt_access_token = json_response['access_token']
+
+    def get_shots(self) -> List[Shot]:
+        return []
diff --git a/shot-builder/shot_builder/operators.py b/shot-builder/shot_builder/operators.py
index e37da531fe5..463543a0ac6 100644
--- a/shot-builder/shot_builder/operators.py
+++ b/shot-builder/shot_builder/operators.py
@@ -1,9 +1,36 @@
+# ##### 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>
+from typing import *
 import bpy
 from shot_builder.project import *
 
-def production_task_types_items(self, context: bpy.types.Context) -> list:
+
+def production_task_type_items(self, context: bpy.types.Context) -> List[Tuple[str, str, str]]:
+    production = get_active_production()
+    return production.get_task_type_items(context=context)
+
+
+def production_shot_id_items(self, context: bpy.types.Context) -> List[Tuple[str, str, str]]:
     production = get_active_production()
-    return production.get_task_types_items()
+    return production.get_shot_items(context=context)
+
 
 class SHOTBUILDER_OT_NewShotFile(bpy.types.Operator):
  

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list