Skip to content

Commit

Permalink
More Robust Config Reading.
Browse files Browse the repository at this point in the history
  • Loading branch information
Liupold committed Jan 5, 2022
1 parent fb03cbc commit c4a13f8
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions pydoro/pydoro_core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,6 @@ def _ini_parse(self):
Defaults to ~/.pydoro.ini if PYDORO_CONFIG_FILE not set
"""
self._conf = configparser.ConfigParser()

filename = os.environ.get(
"PYDORO_CONFIG_FILE", os.path.expanduser("~/.pydoro.ini")
)

if os.path.exists(filename):
self._conf.read(filename)
else:
self._create_default_ini()

def _create_default_ini(self):
"""
Creates default ini configuration file
Saves it in '~/.pydoro.ini'
"""
self._conf["DEFAULT"] = {}

self._conf["General"] = {}
Expand Down Expand Up @@ -94,6 +79,20 @@ def _create_default_ini(self):
self._conf["Trigger"]["long_break_state_cmd"] = "[]"
self._conf["Trigger"]["small_break_state_cmd"] = "[]"

filename = os.environ.get(
"PYDORO_CONFIG_FILE", os.path.expanduser("~/.pydoro.ini")
)

if os.path.exists(filename):
self._conf.read(filename)
else:
self._create_default_ini()

def _create_default_ini(self):
"""
Creates default ini configuration file
Saves it in '~/.pydoro.ini'
"""
filename = os.path.expanduser("~/.pydoro.ini")
with open(filename, "w+") as configfile:
self._conf.write(configfile)
Expand Down

0 comments on commit c4a13f8

Please sign in to comment.