From 082fbb3547931a6667213ffdf5f912f89fc542c4 Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Thu, 2 Apr 2020 15:07:06 +0200 Subject: [PATCH] allow multiple statics server and fixed few smaller bugs --- pype/avalon_apps/rest_api.py | 8 +++++--- pype/services/rest_api/lib/factory.py | 24 ++++++++---------------- 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/pype/avalon_apps/rest_api.py b/pype/avalon_apps/rest_api.py index af40bfe920..aba67abd7e 100644 --- a/pype/avalon_apps/rest_api.py +++ b/pype/avalon_apps/rest_api.py @@ -23,7 +23,9 @@ class AvalonRestApi(RestApi): if not project_name: output = {} 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 return CallbackResult(data=self.result_to_json(output)) @@ -44,7 +46,7 @@ class AvalonRestApi(RestApi): if not self.dbcon.exist_table(_project_name): abort(404, "Project \"{}\" was not found in database".format( - project_name + _project_name )) if not _asset: @@ -65,7 +67,7 @@ class AvalonRestApi(RestApi): return asset abort(404, "Asset \"{}\" with {} was not found in project {}".format( - _asset, identificator, project_name + _asset, identificator, _project_name )) @RestApi.route("/publish/", url_prefix="/premiere", methods="GET") diff --git a/pype/services/rest_api/lib/factory.py b/pype/services/rest_api/lib/factory.py index 2b94d498ff..55dc5e1635 100644 --- a/pype/services/rest_api/lib/factory.py +++ b/pype/services/rest_api/lib/factory.py @@ -3,6 +3,7 @@ import re import inspect import collections from .lib import RestMethods +from queue import Queue from pypeapp import Logger @@ -208,7 +209,7 @@ class _RestApiFactory: """ registered_objs = [] unprocessed_routes = [] - unprocessed_statics = [] + unprocessed_statics = Queue() prepared_routes = { method: collections.defaultdict(list) for method in RestMethods @@ -220,16 +221,6 @@ class _RestApiFactory: def has_handlers(self): 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( self, path, callback, url_prefix, methods, strict_match ): @@ -251,7 +242,7 @@ class _RestApiFactory: def register_statics(self, item): log.debug("Registering statics path \"{}\"".format(item)) - self.unprocessed_statics.append(item) + self.unprocessed_statics.put(item) def _prepare_route(self, route): """Prepare data of registered callbacks for routes. @@ -290,8 +281,9 @@ class _RestApiFactory: methods has `__self__` or are defined in (it is expeted they 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) if not os.path.exists(dir_path): log.warning( @@ -314,7 +306,7 @@ class _RestApiFactory: if not method.restapi: continue - for route in self.unprocessed_routes: + for route in list(self.unprocessed_routes): callback = route["callback"] if not ( callback.__qualname__ == method.__qualname__ and @@ -330,7 +322,7 @@ class _RestApiFactory: self._prepare_route(route) break - for route in self.unprocessed_routes: + for route in list(self.unprocessed_routes): callback = route["callback"] is_class_method = len(callback.__qualname__.split(".")) != 1 if is_class_method: