• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

oemof / demandlib / 13541950960

26 Feb 2025 10:37AM UTC coverage: 85.517%. First build
13541950960

Pull #50

github

web-flow
Merge 2288c1f43 into c088f1488
Pull Request #50: Add VDI profiles based on lpagg

67 of 106 branches covered (63.21%)

Branch coverage included in aggregate %.

331 of 393 new or added lines in 13 files covered. (84.22%)

553 of 619 relevant lines covered (89.34%)

2.68 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

20.75
/src/demandlib/config.py
1
# -*- coding: utf-8 -*-
2

3
"""
4
Adaptable config reader.
5

6
By default the config file of the package is used. Each value can be
7
overwritten with a user value with a custom config file in the $HOME directory
8
or in the working directory. The name of the config file must be:
9
demandlib.ini. If there is such a file in both locations the file in the
10
working directory will overwrite the one in the home folder.
11

12
SPDX-FileCopyrightText: Steffen - https://github.com/steffenGit
13
SPDX-FileCopyrightText: 2016-2021 Uwe Krien <krien@uni-bremen.de>
14

15
SPDX-License-Identifier: MIT
16
"""
17

18
__all__ = [
3✔
19
    "get",
20
    "init",
21
]
22

23

24
import configparser as cp
3✔
25
import os
3✔
26

27
BLACKLIST = ["tox.ini"]
3✔
28

29
cfg = cp.RawConfigParser()
3✔
30
cfg.optionxform = str
3✔
31
_loaded = False
3✔
32

33

34
def get_ini_filenames():
3✔
35
    """Returns a list of ini files to use."""
NEW
36
    paths = []
×
NEW
37
    files = []
×
38

NEW
39
    paths.append(os.path.join(os.path.dirname(__file__)))
×
NEW
40
    paths.append(os.path.join(os.path.expanduser("~")))
×
NEW
41
    paths.append(os.getcwd())
×
42

NEW
43
    for p in paths:
×
NEW
44
        if p == "":  # Empty path string must be ignored
×
NEW
45
            continue
×
NEW
46
        for f in os.listdir(p):
×
NEW
47
            if f == "demandlib.ini":
×
NEW
48
                files.append(os.path.join(p, f))
×
NEW
49
    return files
×
50

51

52
def init():
3✔
53
    """Read config file(s)."""
NEW
54
    cfg.read(get_ini_filenames(), encoding="utf-8")
×
55
    global _loaded
NEW
56
    _loaded = True
×
57

58

59
def load():
3✔
NEW
60
    if not _loaded:
×
NEW
61
        init()
×
62

63

64
def get(section, key):
3✔
65
    """Returns the value of a given key in a given section."""
NEW
66
    load()
×
NEW
67
    try:
×
NEW
68
        return cfg.getint(section, key)
×
NEW
69
    except ValueError:
×
NEW
70
        try:
×
NEW
71
            return cfg.getfloat(section, key)
×
NEW
72
        except ValueError:
×
NEW
73
            try:
×
NEW
74
                return cfg.getboolean(section, key)
×
NEW
75
            except ValueError:
×
NEW
76
                value = cfg.get(section, key)
×
NEW
77
                if value == "None":
×
NEW
78
                    value = None
×
NEW
79
                return value
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc