diff options
43 files changed, 154 insertions, 217 deletions
diff --git a/glances/amps/amp.py b/glances/amps/amp.py index b34063af..61a3b0a4 100644 --- a/glances/amps/amp.py +++ b/glances/amps/amp.py @@ -109,16 +109,14 @@ class GlancesAmp(object): """Generic method to get the item in the AMP configuration""" if key in self.configs: return self.configs[key] - else: - return None + return None def enable(self): """Return True|False if the AMP is enabled in the configuration file (enable=true|false).""" ret = self.get('enable') if ret is None: return False - else: - return ret.lower().startswith('true') + return ret.lower().startswith('true') def regex(self): """Return regular expression used to identified the current application.""" @@ -133,8 +131,7 @@ class GlancesAmp(object): ret = self.get('one_line') if ret is None: return False - else: - return ret.lower().startswith('true') + return ret.lower().startswith('true') def time_until_refresh(self): """Return time in seconds until refresh.""" @@ -193,5 +190,4 @@ class GlancesAmp(object): # Call the children update method if self.should_update(): return self.update(process_list) - else: - return self.result() + return self.result() diff --git a/glances/attribute.py b/glances/attribute.py index 4c6c7767..22f25ef2 100644 --- a/glances/attribute.py +++ b/glances/attribute.py @@ -66,8 +66,7 @@ class GlancesAttribute(object): def value(self): if self.history_len() > 0: return (self._value[1] - self.history_value()[1]) / (self._value[0] - self.history_value()[0]) - else: - return None + return None @value.setter def value(self, new_value): diff --git a/glances/autodiscover.py b/glances/autodiscover.py index 336af140..9b784697 100644 --- a/glances/autodiscover.py +++ b/glances/autodiscover.py @@ -148,8 +148,7 @@ class GlancesAutoDiscoverServer(object): """Return the current server list (dict of dict).""" if zeroconf_tag and self.zeroconf_enable_tag: return self.listener.get_servers_list() - else: - return [] + return [] def set_server(self, server_pos, key, value): """Set the key to the value for the server_pos (position in the list).""" diff --git a/glances/client.py b/glances/client.py index 1412d1e1..c4cfe185 100644 --- a/glances/client.py +++ b/glances/client.py @@ -182,12 +182,12 @@ class GlancesClient(object): """Update stats from Glances/SNMP server.""" if self.client_mode == 'glances': return self.update_glances() - elif self.client_mode == 'snmp': + if self.client_mode == 'snmp': return self.update_snmp() - else: - self.end() - logger.critical("Unknown server mode: {}".format(self.client_mode)) - sys.exit(2) + + self.end() + logger.critical("Unknown server mode: {}".format(self.client_mode)) + sys.exit(2) def update_glances(self): """Get stats from Glances server. diff --git a/glances/client_browser.py b/glances/client_browser.py index c8ba9a8a..1409d316 100644 --- a/glances/client_browser.py +++ b/glances/client_browser.py @@ -77,8 +77,7 @@ class GlancesClientBrowser(object): if clear_password is not None: server['password'] = self.password.get_hash(clear_password) return 'http://{}:{}@{}:{}'.format(server['username'], server['password'], server['ip'], server['port']) - else: - return 'http://{}:{}'.format(server['ip'], server['port']) + return 'http://{}:{}'.format(server['ip'], server['port']) def __update_stats(self, server): """Update stats for the given server (picked from the server list)""" diff --git a/glances/cpu_percent.py b/glances/cpu_percent.py index f978f863..e6fe96ec 100644 --- a/glances/cpu_percent.py +++ b/glances/cpu_percent.py @@ -46,8 +46,7 @@ class CpuPercent(object): If percpu, return the percpu stats""" if percpu: return self.__get_percpu() - else: - return self.__get_cpu() + return self.__get_cpu() def get_info(self): """Get additional information about the CPU""" diff --git a/glances/events_list.py b/glances/events_list.py index b50ec83f..e1105d5f 100644 --- a/glances/events_list.py +++ b/glances/events_list.py @@ -158,8 +158,7 @@ def build_global_message(): if themax['weight'] >= themax['thresholds_min']: # Check if the weight is > to the minimal threshold value return themax['msg'] - else: - return tree[0]['msg'] + return tree[0]['msg'] class GlancesEventsList(object): diff --git a/glances/exports/export.py b/glances/exports/export.py index 4b57a122..b92654ea 100644 --- a/glances/exports/export.py +++ b/glances/exports/export.py @@ -122,8 +122,7 @@ class GlancesExport(object): logger.error("No 'key' available in {}".format(item)) if isinstance(ret, list): return ret[0] - else: - return ret + return ret def parse_tags(self, tags): """Parse tags into a dict. diff --git a/glances/exports/glances_graphite/__init__.py b/glances/exports/glances_graphite/__init__.py index 84289238..2defe864 100644 --- a/glances/exports/glances_graphite/__init__.py +++ b/glances/exports/glances_graphite/__init__.py @@ -100,6 +100,4 @@ def normalize(name): """Normalize name for the Graphite convention""" # Name should not contain space - ret = name.replace(' ', '_') - - return ret + return name.replace(' ', '_') diff --git a/glances/exports/glances_influxdb2/__init__.py b/glances/exports/glances_influxdb2/__init__.py index 8b8ea964..7e10b8b3 100644 --- a/glances/exports/glances_influxdb2/__init__.py +++ b/glances/exports/glances_influxdb2/__init__.py @@ -84,7 +84,7 @@ class Export(GlancesExport): ) # Create the write client - write_client = client.write_api( + return client.write_api( write_options=WriteOptions( batch_size=500, flush_interval=self.interval * 1000, @@ -95,7 +95,6 @@ class Export(GlancesExport): exponential_base=2, ) ) - return write_client def _normalize(self, name, columns, points): """Normalize data for the InfluxDB's data model. diff --git a/glances/exports/glances_rabbitmq/__init__.py b/glances/exports/glances_rabbitmq/__init__.py index 0cec274e..5d481aa1 100644 --- a/glances/exports/glances_rabbitmq/__init__.py +++ b/glances/exports/glances_rabbitmq/__init__.py @@ -67,8 +67,7 @@ class Export(GlancesExport): self.protocol + '://' + self.user + ':' + self.password + '@' + self.host + ':' + self.port + '/' ) connection = pika.BlockingConnection(parameters) - channel = connection.channel() - return channel + return connection.channel() except Exception as e: logger.critical("Connection to rabbitMQ server %s:%s failed. %s" % (self.host, self.port, e)) sys.exit(2) @@ -79,8 +78,8 @@ class Export(GlancesExport): for i in range(len(columns)): if not isinstance(points[i], Number): continue - else: - data += ", " + columns[i] + "=" + str(points[i]) + data += ", " + columns[i] + "=" + str(points[i]) + logger.debug(data) try: self.client.basic_publish(exchange='', routing_key=self.queue, body=data) diff --git a/glances/exports/glances_riemann/__init__.py b/glances/exports/glances_riemann/__init__.py index 79dd2cb8..50e12e05 100644 --- a/glances/exports/glances_riemann/__init__.py +++ b/glances/exports/glances_riemann/__init__.py @@ -48,8 +48,7 @@ class Export(GlancesExport): if not self.export_enable: return None try: - client = bernhard.Client(host=self.host, port=self.port) - return client + return bernhard.Client(host=self.host, port=self.port) except Exception as e: logger.critical("Connection to Riemann failed : %s " % e) return None @@ -59,10 +58,10 @@ class Export(GlancesExport): for i in range(len(columns)): if not isinstance(points[i], Number): continue - else: - data = {'host': self.hostname, 'service': name + " " + columns[i], 'metric': points[i]} - logger.debug(data) - try: - self.client.send(data) - except Exception as e: - logger.error("Cannot export stats to Riemann (%s)" % e) + + data = {'host': self.hostname, 'service': name + " " + columns[i], 'metric': points[i]} + logger.debug(data) + try: + self.client.send(data) + except Exception as e: + logger.error("Cannot export stats to Riemann (%s)" % e) diff --git a/glances/exports/glances_statsd/__init__.py b/glances/exports/glances_statsd/__init__.py index d65c36ca..89dd3f33 100644 --- a/glances/exports/glances_statsd/__init__.py +++ b/glances/exports/glances_statsd/__init__.py @@ -69,6 +69,4 @@ def normalize(name): # Name should not contain some specials chars (issue #1068) ret = name.replace(':', '') ret = ret.replace('%', '') - ret = ret.replace(' ', '_') - - return ret + return ret.replace(' ', '_') diff --git a/glances/filter.py b/glances/filter.py index c0a4a529..e2061277 100644 --- a/glances/filter.py +++ b/glances/filter.py @@ -156,9 +156,9 @@ class GlancesFilter(object): if self.filter_key is None: # Apply filter on command line and process name return self._is_process_filtered(process, key='name') or self._is_process_filtered(process, key='cmdline') - else: - # Apply filter on <key> - return self._is_process_filtered(process) + + # Apply filter on <key> + return self._is_process_filtered(process) def _is_process_filtered(self, process, key=None): """Return True if the process[key] should be filtered according to the current filter""" diff --git a/glances/folder_list.py b/glances/folder_list.py index 5820e847..2211e5f6 100644 --- a/glances/folder_list.py +++ b/glances/folder_list.py @@ -67,8 +67,7 @@ class FolderList(object): value['path'] = self.config.get_value(section, key + 'path') if value['path'] is None: continue - else: - value['path'] = nativestr(value['path']) + value['path'] = nativestr(value['path']) # Optional conf keys # Refresh time diff --git a/glances/globals.py b/glances/globals.py index e18a9f35..43c3b697 100644 --- a/glances/globals.py +++ b/glances/globals.py @@ -128,10 +128,9 @@ def b(s, errors='replace'): def nativestr(s, errors='replace'): if isinstance(s, text_type): return s - elif isinstance(s, (int, float)): + if isinstance(s, (int, float)): return s.__str__() - else: - return s.decode('utf-8', errors=errors) + return s.decode('utf-8', errors=errors) def system_exec(command): @@ -331,8 +330,7 @@ def json_dumps_dictlist(data, item): dl = dictlist(data, item) if dl is None: return None - else: - return json_dumps(dl) + return json_dumps(dl) def string_value_to_float(s): diff --git a/glances/outputs/glances_bars.py b/glances/outputs/glances_bars.py index d434c0f9..d6012b9a 100644 --- a/glances/outputs/glances_bars.py +++ b/glances/outputs/glances_bars.py @@ -76,6 +76,7 @@ class Bar(object): return self.__size if self.__display_value: return self.__size - 6 + return None @property def percent(self): diff --git a/glances/outputs/glances_curses.py b/glances/outputs/glances_curses.py index bed7970a..5a8321af 100644 --- a/glances/outputs/glances_curses.py +++ b/glances/outputs/glances_curses.py @@ -154,9 +154,9 @@ class _GlancesCurses(object): logger.info("Cannot init the curses library, quiet mode on and export.") args.quiet = True return - else: - logger.critical("Cannot init the curses library ({})".format(e)) - sys.exit(1) + + logger.critical("Cannot init the curses library ({})".format(e)) + sys.exit(1) # Load configuration file self.load_config(config) @@ -359,8 +359,7 @@ class _GlancesCurses(object): def get_key(self, window): # TODO: Check issue #163 - ret = window.getch() - return ret + return window.getch() def __catch_key(self, return_to_browser=False): # Catch the pressed key @@ -990,7 +989,8 @@ class _GlancesCurses(object): popup.refresh() self.wait(duration * 1000) return True - elif popup_type == 'input': + + if popup_type == 'input': logger.info(popup_type) logger.info(is_password) # Create a sub-window for the text field @@ -1010,17 +1010,17 @@ class _GlancesCurses(object): self.set_cursor(0) if textbox != '': return textbox - else: - return None - else: - textbox = GlancesTextbox(sub_pop, insert_mode=True) - textbox.edit() - self.set_cursor(0) - if textbox.gather() != '': - return textbox.gather()[:-1] - else: - return None - elif popup_type == 'yesno': + return None + + # No password + textbox = GlancesTextbox(sub_pop, insert_mode=True) + textbox.edit() + self.set_cursor(0) + if textbox.gather() != '': + return textbox.gather()[:-1] + return None + + if popup_type == 'yesno': # # Create a sub-window for the text field sub_pop = popup.derwin(1, 2, len(sentence_list) + 1, len(m) + 2) sub_pop.attron(self.colors_list['FILTER']) @@ -1038,6 +1038,8 @@ class _GlancesCurses(object): # self.term_window.keypad(0) return textbox.gather() + return None + def display_plugin(self, plugin_stats, display_optional=True, display_additional=True, max_y=65535, add_space=0): """Display the plugin_stats on the screen. @@ -1132,6 +1134,7 @@ class _GlancesCurses(object): # Have empty lines after the plugins self.next_line += add_space + return None def clear(self): """Erase the content of the screen. @@ -1214,8 +1217,7 @@ class _GlancesCurses(object): if isexitkey and self.args.help_tag: # Quit from help should return to main screen, not exit #1874 self.args.help_tag = not self.args.help_tag - isexitkey = False - return isexitkey + return False if not isexitkey and pressedkey > -1: # Redraw display diff --git a/glances/outputs/glances_sparklines.py b/glances/outputs/glances_sparklines.py index d4ada88c..99f6e9fe 100644 --- a/glances/outputs/glances_sparklines.py +++ b/glances/outputs/glances_sparklines.py @@ -59,6 +59,7 @@ class Sparkline(object): return self.__size if self.__display_value: return self.__size - 6 + return None @property def percents(self): diff --git a/glances/outputs/glances_stdout_apidoc.py b/glances/outputs/glances_stdout_apidoc.py index 907d4929..8b9350d9 100644 --- a/glances/outputs/glances_stdout_apidoc.py +++ b/glances/outputs/glances_stdout_apidoc.py @@ -82,8 +82,7 @@ def indent_stat(stat, indent=' '): if isinstance(stat, list) and len(stat) > 1 and isinstance(stat[0], dict): # Only display two first items return indent + pformat(stat[0:2]).replace('\n', '\n' + indent).replace("'", '"') - else: - return indent + pformat(stat).replace('\n', '\n' + indent).replace("'", '"') + return indent + pformat(stat).replace('\n', '\n' + indent).replace("'", '"') def print_api_status(): diff --git a/glances/outputs/glances_unicode.py b/glances/outputs/glances_unicode.py index 76ae3e60..99f4e786 100644 --- a/glances/outputs/glances_unicode.py +++ b/glances/outputs/glances_unicode.py @@ -25,5 +25,4 @@ def unicode_message(key, args=None): """Return the unicode message for the given key.""" if args and hasattr(args, 'disable_unicode') and args.disable_unicode: return _unicode_message[key][1] - else: - return _unicode_message[key][0] + return _unicode_message[key][0] diff --git a/glances/password.py b/glances/password.py index c4e8280e..9d79e995 100644 --- a/glances/password.py +++ b/glances/password.py @@ -38,8 +38,7 @@ class GlancesPassword(object): """ if self.config is None: return user_config_dir()[0] - else: - return self.config.get_value('passwords', 'local_password_path', default=user_config_dir()[0]) + return self.config.get_value('passwords', 'local_password_path', default=user_config_dir()[0]) @weak_lru_cache(maxsize=32) def get_hash(self, plain_password, salt=''): @@ -120,6 +119,4 @@ class GlancesPassword(object): """Load the hashed password from the Glances folder.""" # Read the password file, if it exists with open(self.password_file, 'r') as file_pwd: - hashed_password = file_pwd.read() - - return hashed_password + return file_pwd.read() diff --git a/glances/password_list.py b/glances/password_list.py index 21ee3c7a..1f3973fa 100644 --- a/glances/password_list.py +++ b/glances/password_list.py @@ -51,14 +51,14 @@ class GlancesPasswordList(GlancesPassword): """ if host is None: return self._password_dict - else: + + try: + return self._password_dict[host] + except (KeyError, TypeError): try: - return self._password_dict[host] + return self._password_dict['default'] except (KeyError, TypeError): - try: - return self._password_dict['default'] - except (KeyError, TypeError): - return None + return None def set_password(self, host, password): """Set a password for a specific host.""" diff --git a/glances/plugins/alert/__init__.py b/glances/plugins/alert/__init__.py index 8275bb30..4068d395 100644 --- a/glances/plugins/alert/__init__.py +++ b/glances/plugins/alert/__init__.py @@ -183,5 +183,4 @@ class PluginModel(GlancesPluginModel): """Compare a with b using the tolerance (if numerical).""" if str(int(a)).isdigit() and str(int(b)).isdigit(): return abs(a - b) <= max(abs(a), abs(b)) * tolerance - else: - return a == b + return a == b diff --git a/glances/plugins/amps/__init__.py b/glances/plugins/amps/__init__.py index 9e9e46be..acdcf315 100644 --- a/glances/plugins/amps/__init__.py +++ b/glances/plugins/amps/__init__.py @@ -93,13 +93,11 @@ class PluginModel(GlancesPluginModel): if nbprocess > 0: if int(countmin) <= int(nbprocess) <= int(countmax): return 'OK' - else: - return 'WARNING' - else: - if int(countmin) == 0: - return 'OK' - else: - return 'CRITICAL' + return 'WARNING' + + if int(countmin) == 0: + return 'OK' + return 'CRITICAL' def msg_curse(self, args=None, max_width=None): """Return the dict to display in the curse interface.""" diff --git a/glances/plugins/containers/__init__.py b/glances/plugins/containers/__init__.py index e88d1d36..024b97fa 100644 --- a/glances/plugins/containers/__init__.py +++ b/glances/plugins/containers/__init__.py @@ -164,8 +164,7 @@ class PluginModel(GlancesPluginModel): conf_podman_sock = self.get_conf_value('podman_sock') if len(conf_podman_sock) == 0: return "unix:///run/user/1000/podman/podman.sock" - else: - return conf_podman_sock[0] + return conf_podman_sock[0] def exit(self): """Overwrite the exit method to close threads.""" @@ -209,8 +208,7 @@ class PluginModel(GlancesPluginModel): all_tag = self.get_conf_value('all') if len(all_tag) == 0: return False - else: - return all_tag[0].lower() == 'true' + return all_tag[0].lower() == 'true' @GlancesPluginModel._check_decorator @GlancesPluginModel._log_result_decorator @@ -453,12 +451,11 @@ class PluginModel(GlancesPluginModel): """Analyse the container status.""" if status == 'running': return 'OK' - elif status == 'exited': + if status == 'exited': return 'WARNING' - elif status == 'dead': + if status == 'dead': return 'CRITICAL' - else: - return 'CAREFUL' + return 'CAREFUL' def sort_docker_stats(stats): diff --git a/glances/plugins/containers/engines/docker.py b/glances/plugins/containers/engines/docker.py index a74e2a70..ab27dadc 100644 --- a/glances/plugins/containers/engines/docker.py +++ b/glances/plugins/containers/engines/docker.py @@ -71,13 +71,12 @@ class DockerStatsFetcher: memory_stats = self._get_memory_stats() network_stats = self._get_network_stats() - computed_stats = { |