diff options
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | contrib/.gitignore | 1 | ||||
-rw-r--r-- | waterspout_radar/_config.py | 5 | ||||
-rw-r--r-- | waterspout_radar/cli.py | 6 |
4 files changed, 9 insertions, 5 deletions
@@ -3,6 +3,6 @@ __pycache__/ build*/ dist/ .venv/ -dev.conf .env +*.conf *.json diff --git a/contrib/.gitignore b/contrib/.gitignore new file mode 100644 index 0000000..f8d2b04 --- /dev/null +++ b/contrib/.gitignore @@ -0,0 +1 @@ +!*.conf diff --git a/waterspout_radar/_config.py b/waterspout_radar/_config.py index 7712939..222f023 100644 --- a/waterspout_radar/_config.py +++ b/waterspout_radar/_config.py @@ -33,6 +33,11 @@ class ConfigError(Exception): "Raised when configuration could not be loaded or was malformed." +def effective_pathname(pathname: str = None) -> str: + "Pathname of the configuration file based on optional *pathname*, environment, and default." + return pathname or os.getenv("WATERSPOUT_RADAR_CONFIG") or "waterspout-radar.conf" + + def load(pathname: str) -> Config: "Loads configuration from a file at *pathname*. May raise ConfigError when content does not meet expectations." config = configparser.ConfigParser(allow_no_value=True) diff --git a/waterspout_radar/cli.py b/waterspout_radar/cli.py index 24f9e53..b8fb041 100644 --- a/waterspout_radar/cli.py +++ b/waterspout_radar/cli.py @@ -5,11 +5,9 @@ from . import _config, _radar, _storage def main(): parser = argparse.ArgumentParser() - parser.add_argument( - "-c", "--config", default="radar.conf", - help="Pathname of the instance configuration file (default: %(default)s)") + parser.add_argument("-c", "--config", help="Overrides configuration file pathname.") args = parser.parse_args() - config = _config.load(args.config) + config = _config.load(_config.effective_pathname(args.config)) storage = _storage.Storage(config.db) storage.extend(_radar.calculate(config)) for prediction in sorted(storage, key=lambda x: (x.time, x.swi)): |