mirror of
https://github.com/ynput/ayon-core.git
synced 2026-01-01 16:34:53 +01:00
replace avalon_apps with library loader action
This commit is contained in:
parent
d699a17e93
commit
dfff50a6d6
4 changed files with 4 additions and 178 deletions
|
|
@ -1,6 +0,0 @@
|
|||
from .avalon_app import AvalonModule
|
||||
|
||||
|
||||
__all__ = (
|
||||
"AvalonModule",
|
||||
)
|
||||
|
|
@ -1,131 +0,0 @@
|
|||
import json
|
||||
import datetime
|
||||
|
||||
from bson.objectid import ObjectId
|
||||
|
||||
from aiohttp.web_response import Response
|
||||
|
||||
from ayon_core.client import (
|
||||
get_projects,
|
||||
get_project,
|
||||
get_assets,
|
||||
get_asset_by_name,
|
||||
)
|
||||
from openpype_modules.webserver.base_routes import RestApiEndpoint
|
||||
|
||||
|
||||
class _RestApiEndpoint(RestApiEndpoint):
|
||||
def __init__(self, resource):
|
||||
self.resource = resource
|
||||
super(_RestApiEndpoint, self).__init__()
|
||||
|
||||
|
||||
class AvalonProjectsEndpoint(_RestApiEndpoint):
|
||||
async def get(self) -> Response:
|
||||
output = [
|
||||
project_doc
|
||||
for project_doc in get_projects()
|
||||
]
|
||||
return Response(
|
||||
status=200,
|
||||
body=self.resource.encode(output),
|
||||
content_type="application/json"
|
||||
)
|
||||
|
||||
|
||||
class AvalonProjectEndpoint(_RestApiEndpoint):
|
||||
async def get(self, project_name) -> Response:
|
||||
project_doc = get_project(project_name)
|
||||
if project_doc:
|
||||
return Response(
|
||||
status=200,
|
||||
body=self.resource.encode(project_doc),
|
||||
content_type="application/json"
|
||||
)
|
||||
return Response(
|
||||
status=404,
|
||||
reason="Project name {} not found".format(project_name)
|
||||
)
|
||||
|
||||
|
||||
class AvalonAssetsEndpoint(_RestApiEndpoint):
|
||||
async def get(self, project_name) -> Response:
|
||||
asset_docs = list(get_assets(project_name))
|
||||
return Response(
|
||||
status=200,
|
||||
body=self.resource.encode(asset_docs),
|
||||
content_type="application/json"
|
||||
)
|
||||
|
||||
|
||||
class AvalonAssetEndpoint(_RestApiEndpoint):
|
||||
async def get(self, project_name, asset_name) -> Response:
|
||||
asset_doc = get_asset_by_name(project_name, asset_name)
|
||||
if asset_doc:
|
||||
return Response(
|
||||
status=200,
|
||||
body=self.resource.encode(asset_doc),
|
||||
content_type="application/json"
|
||||
)
|
||||
return Response(
|
||||
status=404,
|
||||
reason="Asset name {} not found in project {}".format(
|
||||
asset_name, project_name
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
class AvalonRestApiResource:
|
||||
def __init__(self, avalon_module, server_manager):
|
||||
self.module = avalon_module
|
||||
self.server_manager = server_manager
|
||||
|
||||
self.prefix = "/avalon"
|
||||
|
||||
self.endpoint_defs = (
|
||||
(
|
||||
"GET",
|
||||
"/projects",
|
||||
AvalonProjectsEndpoint(self)
|
||||
),
|
||||
(
|
||||
"GET",
|
||||
"/projects/{project_name}",
|
||||
AvalonProjectEndpoint(self)
|
||||
),
|
||||
(
|
||||
"GET",
|
||||
"/projects/{project_name}/assets",
|
||||
AvalonAssetsEndpoint(self)
|
||||
),
|
||||
(
|
||||
"GET",
|
||||
"/projects/{project_name}/assets/{asset_name}",
|
||||
AvalonAssetEndpoint(self)
|
||||
)
|
||||
)
|
||||
|
||||
self.register()
|
||||
|
||||
def register(self):
|
||||
for methods, url, endpoint in self.endpoint_defs:
|
||||
final_url = self.prefix + url
|
||||
self.server_manager.add_route(
|
||||
methods, final_url, endpoint.dispatch
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def json_dump_handler(value):
|
||||
if isinstance(value, datetime.datetime):
|
||||
return value.isoformat()
|
||||
if isinstance(value, ObjectId):
|
||||
return str(value)
|
||||
raise TypeError(value)
|
||||
|
||||
@classmethod
|
||||
def encode(cls, data):
|
||||
return json.dumps(
|
||||
data,
|
||||
indent=4,
|
||||
default=cls.json_dump_handler
|
||||
).encode("utf-8")
|
||||
|
|
@ -1278,7 +1278,7 @@ class TrayModulesManager(ModulesManager):
|
|||
"ftrack",
|
||||
"kitsu",
|
||||
"launcher_tool",
|
||||
"avalon",
|
||||
"library_tool",
|
||||
"clockify",
|
||||
"standalonepublish_tool",
|
||||
"traypublish_tool",
|
||||
|
|
|
|||
|
|
@ -1,43 +1,13 @@
|
|||
import os
|
||||
|
||||
from ayon_core.modules import OpenPypeModule, ITrayModule
|
||||
from ayon_core.modules import AYONAddon, ITrayModule
|
||||
|
||||
|
||||
class AvalonModule(OpenPypeModule, ITrayModule):
|
||||
name = "avalon"
|
||||
class LibraryLoaderAddon(AYONAddon, ITrayModule):
|
||||
name = "library_tool"
|
||||
|
||||
def initialize(self, modules_settings):
|
||||
# This module is always enabled
|
||||
self.enabled = True
|
||||
|
||||
avalon_settings = modules_settings[self.name]
|
||||
|
||||
thumbnail_root = os.environ.get("AVALON_THUMBNAIL_ROOT")
|
||||
if not thumbnail_root:
|
||||
thumbnail_root = avalon_settings["AVALON_THUMBNAIL_ROOT"]
|
||||
|
||||
# Mongo timeout
|
||||
avalon_mongo_timeout = os.environ.get("AVALON_TIMEOUT")
|
||||
if not avalon_mongo_timeout:
|
||||
avalon_mongo_timeout = avalon_settings["AVALON_TIMEOUT"]
|
||||
|
||||
self.thumbnail_root = thumbnail_root
|
||||
self.avalon_mongo_timeout = avalon_mongo_timeout
|
||||
|
||||
# Tray attributes
|
||||
self._library_loader_imported = None
|
||||
self._library_loader_window = None
|
||||
self.rest_api_obj = None
|
||||
|
||||
def get_global_environments(self):
|
||||
"""Avalon global environments for pype implementation."""
|
||||
return {
|
||||
# TODO thumbnails root should be multiplafrom
|
||||
# - thumbnails root
|
||||
"AVALON_THUMBNAIL_ROOT": self.thumbnail_root,
|
||||
# - mongo timeout in ms
|
||||
"AVALON_TIMEOUT": str(self.avalon_mongo_timeout),
|
||||
}
|
||||
|
||||
def tray_init(self):
|
||||
# Add library tool
|
||||
|
|
@ -89,13 +59,6 @@ class AvalonModule(OpenPypeModule, ITrayModule):
|
|||
# for Windows
|
||||
self._library_loader_window.activateWindow()
|
||||
|
||||
# Webserver module implementation
|
||||
def webserver_initialization(self, server_manager):
|
||||
"""Add routes for webserver."""
|
||||
if self.tray_initialized:
|
||||
from .rest_api import AvalonRestApiResource
|
||||
self.rest_api_obj = AvalonRestApiResource(self, server_manager)
|
||||
|
||||
def _init_library_loader(self):
|
||||
from ayon_core.tools.loader.ui import LoaderWindow
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue