Total Complexity | 8 |
Total Lines | 40 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | """Load config file as a singleton.""" |
||
2 | from configparser import RawConfigParser |
||
3 | from os import path |
||
4 | |||
5 | from elodie import constants |
||
6 | |||
7 | config_file = '%s/config.ini' % constants.application_directory |
||
8 | |||
9 | |||
10 | def load_config(): |
||
11 | if hasattr(load_config, "config"): |
||
12 | return load_config.config |
||
13 | |||
14 | if not path.exists(config_file): |
||
15 | return {} |
||
16 | |||
17 | load_config.config = RawConfigParser() |
||
18 | load_config.config.read(config_file) |
||
19 | return load_config.config |
||
20 | |||
21 | def load_plugin_config(): |
||
22 | config = load_config() |
||
23 | |||
24 | # If plugins are defined in the config we return them as a list |
||
25 | # Else we return an empty list |
||
26 | if 'Plugins' in config and 'plugins' in config['Plugins']: |
||
27 | return config['Plugins']['plugins'].split(',') |
||
28 | |||
29 | return [] |
||
30 | |||
31 | def load_config_for_plugin(name): |
||
32 | # Plugins store data using Plugin%PluginName% format. |
||
33 | key = 'Plugin{}'.format(name) |
||
34 | config = load_config() |
||
35 | |||
36 | if key in config: |
||
37 | return config[key] |
||
38 | |||
39 | return {} |
||
40 |