From 1c1e840fe2b8cae3eb7d765eaa89f5511b2258bb Mon Sep 17 00:00:00 2001 From: Mark Dawson Date: Thu, 4 Jan 2024 17:22:12 +0000 Subject: [PATCH] Added missing union type import (#5906) * Added missing union type import * moved functions back into log_level --------- Co-authored-by: Mark Dawson --- cylc/flow/log_level.py | 4 +- cylc/flow/option_parsers.py | 93 ------------------------------------- 2 files changed, 2 insertions(+), 95 deletions(-) diff --git a/cylc/flow/log_level.py b/cylc/flow/log_level.py index 4b091154893..cda3c4493ad 100644 --- a/cylc/flow/log_level.py +++ b/cylc/flow/log_level.py @@ -39,7 +39,7 @@ def log_level_to_verbosity(lvl: int) -> int: >>> log_level_to_verbosity(logging.NOTSET) 2 >>> log_level_to_verbosity(logging.DEBUG) - 1 + 2 >>> log_level_to_verbosity(logging.INFO) 0 >>> log_level_to_verbosity(logging.WARNING) @@ -47,7 +47,7 @@ def log_level_to_verbosity(lvl: int) -> int: >>> log_level_to_verbosity(logging.ERROR) -1 """ - if lvl < logging.DEBUG: + if lvl <= logging.DEBUG: return 2 if lvl < logging.INFO: return 1 diff --git a/cylc/flow/option_parsers.py b/cylc/flow/option_parsers.py index 3dc789f2aed..b83ff45aab9 100644 --- a/cylc/flow/option_parsers.py +++ b/cylc/flow/option_parsers.py @@ -182,99 +182,6 @@ def format_help_headings(string): ) -def verbosity_to_log_level(verb: int) -> int: - """Convert Cylc verbosity to log severity level.""" - if verb < 0: - return logging.WARNING - if verb > 0: - return logging.DEBUG - return logging.INFO - - -def log_level_to_verbosity(lvl: int) -> int: - """Convert log severity level to Cylc verbosity. - - Examples: - >>> log_level_to_verbosity(logging.NOTSET) - 2 - >>> log_level_to_verbosity(logging.DEBUG) - 2 - >>> log_level_to_verbosity(logging.INFO) - 0 - >>> log_level_to_verbosity(logging.WARNING) - -1 - >>> log_level_to_verbosity(logging.ERROR) - -1 - """ - if lvl <= logging.DEBUG: - return 2 - if lvl < logging.INFO: - return 1 - if lvl == logging.INFO: - return 0 - return -1 - - -def verbosity_to_opts(verb: int) -> List[str]: - """Convert Cylc verbosity to the CLI opts required to replicate it. - - Examples: - >>> verbosity_to_opts(0) - [] - >>> verbosity_to_opts(-2) - ['-q', '-q'] - >>> verbosity_to_opts(2) - ['-v', '-v'] - - """ - return [ - '-q' - for _ in range(verb, 0) - ] + [ - '-v' - for _ in range(0, verb) - ] - - -def verbosity_to_env(verb: int) -> Dict[str, str]: - """Convert Cylc verbosity to the env vars required to replicate it. - - Examples: - >>> verbosity_to_env(0) - {'CYLC_VERBOSE': 'false', 'CYLC_DEBUG': 'false'} - >>> verbosity_to_env(1) - {'CYLC_VERBOSE': 'true', 'CYLC_DEBUG': 'false'} - >>> verbosity_to_env(2) - {'CYLC_VERBOSE': 'true', 'CYLC_DEBUG': 'true'} - - """ - return { - 'CYLC_VERBOSE': str((verb > 0)).lower(), - 'CYLC_DEBUG': str((verb > 1)).lower(), - } - - -def env_to_verbosity(env: Union[Dict, os._Environ]) -> int: - """Extract verbosity from environment variables. - - Examples: - >>> env_to_verbosity({}) - 0 - >>> env_to_verbosity({'CYLC_VERBOSE': 'true'}) - 1 - >>> env_to_verbosity({'CYLC_DEBUG': 'true'}) - 2 - >>> env_to_verbosity({'CYLC_DEBUG': 'TRUE'}) - 2 - - """ - return ( - 2 if env.get('CYLC_DEBUG', '').lower() == 'true' - else 1 if env.get('CYLC_VERBOSE', '').lower() == 'true' - else 0 - ) - - class CylcOption(Option): """Optparse option which adds a decrement action."""