diff --git a/conf/glances.conf b/conf/glances.conf index 3a0b8755fc602839a5cc12e58a9cd05e3d6cca01..1c24b7731ff5ebcc67e8c8c156d58bd5b4cd5701 100644 --- a/conf/glances.conf +++ b/conf/glances.conf @@ -203,7 +203,7 @@ critical=90 [irq] # Documentation: https://glances.readthedocs.io/en/stable/aoa/irq.html # This plugin is disabled by default -disable=False +disable=True [folders] # Documentation: https://glances.readthedocs.io/en/stable/aoa/folders.html diff --git a/glances/compat.py b/glances/compat.py index 938c4b1696bd829a8965ca08be81bed1b3c60521..3822bf3c097d121892c28bd6356b93a89d3c9a67 100644 --- a/glances/compat.py +++ b/glances/compat.py @@ -283,3 +283,15 @@ def key_exist_value_not_none_not_v(k, d, v=''): # - d[k] is not None # - d[k] != v return k in d and d[k] is not None and d[k] != v + + +def disable(class_name, var): + """Set disable_ to True in the class class_name.""" + setattr(class_name, 'enable_' + var, False) + setattr(class_name, 'disable_' + var, True) + + +def enable(class_name, var): + """Set disable_ to False in the class class_name.""" + setattr(class_name, 'enable_' + var, True) + setattr(class_name, 'disable_' + var, False) diff --git a/glances/main.py b/glances/main.py index 9cb81f2b6ec142ec481ddf0b58a4452e50166f6f..11e68a3b53cffb571052ff895851632aa31aa060 100644 --- a/glances/main.py +++ b/glances/main.py @@ -24,22 +24,12 @@ import sys import tempfile from glances import __version__, psutil_version -from glances.compat import input +from glances.compat import input, disable, enable from glances.config import Config from glances.globals import WINDOWS from glances.logger import logger, LOG_FILENAME -def disable(class_name, var): - """Set disable_ to True in the class class_name.""" - setattr(class_name, 'disable_' + var, True) - - -def enable(class_name, var): - """Set disable_ to False in the class class_name.""" - setattr(class_name, 'disable_' + var, False) - - class GlancesMain(object): """Main class to manage Glances instance.""" diff --git a/glances/outputs/glances_curses.py b/glances/outputs/glances_curses.py index 121bbf8cbaaee441f67fb7fb6db480ba40353ec8..2e4a535d5c2000f79aa92ec4245e6b1ce8e1aefd 100644 --- a/glances/outputs/glances_curses.py +++ b/glances/outputs/glances_curses.py @@ -23,7 +23,7 @@ from __future__ import unicode_literals import re import sys -from glances.compat import to_ascii, nativestr, b, u, itervalues +from glances.compat import to_ascii, nativestr, b, u, itervalues, enable, disable from glances.globals import MACOS, WINDOWS from glances.logger import logger from glances.events import glances_events @@ -36,9 +36,11 @@ try: import curses.panel from curses.textpad import Textbox except ImportError: - logger.critical("Curses module not found. Glances cannot start in standalone mode.") + logger.critical( + "Curses module not found. Glances cannot start in standalone mode.") if WINDOWS: - logger.critical("For Windows you can try installing windows-curses with pip install.") + logger.critical( + "For Windows you can try installing windows-curses with pip install.") sys.exit(1) @@ -348,10 +350,25 @@ class _GlancesCurses(object): # Actions (available in the global hotkey dict)... for hotkey in self._hotkeys: if self.pressedkey == ord(hotkey) and 'switch' in self._hotkeys[hotkey]: - setattr(self.args, - self._hotkeys[hotkey]['switch'], - not getattr(self.args, - self._hotkeys[hotkey]['switch'])) + if self._hotkeys[hotkey]['switch'].startswith('enable_') or \ + self._hotkeys[hotkey]['switch'].startswith('disable_'): + # Enable / Disable switch + # Get the option name + # Ex: disable_foo return foo + # enable_foo_bar return foo_bar + option = '_'.join( + self._hotkeys[hotkey]['switch'].split('_')[1:]) + if getattr(self.args, + self._hotkeys[hotkey]['switch']): + disable(self.args, option) + else: + enable(self.args, option) + else: + # Others switchs options (with no enable_ or disable_) + setattr(self.args, + self._hotkeys[hotkey]['switch'], + not getattr(self.args, + self._hotkeys[hotkey]['switch'])) if self.pressedkey == ord(hotkey) and 'sort_key' in self._hotkeys[hotkey]: glances_processes.set_sort_key(self._hotkeys[hotkey]['sort_key'], self._hotkeys[hotkey]['sort_key'] == 'auto') diff --git a/glances/plugins/glances_irq.py b/glances/plugins/glances_irq.py index 7f666df7abfabc12caa2c3bc1d24a6b474afa0e9..8bf5b1291f9494b828cbec8a4377d941377b1e0a 100644 --- a/glances/plugins/glances_irq.py +++ b/glances/plugins/glances_irq.py @@ -22,6 +22,7 @@ import os import operator +from glances.logger import logger from glances.globals import LINUX from glances.timer import getTimeSinceLastUpdate from glances.plugins.glances_plugin import GlancesPlugin diff --git a/glances/plugins/glances_plugin.py b/glances/plugins/glances_plugin.py index 869cac7b8216babb1f4db9acf8627777f1bde7cf..50029d7358b98972c588c70e2e13a43bb4e713bf 100644 --- a/glances/plugins/glances_plugin.py +++ b/glances/plugins/glances_plugin.py @@ -143,9 +143,8 @@ class GlancesPlugin(object): try: d = getattr(self.args, 'disable_' + plugin_name) except AttributeError: - return True - else: - return d is False + d = getattr(self.args, 'enable_' + plugin_name, True) + return d is False def is_disable(self, plugin_name=None): """Return true if plugin is disabled."""