##// END OF EJS Templates
configurator: reorganize the code
ergo -
Show More
@@ -42,7 +42,8 b' from redlock import Redlock'
42 from sqlalchemy import engine_from_config
42 from sqlalchemy import engine_from_config
43
43
44 from appenlight.celery import configure_celery
44 from appenlight.celery import configure_celery
45 from appenlight.lib.configurator import CythonCompatConfigurator
45 from appenlight.lib.configurator import (CythonCompatConfigurator,
46 register_appenlight_plugin)
46 from appenlight.lib import cache_regions
47 from appenlight.lib import cache_regions
47 from appenlight.lib.ext_json import json
48 from appenlight.lib.ext_json import json
48 from appenlight.security import groupfinder, AuthTokenAuthenticationPolicy
49 from appenlight.security import groupfinder, AuthTokenAuthenticationPolicy
@@ -96,6 +97,13 b' def main(global_config, **settings):'
96 authorization_policy=authorization_policy,
97 authorization_policy=authorization_policy,
97 root_factory='appenlight.security.RootFactory',
98 root_factory='appenlight.security.RootFactory',
98 default_permission='view')
99 default_permission='view')
100 # custom registry variables
101
102 # resource type information
103 config.registry.resource_types = ['resource', 'application']
104 # plugin information
105 config.registry.appenlight_plugins = {}
106
99 config.set_default_csrf_options(require_csrf=True, header='X-XSRF-TOKEN')
107 config.set_default_csrf_options(require_csrf=True, header='X-XSRF-TOKEN')
100 config.add_view_deriver('appenlight.predicates.csrf_view',
108 config.add_view_deriver('appenlight.predicates.csrf_view',
101 name='csrf_view')
109 name='csrf_view')
@@ -177,44 +185,9 b' def main(global_config, **settings):'
177
185
178 config.include('appenlight.views')
186 config.include('appenlight.views')
179 config.include('appenlight.views.admin')
187 config.include('appenlight.views.admin')
180 config.scan(ignore=['appenlight.migrations',
188 config.scan(ignore=['appenlight.migrations', 'appenlight.scripts',
181 'appenlight.scripts',
182 'appenlight.tests'])
189 'appenlight.tests'])
183
190
184 # resource type information
185 config.registry.resource_types = ['resource', 'application']
186
187 # plugin information
188 config.registry.appenlight_plugins = {}
189
190 def register_appenlight_plugin(config, plugin_name, plugin_config):
191 def register():
192 log.warning('Registering plugin: {}'.format(plugin_name))
193 if plugin_name not in config.registry.appenlight_plugins:
194 config.registry.appenlight_plugins[plugin_name] = {
195 'javascript': None,
196 'static': None,
197 'css': None,
198 'top_nav': None,
199 'celery_tasks': None,
200 'celery_beats': None,
201 'fulltext_indexer': None,
202 'sqlalchemy_migrations': None,
203 'default_values_setter': None,
204 'resource_types': [],
205 'url_gen': None
206 }
207 config.registry.appenlight_plugins[plugin_name].update(
208 plugin_config)
209 # inform AE what kind of resource types we have available
210 # so we can avoid failing when a plugin is removed but data
211 # is still present in the db
212 if plugin_config.get('resource_types'):
213 config.registry.resource_types.extend(
214 plugin_config['resource_types'])
215
216 config.action('appenlight_plugin={}'.format(plugin_name), register)
217
218 config.add_directive('register_appenlight_plugin',
191 config.add_directive('register_appenlight_plugin',
219 register_appenlight_plugin)
192 register_appenlight_plugin)
220
193
@@ -1,7 +1,9 b''
1 import inspect
1 import inspect
2 import logging
2
3
3 from pyramid.config import Configurator
4 from pyramid.config import Configurator
4
5
6 log = logging.getLogger(__name__)
5
7
6 class InspectProxy(object):
8 class InspectProxy(object):
7 """
9 """
@@ -59,3 +61,32 b' class CythonCompatConfigurator(Configurator):'
59 a custom one that is cython compatible.
61 a custom one that is cython compatible.
60 """
62 """
61 inspect = InspectProxy()
63 inspect = InspectProxy()
64
65
66 def register_appenlight_plugin(config, plugin_name, plugin_config):
67 def register():
68 log.warning('Registering plugin: {}'.format(plugin_name))
69 if plugin_name not in config.registry.appenlight_plugins:
70 config.registry.appenlight_plugins[plugin_name] = {
71 'javascript': None,
72 'static': None,
73 'css': None,
74 'top_nav': None,
75 'celery_tasks': None,
76 'celery_beats': None,
77 'fulltext_indexer': None,
78 'sqlalchemy_migrations': None,
79 'default_values_setter': None,
80 'resource_types': [],
81 'url_gen': None
82 }
83 config.registry.appenlight_plugins[plugin_name].update(
84 plugin_config)
85 # inform AE what kind of resource types we have available
86 # so we can avoid failing when a plugin is removed but data
87 # is still present in the db
88 if plugin_config.get('resource_types'):
89 config.registry.resource_types.extend(
90 plugin_config['resource_types'])
91
92 config.action('appenlight_plugin={}'.format(plugin_name), register)
General Comments 0
You need to be logged in to leave comments. Login now