Commit b5a489a0986baa6bd399a9449ace8914ba129204
1 parent
fb7c8350
Exists in
master
and in
5 other branches
Handle .yaml plugins menu
Signed-off-by: Alexandre Barbosa <alexandreab@live.com> Signed-off-by: Gustavo Jaruga <darksshades@gmail.com>
Showing
1 changed file
with
27 additions
and
2 deletions
Show diff stats
colab/utils/conf.py
@@ -49,12 +49,17 @@ def load_yaml_settings(): | @@ -49,12 +49,17 @@ def load_yaml_settings(): | ||
49 | 49 | ||
50 | yaml_settings = _load_yaml_file(yaml_path) | 50 | yaml_settings = _load_yaml_file(yaml_path) |
51 | 51 | ||
52 | + parse_yml_menus(yaml_settings) | ||
53 | + | ||
52 | # Try to read settings from settings.d | 54 | # Try to read settings from settings.d |
53 | if os.path.exists(settings_dir): | 55 | if os.path.exists(settings_dir): |
54 | for file_name in os.listdir(settings_dir): | 56 | for file_name in os.listdir(settings_dir): |
55 | if file_name.endswith('.yaml') or file_name.endswith('yml'): | 57 | if file_name.endswith('.yaml') or file_name.endswith('yml'): |
56 | file_path = os.path.join(settings_dir, file_name) | 58 | file_path = os.path.join(settings_dir, file_name) |
57 | yaml_settings_d = _load_yaml_file(file_path) | 59 | yaml_settings_d = _load_yaml_file(file_path) |
60 | + | ||
61 | + parse_yml_menus(yaml_settings_d) | ||
62 | + | ||
58 | yaml_settings.update(yaml_settings_d) | 63 | yaml_settings.update(yaml_settings_d) |
59 | 64 | ||
60 | return yaml_settings or {} | 65 | return yaml_settings or {} |
@@ -131,17 +136,37 @@ def load_colab_apps(): | @@ -131,17 +136,37 @@ def load_colab_apps(): | ||
131 | fields = ['urls', 'menu', 'upstream', 'middlewares', | 136 | fields = ['urls', 'menu', 'upstream', 'middlewares', |
132 | 'dependencies', 'context_processors'] | 137 | 'dependencies', 'context_processors'] |
133 | 138 | ||
134 | - app_name = getattr(py_settings_d, 'name', None) | 139 | + app_name = py_settings_d.get('name') |
135 | if not app_name: | 140 | if not app_name: |
136 | warnings.warn("Plugin missing name variable") | 141 | warnings.warn("Plugin missing name variable") |
137 | continue | 142 | continue |
138 | 143 | ||
139 | COLAB_APPS[app_name] = {} | 144 | COLAB_APPS[app_name] = {} |
140 | for key in fields: | 145 | for key in fields: |
141 | - value = getattr(py_settings_d, key, None) | 146 | + value = py_settings_d.get(key) |
142 | if value: | 147 | if value: |
143 | COLAB_APPS[app_name][key] = value | 148 | COLAB_APPS[app_name][key] = value |
144 | 149 | ||
145 | sys.path.remove(plugins_dir) | 150 | sys.path.remove(plugins_dir) |
146 | 151 | ||
147 | return {'COLAB_APPS': COLAB_APPS} | 152 | return {'COLAB_APPS': COLAB_APPS} |
153 | + | ||
154 | + | ||
155 | +def parse_yml_menus(yaml_settings): | ||
156 | + if 'COLAB_APPS' in yaml_settings: | ||
157 | + for key, plugin in yaml_settings['COLAB_APPS'].items(): | ||
158 | + if 'menu' in plugin: | ||
159 | + parse_yml_tuples(yaml_settings['COLAB_APPS'][key]['menu']) | ||
160 | + | ||
161 | + | ||
162 | +def parse_yml_tuples(menu): | ||
163 | + dict_links = menu['links'] | ||
164 | + dict_auth_links = menu['auth_links'] | ||
165 | + menu['links'] = tuple() | ||
166 | + menu['auth_links'] = tuple() | ||
167 | + | ||
168 | + for key, value in dict_links.items(): | ||
169 | + menu['links'] += ((key, value),) | ||
170 | + | ||
171 | + for key, value in dict_auth_links.items(): | ||
172 | + menu['auth_links'] += ((key, value),) |