mirror of
https://github.com/ynput/ayon-core.git
synced 2026-01-01 08:24:53 +01:00
allow multiple statics server and fixed few smaller bugs
This commit is contained in:
parent
a0ab0fea88
commit
082fbb3547
2 changed files with 13 additions and 19 deletions
|
|
@ -23,7 +23,9 @@ class AvalonRestApi(RestApi):
|
||||||
if not project_name:
|
if not project_name:
|
||||||
output = {}
|
output = {}
|
||||||
for project_name in self.dbcon.tables():
|
for project_name in self.dbcon.tables():
|
||||||
project = self.dbcon[project_name].find_one({"type": "project"})
|
project = self.dbcon[project_name].find_one({
|
||||||
|
"type": "project"
|
||||||
|
})
|
||||||
output[project_name] = project
|
output[project_name] = project
|
||||||
|
|
||||||
return CallbackResult(data=self.result_to_json(output))
|
return CallbackResult(data=self.result_to_json(output))
|
||||||
|
|
@ -44,7 +46,7 @@ class AvalonRestApi(RestApi):
|
||||||
|
|
||||||
if not self.dbcon.exist_table(_project_name):
|
if not self.dbcon.exist_table(_project_name):
|
||||||
abort(404, "Project \"{}\" was not found in database".format(
|
abort(404, "Project \"{}\" was not found in database".format(
|
||||||
project_name
|
_project_name
|
||||||
))
|
))
|
||||||
|
|
||||||
if not _asset:
|
if not _asset:
|
||||||
|
|
@ -65,7 +67,7 @@ class AvalonRestApi(RestApi):
|
||||||
return asset
|
return asset
|
||||||
|
|
||||||
abort(404, "Asset \"{}\" with {} was not found in project {}".format(
|
abort(404, "Asset \"{}\" with {} was not found in project {}".format(
|
||||||
_asset, identificator, project_name
|
_asset, identificator, _project_name
|
||||||
))
|
))
|
||||||
|
|
||||||
@RestApi.route("/publish/<asset_name>", url_prefix="/premiere", methods="GET")
|
@RestApi.route("/publish/<asset_name>", url_prefix="/premiere", methods="GET")
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ import re
|
||||||
import inspect
|
import inspect
|
||||||
import collections
|
import collections
|
||||||
from .lib import RestMethods
|
from .lib import RestMethods
|
||||||
|
from queue import Queue
|
||||||
|
|
||||||
from pypeapp import Logger
|
from pypeapp import Logger
|
||||||
|
|
||||||
|
|
@ -208,7 +209,7 @@ class _RestApiFactory:
|
||||||
"""
|
"""
|
||||||
registered_objs = []
|
registered_objs = []
|
||||||
unprocessed_routes = []
|
unprocessed_routes = []
|
||||||
unprocessed_statics = []
|
unprocessed_statics = Queue()
|
||||||
|
|
||||||
prepared_routes = {
|
prepared_routes = {
|
||||||
method: collections.defaultdict(list) for method in RestMethods
|
method: collections.defaultdict(list) for method in RestMethods
|
||||||
|
|
@ -220,16 +221,6 @@ class _RestApiFactory:
|
||||||
def has_handlers(self):
|
def has_handlers(self):
|
||||||
return (self.has_routes or self.prepared_statics)
|
return (self.has_routes or self.prepared_statics)
|
||||||
|
|
||||||
def _process_route(self, route):
|
|
||||||
return self.unprocessed_routes.pop(
|
|
||||||
self.unprocessed_routes.index(route)
|
|
||||||
)
|
|
||||||
|
|
||||||
def _process_statics(self, item):
|
|
||||||
return self.unprocessed_statics.pop(
|
|
||||||
self.unprocessed_statics.index(item)
|
|
||||||
)
|
|
||||||
|
|
||||||
def register_route(
|
def register_route(
|
||||||
self, path, callback, url_prefix, methods, strict_match
|
self, path, callback, url_prefix, methods, strict_match
|
||||||
):
|
):
|
||||||
|
|
@ -251,7 +242,7 @@ class _RestApiFactory:
|
||||||
|
|
||||||
def register_statics(self, item):
|
def register_statics(self, item):
|
||||||
log.debug("Registering statics path \"{}\"".format(item))
|
log.debug("Registering statics path \"{}\"".format(item))
|
||||||
self.unprocessed_statics.append(item)
|
self.unprocessed_statics.put(item)
|
||||||
|
|
||||||
def _prepare_route(self, route):
|
def _prepare_route(self, route):
|
||||||
"""Prepare data of registered callbacks for routes.
|
"""Prepare data of registered callbacks for routes.
|
||||||
|
|
@ -290,8 +281,9 @@ class _RestApiFactory:
|
||||||
methods has `__self__` or are defined in <locals> (it is expeted they
|
methods has `__self__` or are defined in <locals> (it is expeted they
|
||||||
do not requise access to object)
|
do not requise access to object)
|
||||||
"""
|
"""
|
||||||
for url_prefix, dir_path in self.unprocessed_statics:
|
|
||||||
self._process_statics((url_prefix, dir_path))
|
while not self.unprocessed_statics.empty():
|
||||||
|
url_prefix, dir_path = self.unprocessed_statics.get()
|
||||||
dir_path = os.path.normpath(dir_path)
|
dir_path = os.path.normpath(dir_path)
|
||||||
if not os.path.exists(dir_path):
|
if not os.path.exists(dir_path):
|
||||||
log.warning(
|
log.warning(
|
||||||
|
|
@ -314,7 +306,7 @@ class _RestApiFactory:
|
||||||
if not method.restapi:
|
if not method.restapi:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
for route in self.unprocessed_routes:
|
for route in list(self.unprocessed_routes):
|
||||||
callback = route["callback"]
|
callback = route["callback"]
|
||||||
if not (
|
if not (
|
||||||
callback.__qualname__ == method.__qualname__ and
|
callback.__qualname__ == method.__qualname__ and
|
||||||
|
|
@ -330,7 +322,7 @@ class _RestApiFactory:
|
||||||
self._prepare_route(route)
|
self._prepare_route(route)
|
||||||
break
|
break
|
||||||
|
|
||||||
for route in self.unprocessed_routes:
|
for route in list(self.unprocessed_routes):
|
||||||
callback = route["callback"]
|
callback = route["callback"]
|
||||||
is_class_method = len(callback.__qualname__.split(".")) != 1
|
is_class_method = len(callback.__qualname__.split(".")) != 1
|
||||||
if is_class_method:
|
if is_class_method:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue