Config: Accept strings as value for glob_paths

Make Config's ctor accept strings as values for glob_paths, as
opposed to lists. This covers the canonical case of one configuration
file being passed.

Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2025-01-29 12:56:32 +01:00
commit bee3e28ff5

View file

@ -28,6 +28,8 @@ class Config(): # export
exe = Path(os.path.basename(sys.argv[0])).stem
if glob_paths is None:
glob_paths = [f'.{exe}', f'{exe}.conf']
elif isinstance(glob_paths, str):
glob_paths = [glob_paths]
if search_dirs is None:
env_key = re.sub('[-.]', '_', exe)
search_dirs = os.getenv(env_key)
@ -36,7 +38,7 @@ class Config(): # export
if dirs is None:
dirs = [''] if __is_abs(path) else [ str(Path.home()), str(Path.cwd()) ]
for d in dirs:
g = d + '/' + path
g = d + '/' + path if len(d) else path
slog(DEBUG, 'Looking for config "{}"'.format(g))
for f in glob.glob(g):
slog(DEBUG, 'Reading config "{}"'.format(f))