only add HOME from environ to ConfigParser, set _cfgfiles on loading, add comment on default ocnfig file locations

This commit is contained in:
Marcus Stoegbauer 2024-03-30 20:40:30 +01:00
parent 015ea337f2
commit 7684033903
1 changed files with 4 additions and 1 deletions

View File

@ -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