From afe5e6c7f29867e16fada5eb59be65e0b30adb04 Mon Sep 17 00:00:00 2001 From: Alessio Sergi Date: Sat, 18 Jul 2015 18:18:18 +0200 Subject: [PATCH] Use Python 2.6 compatible string.format calls (closes #633) --- glances/exports/glances_export.py | 8 ++++---- glances/exports/glances_influxdb.py | 4 ++-- glances/exports/glances_statsd.py | 2 +- glances/outputs/glances_curses.py | 2 +- glances/plugins/glances_docker.py | 11 ++++++----- glances/plugins/glances_raid.py | 2 +- 6 files changed, 15 insertions(+), 14 deletions(-) diff --git a/glances/exports/glances_export.py b/glances/exports/glances_export.py index 6ec8998d..0b70ae59 100644 --- a/glances/exports/glances_export.py +++ b/glances/exports/glances_export.py @@ -70,11 +70,11 @@ class GlancesExport(object): 'docker'] def get_item_key(self, item): - """Return the value of the item 'key'""" + """Return the value of the item 'key'.""" try: ret = item[item['key']] except KeyError: - logger.error("No 'key' available in {}".format(item)) + logger.error("No 'key' available in {0}".format(item)) if isinstance(ret, list): return ret[0] else: @@ -112,7 +112,7 @@ class GlancesExport(object): return True def __build_export(self, stats): - """Build the export lists""" + """Build the export lists.""" export_names = [] export_values = [] @@ -120,7 +120,7 @@ class GlancesExport(object): # Stats is a dict # Is there a key ? if 'key' in list(stats.keys()): - pre_key = '{}.'.format(stats[stats['key']]) + pre_key = '{0}.'.format(stats[stats['key']]) else: pre_key = '' # Walk through the dict diff --git a/glances/exports/glances_influxdb.py b/glances/exports/glances_influxdb.py index 946095cc..d03823d7 100644 --- a/glances/exports/glances_influxdb.py +++ b/glances/exports/glances_influxdb.py @@ -146,7 +146,7 @@ class Export(GlancesExport): def export(self, name, columns, points): """Write the points to the InfluxDB server.""" - logger.debug("Export {} stats to InfluxDB".format(name)) + logger.debug("Export {0} stats to InfluxDB".format(name)) # Manage prefix if self.prefix is not None: name = self.prefix + '.' + name @@ -162,4 +162,4 @@ class Export(GlancesExport): try: self.client.write_points(data) except Exception as e: - logger.error("Can not export {} stats to InfluxDB ({})".format(name, e)) + logger.error("Cannot export {0} stats to InfluxDB ({1})".format(name, e)) diff --git a/glances/exports/glances_statsd.py b/glances/exports/glances_statsd.py index aaff939a..0f06c2b7 100644 --- a/glances/exports/glances_statsd.py +++ b/glances/exports/glances_statsd.py @@ -100,4 +100,4 @@ class Export(GlancesExport): self.client.gauge(stat_name, stat_value) except Exception as e: logger.error("Can not export stats to Statsd (%s)" % e) - logger.debug("Export {} stats to Statsd".format(name)) + logger.debug("Export {0} stats to Statsd".format(name)) diff --git a/glances/outputs/glances_curses.py b/glances/outputs/glances_curses.py index 1205aa17..7e2a334c 100644 --- a/glances/outputs/glances_curses.py +++ b/glances/outputs/glances_curses.py @@ -1020,7 +1020,7 @@ class GlancesCursesBrowser(_GlancesCurses): servers_list: Dict of dict with servers stats """ # Flush display - logger.debug("Servers list: {}".format(servers_list)) + logger.debug('Servers list: {0}'.format(servers_list)) self.flush(servers_list) # Wait diff --git a/glances/plugins/glances_docker.py b/glances/plugins/glances_docker.py index 3d051154..4120666a 100644 --- a/glances/plugins/glances_docker.py +++ b/glances/plugins/glances_docker.py @@ -65,7 +65,8 @@ class Plugin(GlancesPlugin): return 'name' def get_export(self): - """Overwrite the default export method + """Overwrite the default export method. + - Only exports containers - The key is the first container name """ @@ -73,7 +74,7 @@ class Plugin(GlancesPlugin): try: ret = self.stats['containers'] except KeyError as e: - logger.debug("Docker export error {}".format(e)) + logger.debug("Docker export error {0}".format(e)) return ret def connect(self, version=None): @@ -180,10 +181,10 @@ class Plugin(GlancesPlugin): # Create the stats instance for the current container try: self.docker_stats[c['Id']] = self.docker_client.stats(c['Id'], decode=True) - logger.debug("Create Docker stats object for container {}".format(c['Id'])) + logger.debug("Create Docker stats object for container {0}".format(c['Id'])) except Exception as e: # Correct Issue #602 - logger.error("Can not call Docker stats method {}".format(e)) + logger.error("Cannot call Docker stats method {0}".format(e)) # Get the docker stats try: @@ -365,7 +366,7 @@ class Plugin(GlancesPlugin): # By storing time data we enable Rx/s and Tx/s calculations in the # XML/RPC API, which would otherwise be overly difficult work # for users of the API - network_new['time_since_update'] = getTimeSinceLastUpdate('docker_net_{}'.format(container_id)) + network_new['time_since_update'] = getTimeSinceLastUpdate('docker_net_{0}'.format(container_id)) network_new['rx'] = netiocounters["rx_bytes"] - self.netiocounters_old[container_id]["rx_bytes"] network_new['tx'] = netiocounters["tx_bytes"] - self.netiocounters_old[container_id]["tx_bytes"] network_new['cumulative_rx'] = netiocounters["rx_bytes"] diff --git a/glances/plugins/glances_raid.py b/glances/plugins/glances_raid.py index d0482c8d..3a88004a 100644 --- a/glances/plugins/glances_raid.py +++ b/glances/plugins/glances_raid.py @@ -112,7 +112,7 @@ class Plugin(GlancesPlugin): ret.append(self.curse_add_line(msg, status)) elif self.stats[array]['status'] == 'inactive': ret.append(self.curse_new_line()) - msg = '└─ Status {}'.format(self.stats[array]['status']) + msg = '└─ Status {0}'.format(self.stats[array]['status']) ret.append(self.curse_add_line(msg, status)) components = self.stats[array]['components'].keys() components.sort()