aboutsummaryrefslogtreecommitdiffstats
path: root/IRC/getconf.py
blob: d6e9f425162995e9a91f1534c78f5a78e48b00ff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#getconf = make_getconf("dateiname.json") 
#getconf(key) -> value                    
#oder error                               

import imp
import os


def make_getconf(filename):

    config = load_config(filename)

    def getconf(prop):
        prop_split = prop.split('.')
        string = ''
        imp.reload(config)
        tmp = config.__dict__
        for pr in prop_split:
            tmp = tmp[pr]
        return tmp

    return getconf


def load_config(filename):
    dirname = os.path.dirname(filename)
    modname, ext = os.path.splitext(os.path.basename(filename))
    file, pathname, description = imp.find_module(modname, [ dirname ])
    return imp.load_module(modname, file, pathname, description)