Replace in+remove with index+pop.
The code turns out to be longer with these duplicate try-except, but they are different enough that I can't really condense it at the moment.
This commit is contained in:
parent
b561fd24b5
commit
d0d7cf2145
1 changed files with 16 additions and 5 deletions
|
@ -190,6 +190,8 @@ def get_level_by_argv(argv):
|
|||
and level is either an integer log level, or None if the user did not
|
||||
opt in. Even if you are not attaching operatornotify to your logger, you
|
||||
can still use this value to make decisions about when/what to notify.
|
||||
|
||||
Raises ValueError if --operatornotify-level X is not a recognized level.
|
||||
'''
|
||||
# This serves the purpose of normalizing the argument, but also creating a
|
||||
# duplicate list so we are not altering sys.argv.
|
||||
|
@ -197,18 +199,27 @@ def get_level_by_argv(argv):
|
|||
argv = ['--operatornotify-level' if arg == '--operatornotify_level' else arg for arg in argv]
|
||||
|
||||
level = None
|
||||
if '--operatornotify-level' in argv:
|
||||
level = argv.pop(argv.index('--operatornotify-level') + 1)
|
||||
|
||||
try:
|
||||
index = argv.index('--operatornotify-level')
|
||||
except ValueError:
|
||||
pass
|
||||
else:
|
||||
argv.pop(index)
|
||||
level = argv.pop(index)
|
||||
try:
|
||||
level = int(level)
|
||||
except ValueError:
|
||||
level = vlogging.get_level_by_name(level)
|
||||
argv.remove('--operatornotify-level')
|
||||
|
||||
if '--operatornotify' in argv:
|
||||
try:
|
||||
index = argv.index('--operatornotify')
|
||||
except ValueError:
|
||||
pass
|
||||
else:
|
||||
if level is None:
|
||||
level = vlogging.WARNING
|
||||
argv.remove('--operatornotify')
|
||||
argv.pop(index)
|
||||
|
||||
return (argv, level)
|
||||
|
||||
|
|
Loading…
Reference in a new issue