cnfparse.py 1.15 KB
Newer Older
1
import ConfigParser as configparser
2

3

4
def importConf(path_to_file):
5
    config = configparser.RawConfigParser(allow_no_value=False)
6 7 8
    try:
        config.read(path_to_file)
        params = {}
9
        metrics = {}
10 11 12 13 14 15 16 17
        params["debugMode"] = config.get("Client", "Debug")
        metrics["cpu.usage"] = int(config.get("Metrics", "cpuUsage"))
        metrics["memory.usage"] = int(config.get("Metrics", "memoryUsage"))
        metrics["user.count"] = int(config.get("Metrics", "userCount"))
        metrics["swap.usage"] = int(config.get("Metrics", "swapUsage"))
        metrics["system.boot_time"] = int(config.get("Metrics",
                                                     "systemBootTime"))
        metrics["network"] = int(config.get("Metrics", "dataTraffic"))
18 19 20 21 22 23 24 25 26 27
    except configparser.NoSectionError:
        print("Config file contains error! Reason: Missing section.")
        raise
    except configparser.ParsingError:
        print("Config file contains error! Reason: Cannot parse.")
        raise
    except configparser.MissingSectionHeader:
        print("Config file contains error! Reason: Missing section-header.")
        raise

28
    return params, metrics