diff options
author | Aki <please@ignore.pl> | 2023-04-05 21:40:09 +0200 |
---|---|---|
committer | Aki <please@ignore.pl> | 2023-04-05 21:40:09 +0200 |
commit | 9c863e9851cfe36bd2101d63a3db767738066331 (patch) | |
tree | f11aa03d99378c3c97e50d8e1e71666bd030b7c0 /waterspout_radar | |
parent | 9578d46e006efed6b0ea465cd4a809214d45a3ac (diff) | |
download | waterspout-radar-9c863e9851cfe36bd2101d63a3db767738066331.zip waterspout-radar-9c863e9851cfe36bd2101d63a3db767738066331.tar.gz waterspout-radar-9c863e9851cfe36bd2101d63a3db767738066331.tar.bz2 |
Configuration path may now be passed through environment
Diffstat (limited to 'waterspout_radar')
-rw-r--r-- | waterspout_radar/_config.py | 5 | ||||
-rw-r--r-- | waterspout_radar/cli.py | 6 |
2 files changed, 7 insertions, 4 deletions
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)): |