提交 e1c47695 编写于 作者: N nicolargo

Pressing Q to get rid of irq not working #1792

上级 89d3cb09
......@@ -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
......
......@@ -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_<var> 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_<var> to False in the class class_name."""
setattr(class_name, 'enable_' + var, True)
setattr(class_name, 'disable_' + var, False)
......@@ -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_<var> to True in the class class_name."""
setattr(class_name, 'disable_' + var, True)
def enable(class_name, var):
"""Set disable_<var> to False in the class class_name."""
setattr(class_name, 'disable_' + var, False)
class GlancesMain(object):
"""Main class to manage Glances instance."""
......
......@@ -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')
......
......@@ -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
......
......@@ -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."""
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册