aboutsummaryrefslogtreecommitdiff
path: root/config.py
blob: 845d6e4ea3d6ab55ee45daa72c9036b6556b0984 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
"""
Functions for handling the program's configuration file
"""

from configparser import ConfigParser
import os

CONFIG_FILE = os.path.expanduser("~/.config/joc/config.ini")

def read_config_file():
    """ Read config file and return ConfigParser instance """
    parser = ConfigParser(inline_comment_prefixes="#")
    parser.read(os.path.expanduser(CONFIG_FILE))
    return parser


def write_config_file(parser:ConfigParser):
    """ Write ConfigParser contents back to config file """
    with open(os.path.expanduser(CONFIG_FILE), "w") as conf:
        parser.write(conf)