提交 5b78805b 编写于 作者: A Alessio Sergi

Fix blind except statements

上级 ed0ef184
......@@ -227,7 +227,7 @@ class GlancesAutoDiscoverClient(object):
gateway_itf = netifaces.gateways()['default'][netifaces.AF_INET][1]
# IP address for the interface
return netifaces.ifaddresses(gateway_itf)[netifaces.AF_INET][0]['addr']
except:
except Exception:
return None
def close(self):
......
......@@ -30,7 +30,7 @@ except ImportError:
from xmlrpclib import Transport, ServerProxy, ProtocolError, Fault
try:
import http.client as httplib
except:
except ImportError:
# Python 2
import httplib
......@@ -214,7 +214,7 @@ class GlancesClient(object):
# Update the stats
try:
self.stats.update()
except:
except Exception:
# Client can not get SNMP server stats
return "Disconnected"
else:
......
......@@ -80,7 +80,7 @@ class MonitorList(object):
value["description"] = description
try:
re.compile(regex)
except:
except Exception:
continue
else:
value["regex"] = regex
......
......@@ -288,7 +288,7 @@ class GlancesProcesses(object):
self.process_filter_re = re.compile(value)
logger.debug(
_("Process filter regular expression compilation OK: %s") % self.get_process_filter())
except:
except Exception:
logger.error(
_("Can not compile process filter regular expression: %s") % value)
self.process_filter_re = None
......@@ -487,7 +487,7 @@ class GlancesProcesses(object):
pass
except psutil.AccessDenied:
procstat['memory_swap'] = None
except:
except Exception:
# Add a dirty except to handle the PsUtil issue #413
procstat['memory_swap'] = None
......@@ -495,7 +495,7 @@ class GlancesProcesses(object):
try:
procstat['tcp'] = len(proc.connections(kind="tcp"))
procstat['udp'] = len(proc.connections(kind="udp"))
except:
except Exception:
procstat['tcp'] = None
procstat['udp'] = None
......@@ -570,7 +570,7 @@ class GlancesProcesses(object):
# Update thread number (global statistics)
try:
self.processcount['thread'] += proc.num_threads()
except:
except Exception:
pass
if self._enable_tree:
......
......@@ -95,14 +95,14 @@ class _GlancesCurses(object):
curses.init_pair(8, curses.COLOR_BLUE, -1)
try:
curses.init_pair(9, curses.COLOR_MAGENTA, -1)
except:
except Exception:
if args.theme_white:
curses.init_pair(9, curses.COLOR_BLACK, -1)
else:
curses.init_pair(9, curses.COLOR_WHITE, -1)
try:
curses.init_pair(10, curses.COLOR_CYAN, -1)
except:
except Exception:
if args.theme_white:
curses.init_pair(10, curses.COLOR_BLACK, -1)
else:
......@@ -553,7 +553,7 @@ class _GlancesCurses(object):
elif (self.history_tag or self.reset_history_tag) and not self.args.enable_history:
try:
self.glances_history.graph_enabled()
except:
except Exception:
self.display_popup(
_("History disabled\nEnable it using --enable-history"))
else:
......@@ -717,7 +717,7 @@ class _GlancesCurses(object):
# Do not disply outside the screen
screen_x - x,
self.colors_list[m['decoration']])
except:
except Exception:
pass
else:
# New column
......@@ -803,7 +803,7 @@ class _GlancesCurses(object):
# Size with all options
c = len(max(''.join([i['msg']
for i in curse_msg['msgdict']]).split('\n'), key=len))
except:
except Exception:
return 0
else:
return c
......@@ -815,7 +815,7 @@ class _GlancesCurses(object):
"""
try:
c = [i['msg'] for i in curse_msg['msgdict']].count('\n')
except:
except Exception:
return 0
else:
return c + 1
......
......@@ -29,7 +29,7 @@ from glances.core.glances_globals import logger
try:
from matplotlib import __version__ as matplotlib_version
import matplotlib.pyplot as plt
except:
except ImportError:
matplotlib_check = False
logger.warning(
'Can not load Matplotlib library. Please install it using "pip install matplotlib"')
......
......@@ -70,7 +70,7 @@ class Plugin(GlancesPlugin):
# write_time: time spent writing to disk (in milliseconds)
try:
diskiocounters = psutil.disk_io_counters(perdisk=True)
except:
except Exception:
return self.stats
# Previous disk IO stats are stored in the diskio_old variable
......
......@@ -62,7 +62,7 @@ class Plugin(GlancesPlugin):
# Configuration file path
try:
msg = '{0}: {1}'.format(_("Configuration file"), self.config.get_loaded_config_file())
except AttributeError as e:
except AttributeError:
pass
else:
ret.append(self.curse_new_line())
......
......@@ -152,7 +152,7 @@ class Plugin(GlancesPlugin):
msg = ' ({0} {1} {2})'.format(self.stats['os_name'],
self.stats['os_version'],
self.stats['platform'])
except:
except Exception:
msg = ' ({0})'.format(self.stats['os_name'])
ret.append(self.curse_add_line(msg, optional=True))
......
......@@ -74,7 +74,7 @@ class Plugin(GlancesPlugin):
try:
# In hundredths of seconds
self.stats = str(timedelta(seconds=int(uptime) / 100))
except:
except Exception:
pass
# Return the result
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册