Skip to content

Commit

Permalink
move setup code to rw.scope
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianLudwig committed Apr 21, 2015
1 parent 7ace472 commit 52ee200
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 15 deletions.
14 changes: 2 additions & 12 deletions rw/httpbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,22 +73,12 @@ def configure(self):

@gen.coroutine
def _scoped_configure(self):
self.rw_settings = rw.cfg.read_configs(self.root.name)
yield rw.scope.setup_app_scope(self.root.name, self.scope)
self.rw_settings = self.scope['settings']
cfg_rw_http = self.rw_settings.setdefault('rw.http', {})
cfg_rw_http['live_settings'] = self.settings
self.scope['settings'] = self.rw_settings
# load plugins
plugins = []
for plugin_name, active in self.rw_settings.get('rw.plugins', {}).items():
plugin = __import__(plugin_name)
plugin_path = plugin_name.split('.')[1:] + ['plugin']
for sub in plugin_path:
plugin = getattr(plugin, sub)
plugins.append(self.scope.activate(plugin))

self._configure_cookie_secret()

yield plugins
yield self.scope.activate(self.root)

def _configure_cookie_secret(self):
Expand Down
29 changes: 26 additions & 3 deletions rw/scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,16 @@
# under the License.
from __future__ import absolute_import, division, print_function, with_statement

from tornado import stack_context, gen
import contextlib
import functools

import inspect

from tornado import stack_context

import rw.cfg
from . import gen


NOT_PROVIDED = object()
SCOPE_CHAIN = None

Expand Down Expand Up @@ -154,4 +158,23 @@ def wrapper(*args, **kwargs):
pass
return fn(*args, **kwargs)

return wrapper
return wrapper


@gen.coroutine
def setup_app_scope(name, scope):
"""Load confing and activate plugins accordingly"""
settings = rw.cfg.read_configs(name)
scope['settings'] = settings

# load plugins
plugins = []
for plugin_name, active in settings.get('rw.plugins', {}).items():
plugin = __import__(plugin_name)
plugin_path = plugin_name.split('.')[1:] + ['plugin']
for sub in plugin_path:
plugin = getattr(plugin, sub)
plugins.append(scope.activate(plugin))

yield plugins
raise rw.gen.Return(settings)

0 comments on commit 52ee200

Please sign in to comment.