Passed
Push — master ( 9e42ed...b2d36d )
by Jaisen
02:09
created

elodie.config.load_config_for_plugin()   A

Complexity

Conditions 2

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 6
nop 1
dl 0
loc 9
rs 10
c 0
b 0
f 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