Commit fb7c8350fab4672e63f445ac7fd50d8bc0e3b8d9
1 parent
8b4dd611
Exists in
master
and in
5 other branches
Add plugins.d
Signed-off-by: Alexandre Barbosa <alexandreab@live.com> Signed-off-by: Gustavo Jaruga <darksshades@gmail.com>
Showing
3 changed files
with
44 additions
and
5 deletions
Show diff stats
colab/plugins/templatetags/plugins.py
@@ -29,9 +29,9 @@ def plugins_menu(context): | @@ -29,9 +29,9 @@ def plugins_menu(context): | ||
29 | 29 | ||
30 | menu = app.get('menu') | 30 | menu = app.get('menu') |
31 | title = menu.get('title', app_name) | 31 | title = menu.get('title', app_name) |
32 | - links = menu.get('links', tuple()).items() | 32 | + links = menu.get('links', tuple()) |
33 | if context['user'].is_active: | 33 | if context['user'].is_active: |
34 | - links += menu.get('auth_links', tuple()).items() | 34 | + links += menu.get('auth_links', tuple()) |
35 | 35 | ||
36 | if not links: | 36 | if not links: |
37 | continue | 37 | continue |
colab/settings.py
@@ -281,6 +281,7 @@ TASTYPIE_DEFAULT_FORMATS = ['json', ] | @@ -281,6 +281,7 @@ TASTYPIE_DEFAULT_FORMATS = ['json', ] | ||
281 | 281 | ||
282 | from .utils.conf import load_yaml_settings | 282 | from .utils.conf import load_yaml_settings |
283 | from .utils.conf import load_py_settings | 283 | from .utils.conf import load_py_settings |
284 | +from .utils.conf import load_colab_apps | ||
284 | 285 | ||
285 | locals().update(load_yaml_settings()) | 286 | locals().update(load_yaml_settings()) |
286 | 287 | ||
@@ -295,6 +296,8 @@ if locals().get('RAVEN_DSN', False): | @@ -295,6 +296,8 @@ if locals().get('RAVEN_DSN', False): | ||
295 | BROWSERID_ENABLED = locals().get('BROWSERID_ENABLED') or False | 296 | BROWSERID_ENABLED = locals().get('BROWSERID_ENABLED') or False |
296 | SOCIAL_NETWORK_ENABLED = locals().get('SOCIAL_NETWORK_ENABLED') or False | 297 | SOCIAL_NETWORK_ENABLED = locals().get('SOCIAL_NETWORK_ENABLED') or False |
297 | 298 | ||
299 | +locals().update(load_colab_apps()) | ||
300 | + | ||
298 | COLAB_APPS = locals().get('COLAB_APPS') or {} | 301 | COLAB_APPS = locals().get('COLAB_APPS') or {} |
299 | PROXIED_APPS = {} | 302 | PROXIED_APPS = {} |
300 | 303 |
colab/utils/conf.py
@@ -76,7 +76,7 @@ def _load_py_file(py_path): | @@ -76,7 +76,7 @@ def _load_py_file(py_path): | ||
76 | 'has read rights.').format(py_path) | 76 | 'has read rights.').format(py_path) |
77 | raise InaccessiblePySettings(msg) | 77 | raise InaccessiblePySettings(msg) |
78 | 78 | ||
79 | - return py_settings.__dict__ | 79 | + return py_settings |
80 | 80 | ||
81 | 81 | ||
82 | def load_py_settings(): | 82 | def load_py_settings(): |
@@ -95,17 +95,53 @@ def load_py_settings(): | @@ -95,17 +95,53 @@ def load_py_settings(): | ||
95 | sys.path.insert(0, '/etc/colab/') | 95 | sys.path.insert(0, '/etc/colab/') |
96 | sys.path.insert(0, settings_dir) | 96 | sys.path.insert(0, settings_dir) |
97 | 97 | ||
98 | - py_settings = _load_py_file(settings_module) | 98 | + py_settings = _load_py_file(settings_module).__dict__ |
99 | 99 | ||
100 | # Try to read settings from settings.d | 100 | # Try to read settings from settings.d |
101 | if os.path.exists(settings_dir): | 101 | if os.path.exists(settings_dir): |
102 | for file_name in os.listdir(settings_dir): | 102 | for file_name in os.listdir(settings_dir): |
103 | if file_name.endswith('.py'): | 103 | if file_name.endswith('.py'): |
104 | file_module = file_name.split('.')[0] | 104 | file_module = file_name.split('.')[0] |
105 | - py_settings_d = _load_py_file(file_module) | 105 | + py_settings_d = _load_py_file(file_module).__dict__ |
106 | py_settings.update(py_settings_d) | 106 | py_settings.update(py_settings_d) |
107 | 107 | ||
108 | sys.path.remove('/etc/colab/') | 108 | sys.path.remove('/etc/colab/') |
109 | sys.path.remove(settings_dir) | 109 | sys.path.remove(settings_dir) |
110 | 110 | ||
111 | return py_settings or {} | 111 | return py_settings or {} |
112 | + | ||
113 | + | ||
114 | +def load_colab_apps(): | ||
115 | + plugins_dir = '/etc/colab/plugins.d/' | ||
116 | + | ||
117 | + global USING_YAML_SETTINGS | ||
118 | + if USING_YAML_SETTINGS: | ||
119 | + return {} | ||
120 | + | ||
121 | + sys.path.insert(0, plugins_dir) | ||
122 | + | ||
123 | + COLAB_APPS = {} | ||
124 | + | ||
125 | + # Try to read settings from plugins.d | ||
126 | + if os.path.exists(plugins_dir): | ||
127 | + for file_name in os.listdir(plugins_dir): | ||
128 | + if file_name.endswith('.py'): | ||
129 | + file_module = file_name.split('.')[0] | ||
130 | + py_settings_d = _load_py_file(file_module) | ||
131 | + fields = ['urls', 'menu', 'upstream', 'middlewares', | ||
132 | + 'dependencies', 'context_processors'] | ||
133 | + | ||
134 | + app_name = getattr(py_settings_d, 'name', None) | ||
135 | + if not app_name: | ||
136 | + warnings.warn("Plugin missing name variable") | ||
137 | + continue | ||
138 | + | ||
139 | + COLAB_APPS[app_name] = {} | ||
140 | + for key in fields: | ||
141 | + value = getattr(py_settings_d, key, None) | ||
142 | + if value: | ||
143 | + COLAB_APPS[app_name][key] = value | ||
144 | + | ||
145 | + sys.path.remove(plugins_dir) | ||
146 | + | ||
147 | + return {'COLAB_APPS': COLAB_APPS} |