From 5b78805b68fa09f918989c0f2b79ddbc622b2c97 Mon Sep 17 00:00:00 2001 From: Alessio Sergi Date: Thu, 4 Dec 2014 12:27:27 +0100 Subject: [PATCH] Fix blind except statements --- glances/core/glances_autodiscover.py | 2 +- glances/core/glances_client.py | 4 ++-- glances/core/glances_monitor_list.py | 2 +- glances/core/glances_processes.py | 8 ++++---- glances/outputs/glances_curses.py | 12 ++++++------ glances/outputs/glances_history.py | 2 +- glances/plugins/glances_diskio.py | 2 +- glances/plugins/glances_help.py | 2 +- glances/plugins/glances_system.py | 2 +- glances/plugins/glances_uptime.py | 2 +- 10 files changed, 19 insertions(+), 19 deletions(-) diff --git a/glances/core/glances_autodiscover.py b/glances/core/glances_autodiscover.py index 8bb544b2..1545dcaf 100644 --- a/glances/core/glances_autodiscover.py +++ b/glances/core/glances_autodiscover.py @@ -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): diff --git a/glances/core/glances_client.py b/glances/core/glances_client.py index 45d9db7c..ba432160 100644 --- a/glances/core/glances_client.py +++ b/glances/core/glances_client.py @@ -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: diff --git a/glances/core/glances_monitor_list.py b/glances/core/glances_monitor_list.py index 59b51937..d3eebaea 100644 --- a/glances/core/glances_monitor_list.py +++ b/glances/core/glances_monitor_list.py @@ -80,7 +80,7 @@ class MonitorList(object): value["description"] = description try: re.compile(regex) - except: + except Exception: continue else: value["regex"] = regex diff --git a/glances/core/glances_processes.py b/glances/core/glances_processes.py index b65f535b..e7a614b6 100644 --- a/glances/core/glances_processes.py +++ b/glances/core/glances_processes.py @@ -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: diff --git a/glances/outputs/glances_curses.py b/glances/outputs/glances_curses.py index 46c5d056..27883a11 100644 --- a/glances/outputs/glances_curses.py +++ b/glances/outputs/glances_curses.py @@ -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 diff --git a/glances/outputs/glances_history.py b/glances/outputs/glances_history.py index 436bf999..f134d7da 100644 --- a/glances/outputs/glances_history.py +++ b/glances/outputs/glances_history.py @@ -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"') diff --git a/glances/plugins/glances_diskio.py b/glances/plugins/glances_diskio.py index 92120696..15759fe4 100644 --- a/glances/plugins/glances_diskio.py +++ b/glances/plugins/glances_diskio.py @@ -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 diff --git a/glances/plugins/glances_help.py b/glances/plugins/glances_help.py index a057bf87..21ab3a3f 100644 --- a/glances/plugins/glances_help.py +++ b/glances/plugins/glances_help.py @@ -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()) diff --git a/glances/plugins/glances_system.py b/glances/plugins/glances_system.py index fbc83e4a..6e52a148 100644 --- a/glances/plugins/glances_system.py +++ b/glances/plugins/glances_system.py @@ -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)) diff --git a/glances/plugins/glances_uptime.py b/glances/plugins/glances_uptime.py index 9750ebc2..c49023f4 100644 --- a/glances/plugins/glances_uptime.py +++ b/glances/plugins/glances_uptime.py @@ -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 -- GitLab