Skip to content

Commit

Permalink
Show config file paths more explicitly, and a clearer error if a conf…
Browse files Browse the repository at this point in the history
…ig file isn't found.
  • Loading branch information
yo8192 committed Nov 2, 2024
1 parent d1c5391 commit c010642
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions src/octo2influx.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,11 @@ def _config_only(val: str):
system audit logs, etc): you can define in an access-restricted configuration
file instead.
The settings can also be set in the config file {confuse.CONFIG_FILENAME} (in
/etc/{PROGNAME}, ~/.config/{PROGNAME}, or the directory defined by the env var
{PROGNAME}DIR), or via environment variable of the form
{PROGNAME}_COMMAND_LINE_ARG.
The settings can also be set in the config file (./{confuse.CONFIG_FILENAME},
/etc/{PROGNAME}/{confuse.CONFIG_FILENAME}, ~/.config/{PROGNAME}/{confuse.CONFIG_FILENAME},
or ${PROGNAME.upper()}DIR/{confuse.CONFIG_FILENAME} in a directory of your choice by defining
the env var {PROGNAME.upper()}DIR).
Or via environment variable of the form {PROGNAME.upper()}_COMMAND_LINE_ARG.
The priority from highest to lowest is: environment, command line, config file.
'''

Expand Down Expand Up @@ -396,8 +397,24 @@ def build_argparser(params: dict[str, Parameter]) -> argparse.ArgumentParser:
cfg.set_env()

logging.root.setLevel(cfg['loglevel'])

if read_local_config:
logging.info(f'Read configuration from {local_config_path}.')
else:
# Check confuse did load a config file ok
try:
if not cfg['price_types']:
raise ValueError
except (confuse.exceptions.NotFoundError, ValueError):
configfile_paths = [
local_config_path,
path.join(f'/etc', PROGNAME, confuse.CONFIG_FILENAME),
path.join(path.expanduser('~/.config/'),
PROGNAME, confuse.CONFIG_FILENAME)
]
raise SystemExit(
'Configuration key "price_types" was not found or empty. '
f'Please check you have a valid configuration file at one of {configfile_paths}.')

to_dt = datetime_to_days_ago(cfg['to_days_ago'])
to_iso8601 = iso8601_from_datetime(to_dt)
Expand Down

0 comments on commit c010642

Please sign in to comment.