Skip to content

Commit

Permalink
Correct an issue if section did not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolargo committed Feb 7, 2021
1 parent 040528a commit aea9942
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions glances/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from io import open
import re

from glances.compat import ConfigParser, NoOptionError, system_exec
from glances.compat import ConfigParser, NoOptionError, NoSectionError, system_exec
from glances.globals import BSD, LINUX, MACOS, SUNOS, WINDOWS
from glances.logger import logger

Expand Down Expand Up @@ -295,7 +295,7 @@ def get_value(self, section, option,
ret = default
try:
ret = self.parser.get(section, option)
except NoOptionError:
except (NoOptionError, NoSectionError):
pass

# Search a substring `foo` and replace it by the result of its exec
Expand All @@ -312,19 +312,19 @@ def get_int_value(self, section, option, default=0):
"""Get the int value of an option, if it exists."""
try:
return self.parser.getint(section, option)
except NoOptionError:
except (NoOptionError, NoSectionError):
return int(default)

def get_float_value(self, section, option, default=0.0):
"""Get the float value of an option, if it exists."""
try:
return self.parser.getfloat(section, option)
except NoOptionError:
except (NoOptionError, NoSectionError):
return float(default)

def get_bool_value(self, section, option, default=True):
"""Get the bool value of an option, if it exists."""
try:
return self.parser.getboolean(section, option)
except NoOptionError:
except (NoOptionError, NoSectionError):
return bool(default)
2 changes: 1 addition & 1 deletion glances/plugins/glances_diskio.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def __init__(self, args=None, config=None):
self.display_curse = True
# Hide stats if it has never been != 0
self.hide_zero = config.get_bool_value(
self.plugin_name, 'hide_zero', default=False)
self.plugin_name + 'XXX', 'hide_zero', default=False)
self.hide_zero_fields = ['read_bytes', 'write_bytes']

def get_key(self):
Expand Down

0 comments on commit aea9942

Please sign in to comment.