Always prefer a config template if found

master
Tyler Goodlet 2023-05-22 22:52:21 -04:00
parent 7f246697b4
commit d3bafb0063
1 changed files with 12 additions and 10 deletions

View File

@ -228,6 +228,7 @@ def load(
[str | bytes,], [str | bytes,],
MutableMapping, MutableMapping,
] = tomllib.loads, ] = tomllib.loads,
touch_if_dne: bool = False, touch_if_dne: bool = False,
**tomlkws, **tomlkws,
@ -249,18 +250,19 @@ def load(
exist_ok=True, exist_ok=True,
) )
if not path.is_file(): if (
if path is None: not path.is_file()
fn: str = _conf_fn_w_ext(conf_name) and touch_if_dne
):
fn: str = _conf_fn_w_ext(conf_name)
# try to copy in a template config to the user's directory if # try to copy in a template config to the user's directory if
# one exists. # one exists.
template: Path = repodir() / 'config' / fn template: Path = repodir() / 'config' / fn
if template.is_file(): if template.is_file():
shutil.copyfile(template, path) shutil.copyfile(template, path)
# touch an empty file else: # just touch an empty file with same name
elif touch_if_dne:
with path.open(mode='x'): with path.open(mode='x'):
pass pass