Skip to content

Commit 1c1e840

Browse files
markgrahamdawsonMark Dawson
andauthored
Added missing union type import (#5906)
* Added missing union type import * moved functions back into log_level --------- Co-authored-by: Mark Dawson <[email protected]>
1 parent 5a94866 commit 1c1e840

File tree

2 files changed

+2
-95
lines changed

2 files changed

+2
-95
lines changed

cylc/flow/log_level.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,15 @@ def log_level_to_verbosity(lvl: int) -> int:
3939
>>> log_level_to_verbosity(logging.NOTSET)
4040
2
4141
>>> log_level_to_verbosity(logging.DEBUG)
42-
1
42+
2
4343
>>> log_level_to_verbosity(logging.INFO)
4444
0
4545
>>> log_level_to_verbosity(logging.WARNING)
4646
-1
4747
>>> log_level_to_verbosity(logging.ERROR)
4848
-1
4949
"""
50-
if lvl < logging.DEBUG:
50+
if lvl <= logging.DEBUG:
5151
return 2
5252
if lvl < logging.INFO:
5353
return 1

cylc/flow/option_parsers.py

Lines changed: 0 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -182,99 +182,6 @@ def format_help_headings(string):
182182
)
183183

184184

185-
def verbosity_to_log_level(verb: int) -> int:
186-
"""Convert Cylc verbosity to log severity level."""
187-
if verb < 0:
188-
return logging.WARNING
189-
if verb > 0:
190-
return logging.DEBUG
191-
return logging.INFO
192-
193-
194-
def log_level_to_verbosity(lvl: int) -> int:
195-
"""Convert log severity level to Cylc verbosity.
196-
197-
Examples:
198-
>>> log_level_to_verbosity(logging.NOTSET)
199-
2
200-
>>> log_level_to_verbosity(logging.DEBUG)
201-
2
202-
>>> log_level_to_verbosity(logging.INFO)
203-
0
204-
>>> log_level_to_verbosity(logging.WARNING)
205-
-1
206-
>>> log_level_to_verbosity(logging.ERROR)
207-
-1
208-
"""
209-
if lvl <= logging.DEBUG:
210-
return 2
211-
if lvl < logging.INFO:
212-
return 1
213-
if lvl == logging.INFO:
214-
return 0
215-
return -1
216-
217-
218-
def verbosity_to_opts(verb: int) -> List[str]:
219-
"""Convert Cylc verbosity to the CLI opts required to replicate it.
220-
221-
Examples:
222-
>>> verbosity_to_opts(0)
223-
[]
224-
>>> verbosity_to_opts(-2)
225-
['-q', '-q']
226-
>>> verbosity_to_opts(2)
227-
['-v', '-v']
228-
229-
"""
230-
return [
231-
'-q'
232-
for _ in range(verb, 0)
233-
] + [
234-
'-v'
235-
for _ in range(0, verb)
236-
]
237-
238-
239-
def verbosity_to_env(verb: int) -> Dict[str, str]:
240-
"""Convert Cylc verbosity to the env vars required to replicate it.
241-
242-
Examples:
243-
>>> verbosity_to_env(0)
244-
{'CYLC_VERBOSE': 'false', 'CYLC_DEBUG': 'false'}
245-
>>> verbosity_to_env(1)
246-
{'CYLC_VERBOSE': 'true', 'CYLC_DEBUG': 'false'}
247-
>>> verbosity_to_env(2)
248-
{'CYLC_VERBOSE': 'true', 'CYLC_DEBUG': 'true'}
249-
250-
"""
251-
return {
252-
'CYLC_VERBOSE': str((verb > 0)).lower(),
253-
'CYLC_DEBUG': str((verb > 1)).lower(),
254-
}
255-
256-
257-
def env_to_verbosity(env: Union[Dict, os._Environ]) -> int:
258-
"""Extract verbosity from environment variables.
259-
260-
Examples:
261-
>>> env_to_verbosity({})
262-
0
263-
>>> env_to_verbosity({'CYLC_VERBOSE': 'true'})
264-
1
265-
>>> env_to_verbosity({'CYLC_DEBUG': 'true'})
266-
2
267-
>>> env_to_verbosity({'CYLC_DEBUG': 'TRUE'})
268-
2
269-
270-
"""
271-
return (
272-
2 if env.get('CYLC_DEBUG', '').lower() == 'true'
273-
else 1 if env.get('CYLC_VERBOSE', '').lower() == 'true'
274-
else 0
275-
)
276-
277-
278185
class CylcOption(Option):
279186
"""Optparse option which adds a decrement action."""
280187

0 commit comments

Comments
 (0)