From 7684033903f4a785d86f0d0d03c3a7338ca78b0c Mon Sep 17 00:00:00 2001 From: Marcus Stoegbauer Date: Sat, 30 Mar 2024 20:40:30 +0100 Subject: [PATCH] only add HOME from environ to ConfigParser, set _cfgfiles on loading, add comment on default ocnfig file locations --- userconfig/cfgfile.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/userconfig/cfgfile.py b/userconfig/cfgfile.py index df9f847..395f9f3 100644 --- a/userconfig/cfgfile.py +++ b/userconfig/cfgfile.py @@ -4,7 +4,7 @@ import sys class Conf(object): - _confobj = configparser.ConfigParser(os.environ) + _confobj = configparser.ConfigParser(dict(HOME=os.environ.get('HOME'))) _cfgfiles = [] debug = None @@ -15,6 +15,8 @@ class Conf(object): if filename: filenames.append(filename) if not force_filename: + # default config files are $HOME/etc/userconfig2.conf and + # {sys.prefix}/etc/userconfig2.conf if os.path.isfile(f'{os.environ.get("HOME")}/etc/userconfig2.conf'): filenames.append(f'{os.environ.get("HOME")}/etc/userconfig2.conf') if os.path.isfile(f'{sys.prefix}/etc/userconfig2.conf'): @@ -30,6 +32,7 @@ class Conf(object): ret = self._confobj.read(filenames) if len(ret) == 0: return None + self._cfgfiles = ret if self.debug: self.debug.stdout("Read config files: %s" % ", ".join(filenames), 2) return ret