Clean up strings

Use format() instead of % method.
This commit is contained in:
Alessio Sergi 2014-05-29 22:22:22 +02:00
parent d3a36c58b8
commit ab23f2c574
24 changed files with 182 additions and 183 deletions

View File

@ -58,8 +58,8 @@ class GlancesClient():
# Try to connect to the URI
try:
self.client = ServerProxy(uri)
except Exception as err:
print(_("Error: Couldn't create socket {0}: {1}").format(uri, err))
except Exception as e:
print(_("Error: Couldn't create socket {0}: {1}").format(uri, e))
sys.exit(2)
def set_mode(self, mode='glances'):
@ -144,7 +144,7 @@ class GlancesClient():
elif self.get_mode() == 'snmp':
return self.update_snmp()
else:
print(_("Error: Unknown server mode ({0})").format(self.get_mode()))
print(_("Error: Unknown server mode: {0}").format(self.get_mode()))
sys.exit(2)
def update_glances(self):

View File

@ -68,7 +68,7 @@ class Config(object):
self.parser.read(config_file)
# print(_("DEBUG: Read configuration file %s") % config_file)
except UnicodeDecodeError as e:
print(_("Error decoding configuration file '{0}': {1}").format(config_file, e))
print(_("Error: Cannot decode configuration file '{0}': {1}").format(config_file, e))
sys.exit(1)
break

View File

@ -38,7 +38,7 @@ except ImportError:
psutil_min_version = (2, 0, 0)
psutil_version = tuple([int(num) for num in __psutil_version__.split('.')])
if psutil_version < psutil_min_version:
print('psutil version %s detected.' % __psutil_version__)
print('psutil version {0} detected.').format(__psutil_version__)
print('psutil 2.0 or higher is needed. Glances cannot start.')
sys.exit(1)

View File

@ -89,7 +89,7 @@ class GlancesMain(object):
dest='output_csv', help=_('export stats to a CSV file'))
# Server option
parser.add_argument('-p', '--port', default=self.server_port, type=int, dest='port',
help=_('define the client/server TCP port [default: %d]') % self.server_port)
help=_('define the client/server TCP port [default: {0}]').format(self.server_port))
parser.add_argument('--password-badidea', dest='password_arg',
help=_('define password from the command line'))
parser.add_argument('--password', action='store_true', default=False, dest='password_prompt',
@ -107,7 +107,7 @@ class GlancesMain(object):
parser.add_argument('--snmp-auth', default='password', dest='snmp_auth',
help=_('SNMP authentication key (only for SNMPv3)'))
parser.add_argument('-t', '--time', default=self.refresh_time, type=int,
dest='time', help=_('set refresh time in seconds [default: %s sec]') % self.refresh_time)
dest='time', help=_('set refresh time in seconds [default: {0} sec]').format(self.refresh_time))
parser.add_argument('-w', '--webserver', action='store_true', default=False,
dest='webserver', help=_('run Glances in web server mode'))
# Other options

View File

@ -71,7 +71,7 @@ class monitorList:
countmin = self.config.get_raw_option(section, key + "countmin")
countmax = self.config.get_raw_option(section, key + "countmax")
except Exception as e:
print(_("Error reading monitored list: %s" % e))
print(_("Error: Cannot read monitored list: {0}").format(e))
pass
else:
if description is not None and regex is not None:
@ -130,7 +130,7 @@ class monitorList:
if self.command(i) is None:
# If there is no command specified in the conf file
# then display CPU and MEM %
self.__monitor_list[i]['result'] = "CPU: {0:.1f}% | MEM: {1:.1f}%".format(
self.__monitor_list[i]['result'] = 'CPU: {0:.1f}% | MEM: {1:.1f}%'.format(
sum([p['cpu_percent'] for p in monitoredlist]),
sum([p['memory_percent'] for p in monitoredlist]))
continue

View File

@ -108,12 +108,12 @@ class glancesPassword:
if os.path.exists(self.password_filepath) and not clear:
# If the password file exist then use it
sys.stdout.write(_("[Info] Read password from file %s\n") % self.password_filepath)
print(_("Info: Read password from file: {0}").format(self.password_filepath))
password = self.load_password()
else:
# Else enter the password from the command line
if description != '':
sys.stdout.write("%s\n" % description)
print(description)
# password_plain is the plain SHA-256 password
# password_hashed is the salt + SHA-256 password
@ -124,7 +124,7 @@ class glancesPassword:
password_confirm = hashlib.sha256(getpass.getpass(_("Password (confirm): ")).encode('utf-8')).hexdigest()
if not self.check_password(password_hashed, password_confirm):
sys.stdout.write(_("[Error] Sorry, but passwords did not match...\n"))
print(_("Error: Sorry, but passwords did not match..."))
sys.exit(1)
# Return the plain or hashed password
@ -151,7 +151,7 @@ class glancesPassword:
try:
os.makedirs(self.password_path)
except OSError as e:
print(_("[Warning] Cannot create Glances directory: {0}").format(e))
print(_("Warning: Cannot create Glances directory: {0}").format(e))
return
# Create/overwrite the password file

View File

@ -112,7 +112,7 @@ class GlancesXMLRPCServer(SimpleXMLRPCServer):
try:
self.address_family = socket.getaddrinfo(bind_address, bind_port)[0][0]
except socket.error as e:
print(_("Couldn't open socket: %s") % e)
print(_("Error: Couldn't open socket: {0}").format(e))
sys.exit(1)
SimpleXMLRPCServer.__init__(self, (bind_address, bind_port),
@ -201,8 +201,8 @@ class GlancesServer():
# Init the XML RPC server
try:
self.server = GlancesXMLRPCServer(args.bind_address, args.port, requestHandler)
except Exception as err:
print(_("Error: Cannot start Glances server (%s)") % err)
except Exception as e:
print(_("Error: Cannot start Glances server: {0}").format(e))
sys.exit(2)
# The users dict

View File

@ -45,7 +45,7 @@ class glancesCSV:
self.csv_file = open(self.csv_filename, 'wb')
self.writer = csv.writer(self.csv_file)
except IOError as e:
print(_("Cannot create the CSV file: {0}").format(e))
print(_("Error: Cannot create the CSV file: {0}").format(e))
sys.exit(2)
print(_("Stats dumped to CSV file: {0}").format(self.csv_filename))

View File

@ -75,29 +75,29 @@ class Plugin(GlancesPlugin):
# Build the string message
# Header
if self.stats == []:
msg = "{0}".format(_("No warning or critical alert detected"))
msg = _("No warning or critical alert detected")
ret.append(self.curse_add_line(msg, "TITLE"))
else:
# Header
msg = "{0}".format(_("Warning or critical alerts"))
msg = _("Warning or critical alerts")
ret.append(self.curse_add_line(msg, "TITLE"))
logs_len = glances_logs.len()
if logs_len > 1:
msg = " {0}".format(_("(lasts %s entries)") % logs_len)
msg = _(" (lasts {0} entries)").format(logs_len)
else:
msg = " {0}".format(_("(one entry)"))
msg = _(" (one entry)")
ret.append(self.curse_add_line(msg, "TITLE"))
# Loop over alerts
for alert in self.stats:
# New line
ret.append(self.curse_new_line())
# Start
msg = "{0}".format(datetime.fromtimestamp(alert[0]))
msg = str(datetime.fromtimestamp(alert[0]))
ret.append(self.curse_add_line(msg))
# Duration
if alert[1] > 0:
# If finished display duration
msg = " ({0})".format(datetime.fromtimestamp(alert[1]) - datetime.fromtimestamp(alert[0]))
msg = ' ({0})'.format(datetime.fromtimestamp(alert[1]) - datetime.fromtimestamp(alert[0]))
else:
msg = _(" (ongoing)")
ret.append(self.curse_add_line(msg))
@ -105,24 +105,24 @@ class Plugin(GlancesPlugin):
# Infos
if alert[1] > 0:
# If finished do not display status
msg = "{0} {1} {2}".format(alert[2], _("on"), alert[3])
msg = _("{0} on {1}").format(alert[2], alert[3])
ret.append(self.curse_add_line(msg))
else:
msg = "{0}".format(alert[3])
msg = str(alert[3])
ret.append(self.curse_add_line(msg, decoration=alert[2]))
# Min / Mean / Max
if alert[6] == alert[4]:
msg = " ({0:.1f})".format(alert[5])
msg = ' ({0:.1f})'.format(alert[5])
else:
msg = " (Min:{0:.1f} Mean:{1:.1f} Max:{2:.1f})".format(alert[6], alert[5], alert[4])
msg = _(" (Min:{0:.1f} Mean:{1:.1f} Max:{2:.1f})").format(alert[6], alert[5], alert[4])
ret.append(self.curse_add_line(msg))
# else:
# msg = " {0}".format(_("Running..."))
# msg = _(" Running...")
# ret.append(self.curse_add_line(msg))
# !!! Debug only
# msg = " | {0}".format(alert)
# msg = ' | {0}'.format(alert)
# ret.append(self.curse_add_line(msg))
return ret

View File

@ -120,58 +120,58 @@ class Plugin(GlancesPlugin):
# Build the string message
# Header
msg = "{0:8}".format(_("CPU"))
msg = '{0:8}'.format(_("CPU"))
ret.append(self.curse_add_line(msg, "TITLE"))
# Total CPU usage
msg = "{0:>6.1%}".format((100 - self.stats['idle']) / 100)
msg = '{0:>6.1%}'.format((100 - self.stats['idle']) / 100)
ret.append(self.curse_add_line(msg))
# Nice CPU
if 'nice' in self.stats:
msg = " {0:8}".format(_("nice:"))
msg = ' {0:8}'.format(_("nice:"))
ret.append(self.curse_add_line(msg))
msg = "{0:>6.1%}".format(self.stats['nice'] / 100)
msg = '{0:>6.1%}'.format(self.stats['nice'] / 100)
ret.append(self.curse_add_line(msg, optional=True))
# New line
ret.append(self.curse_new_line())
# User CPU
if 'user' in self.stats:
msg = "{0:8}".format(_("user:"))
msg = '{0:8}'.format(_("user:"))
ret.append(self.curse_add_line(msg))
msg = "{0:>6.1%}".format(self.stats['user'] / 100)
msg = '{0:>6.1%}'.format(self.stats['user'] / 100)
ret.append(self.curse_add_line(msg, self.get_alert_log(self.stats['user'], header="user")))
# IRQ CPU
if 'irq' in self.stats:
msg = " {0:8}".format(_("irq:"))
msg = ' {0:8}'.format(_("irq:"))
ret.append(self.curse_add_line(msg, optional=True))
msg = "{0:>6.1%}".format(self.stats['irq'] / 100)
msg = '{0:>6.1%}'.format(self.stats['irq'] / 100)
ret.append(self.curse_add_line(msg, optional=True))
# New line
ret.append(self.curse_new_line())
# System CPU
if 'system' in self.stats:
msg = "{0:8}".format(_("system:"))
msg = '{0:8}'.format(_("system:"))
ret.append(self.curse_add_line(msg))
msg = "{0:>6.1%}".format(self.stats['system'] / 100)
msg = '{0:>6.1%}'.format(self.stats['system'] / 100)
ret.append(self.curse_add_line(msg, self.get_alert_log(self.stats['system'], header="system")))
# IOWait CPU
if 'iowait' in self.stats:
msg = " {0:8}".format(_("iowait:"))
msg = ' {0:8}'.format(_("iowait:"))
ret.append(self.curse_add_line(msg, optional=True))
msg = "{0:>6.1%}".format(self.stats['iowait'] / 100)
msg = '{0:>6.1%}'.format(self.stats['iowait'] / 100)
ret.append(self.curse_add_line(msg, self.get_alert_log(self.stats['iowait'], header="iowait"), optional=True))
# New line
ret.append(self.curse_new_line())
# Idle CPU
if 'idle' in self.stats:
msg = "{0:8}".format(_("idle:"))
msg = '{0:8}'.format(_("idle:"))
ret.append(self.curse_add_line(msg))
msg = "{0:>6.1%}".format(self.stats['idle'] / 100)
msg = '{0:>6.1%}'.format(self.stats['idle'] / 100)
ret.append(self.curse_add_line(msg))
# Steal CPU usage
if 'steal' in self.stats:
msg = " {0:8}".format(_("steal:"))
msg = ' {0:8}'.format(_("steal:"))
ret.append(self.curse_add_line(msg, optional=True))
msg = "{0:>6.1%}".format(self.stats['steal'] / 100)
msg = '{0:>6.1%}'.format(self.stats['steal'] / 100)
ret.append(self.curse_add_line(msg, self.get_alert(self.stats['steal'], header="steal"), optional=True))
# Return the message with decoration

View File

@ -131,11 +131,11 @@ class Plugin(GlancesPlugin):
# Build the string message
# Header
msg = "{0:9}".format(_("DISK I/O"))
msg = '{0:9}'.format(_("DISK I/O"))
ret.append(self.curse_add_line(msg, "TITLE"))
msg = "{0:>7}".format(_("R/s"))
msg = '{0:>7}'.format(_("R/s"))
ret.append(self.curse_add_line(msg))
msg = "{0:>7}".format(_("W/s"))
msg = '{0:>7}'.format(_("W/s"))
ret.append(self.curse_add_line(msg))
# Disk list (sorted by name)
for i in sorted(self.stats, key=lambda diskio: diskio['disk_name']):
@ -149,13 +149,13 @@ class Plugin(GlancesPlugin):
disk_name = '_' + i['disk_name'][-8:]
else:
disk_name = i['disk_name']
msg = "{0:9}".format(disk_name)
msg = '{0:9}'.format(disk_name)
ret.append(self.curse_add_line(msg))
txps = self.auto_unit(int(i['read_bytes'] // i['time_since_update']))
rxps = self.auto_unit(int(i['write_bytes'] // i['time_since_update']))
msg = "{0:>7}".format(txps)
msg = '{0:>7}'.format(txps)
ret.append(self.curse_add_line(msg))
msg = "{0:>7}".format(rxps)
msg = '{0:>7}'.format(rxps)
ret.append(self.curse_add_line(msg))
return ret

View File

@ -139,11 +139,11 @@ class Plugin(GlancesPlugin):
# Build the string message
# Header
msg = "{0:9}".format(_("FILE SYS"))
msg = '{0:9}'.format(_("FILE SYS"))
ret.append(self.curse_add_line(msg, "TITLE"))
msg = "{0:>7}".format(_("Used"))
msg = '{0:>7}'.format(_("Used"))
ret.append(self.curse_add_line(msg))
msg = "{0:>7}".format(_("Total"))
msg = '{0:>7}'.format(_("Total"))
ret.append(self.curse_add_line(msg))
# Disk list (sorted by name)
@ -158,11 +158,11 @@ class Plugin(GlancesPlugin):
mnt_point = '_' + i['mnt_point'][-8:]
else:
mnt_point = i['mnt_point']
msg = "{0:9}".format(mnt_point)
msg = '{0:9}'.format(mnt_point)
ret.append(self.curse_add_line(msg))
msg = "{0:>7}".format(self.auto_unit(i['used']))
msg = '{0:>7}'.format(self.auto_unit(i['used']))
ret.append(self.curse_add_line(msg, self.get_alert(i['used'], max=i['size'])))
msg = "{0:>7}".format(self.auto_unit(i['size']))
msg = '{0:>7}'.format(self.auto_unit(i['size']))
ret.append(self.curse_add_line(msg))
return ret

View File

@ -63,15 +63,15 @@ class Plugin(GlancesPlugin):
# Build the string message
# Header
msg = "{0} {1}".format(__appname__.title(), __version__)
msg = '{0} {1}'.format(__appname__.title(), __version__)
ret.append(self.curse_add_line(msg, "TITLE"))
msg = " {0} {1}".format(_("with psutil"), __psutil_version__)
msg = _(" with psutil {0}").format(__psutil_version__)
ret.append(self.curse_add_line(msg))
ret.append(self.curse_new_line())
# Keys
msg_col = "{0:1} {1:>35}"
msg_col2 = " {0:1} {1:>35}"
msg_col = '{0:1} {1:>35}'
msg_col2 = ' {0:1} {1:>35}'
ret.append(self.curse_new_line())
msg = msg_col.format(_("a"), _("Sort processes automatically"))

View File

@ -120,33 +120,33 @@ class Plugin(GlancesPlugin):
# Build the string message
# Header
msg = "{0:8}".format(_("LOAD"))
msg = '{0:8}'.format(_("LOAD"))
ret.append(self.curse_add_line(msg, "TITLE"))
# Core number
if self.stats['cpucore'] > 0:
msg = _("{0:>1}-core").format(self.stats['cpucore'])
msg = _("{0}-core").format(self.stats['cpucore'], '>1')
ret.append(self.curse_add_line(msg))
# New line
ret.append(self.curse_new_line())
# 1min load
msg = "{0:8}".format(_("1 min:"))
msg = '{0:8}'.format(_("1 min:"))
ret.append(self.curse_add_line(msg))
msg = "{0:>6.2f}".format(self.stats['min1'])
msg = '{0:>6.2f}'.format(self.stats['min1'])
ret.append(self.curse_add_line(msg))
# New line
ret.append(self.curse_new_line())
# 5min load
msg = "{0:8}".format(_("5 min:"))
msg = '{0:8}'.format(_("5 min:"))
ret.append(self.curse_add_line(msg))
msg = "{0:>6.2f}".format(self.stats['min5'])
msg = '{0:>6.2f}'.format(self.stats['min5'])
ret.append(self.curse_add_line(
msg, self.get_alert(self.stats['min5'], max=100 * self.stats['cpucore'])))
# New line
ret.append(self.curse_new_line())
# 15min load
msg = "{0:8}".format(_("15 min:"))
msg = '{0:8}'.format(_("15 min:"))
ret.append(self.curse_add_line(msg))
msg = "{0:>6.2f}".format(self.stats['min15'])
msg = '{0:>6.2f}'.format(self.stats['min15'])
ret.append(self.curse_add_line(
msg, self.get_alert_log(self.stats['min15'], max=100 * self.stats['cpucore'])))

View File

@ -145,56 +145,56 @@ class Plugin(GlancesPlugin):
# Build the string message
# Header
msg = "{0:5} ".format(_("MEM"))
msg = '{0:5} '.format(_("MEM"))
ret.append(self.curse_add_line(msg, "TITLE"))
# Percent memory usage
msg = "{0:>7.1%}".format(self.stats['percent'] / 100)
msg = '{0:>7.1%}'.format(self.stats['percent'] / 100)
ret.append(self.curse_add_line(msg))
# Active memory usage
if 'active' in self.stats:
msg = " {0:9}".format(_("active:"))
msg = ' {0:9}'.format(_("active:"))
ret.append(self.curse_add_line(msg, optional=True))
msg = "{0:>7}".format(self.auto_unit(self.stats['active']))
msg = '{0:>7}'.format(self.auto_unit(self.stats['active']))
ret.append(self.curse_add_line(msg, optional=True))
# New line
ret.append(self.curse_new_line())
# Total memory usage
msg = "{0:6}".format(_("total:"))
msg = '{0:6}'.format(_("total:"))
ret.append(self.curse_add_line(msg))
msg = "{0:>7}".format(self.auto_unit(self.stats['total']))
msg = '{0:>7}'.format(self.auto_unit(self.stats['total']))
ret.append(self.curse_add_line(msg))
# Inactive memory usage
if 'inactive' in self.stats:
msg = " {0:9}".format(_("inactive:"))
msg = ' {0:9}'.format(_("inactive:"))
ret.append(self.curse_add_line(msg, optional=True))
msg = "{0:>7}".format(self.auto_unit(self.stats['inactive']))
msg = '{0:>7}'.format(self.auto_unit(self.stats['inactive']))
ret.append(self.curse_add_line(msg, optional=True))
# New line
ret.append(self.curse_new_line())
# Used memory usage
msg = "{0:6}".format(_("used:"))
msg = '{0:6}'.format(_("used:"))
ret.append(self.curse_add_line(msg))
msg = "{0:>7}".format(self.auto_unit(self.stats['used']))
msg = '{0:>7}'.format(self.auto_unit(self.stats['used']))
ret.append(self.curse_add_line(
msg, self.get_alert_log(self.stats['used'], max=self.stats['total'])))
# Buffers memory usage
if 'buffers' in self.stats:
msg = " {0:9}".format(_("buffers:"))
msg = ' {0:9}'.format(_("buffers:"))
ret.append(self.curse_add_line(msg, optional=True))
msg = "{0:>7}".format(self.auto_unit(self.stats['buffers']))
msg = '{0:>7}'.format(self.auto_unit(self.stats['buffers']))
ret.append(self.curse_add_line(msg, optional=True))
# New line
ret.append(self.curse_new_line())
# Free memory usage
msg = "{0:6}".format(_("free:"))
msg = '{0:6}'.format(_("free:"))
ret.append(self.curse_add_line(msg))
msg = "{0:>7}".format(self.auto_unit(self.stats['free']))
msg = '{0:>7}'.format(self.auto_unit(self.stats['free']))
ret.append(self.curse_add_line(msg))
# Cached memory usage
if 'cached' in self.stats:
msg = " {0:9}".format(_("cached:"))
msg = ' {0:9}'.format(_("cached:"))
ret.append(self.curse_add_line(msg, optional=True))
msg = "{0:>7}".format(self.auto_unit(self.stats['cached']))
msg = '{0:>7}'.format(self.auto_unit(self.stats['cached']))
ret.append(self.curse_add_line(msg, optional=True))
return ret

View File

@ -116,32 +116,32 @@ class Plugin(GlancesPlugin):
# Build the string message
# Header
msg = "{0:7} ".format(_("SWAP"))
msg = '{0:7} '.format(_("SWAP"))
ret.append(self.curse_add_line(msg, "TITLE"))
# Percent memory usage
msg = "{0:>6.1%}".format(self.stats['percent'] / 100)
msg = '{0:>6.1%}'.format(self.stats['percent'] / 100)
ret.append(self.curse_add_line(msg))
# New line
ret.append(self.curse_new_line())
# Total memory usage
msg = "{0:8}".format(_("total:"))
msg = '{0:8}'.format(_("total:"))
ret.append(self.curse_add_line(msg))
msg = "{0:>6}".format(self.auto_unit(self.stats['total']))
msg = '{0:>6}'.format(self.auto_unit(self.stats['total']))
ret.append(self.curse_add_line(msg))
# New line
ret.append(self.curse_new_line())
# Used memory usage
msg = "{0:8}".format(_("used:"))
msg = '{0:8}'.format(_("used:"))
ret.append(self.curse_add_line(msg))
msg = "{0:>6}".format(self.auto_unit(self.stats['used']))
msg = '{0:>6}'.format(self.auto_unit(self.stats['used']))
ret.append(self.curse_add_line(
msg, self.get_alert_log(self.stats['used'], max=self.stats['total'])))
# New line
ret.append(self.curse_new_line())
# Free memory usage
msg = "{0:8}".format(_("free:"))
msg = '{0:8}'.format(_("free:"))
ret.append(self.curse_add_line(msg))
msg = "{0:>6}".format(self.auto_unit(self.stats['free']))
msg = '{0:>6}'.format(self.auto_unit(self.stats['free']))
ret.append(self.curse_add_line(msg))
return ret

View File

@ -103,22 +103,21 @@ class Plugin(GlancesPlugin):
# Build the string message
for m in self.stats:
msg = "{0:<16} ".format(str(m['description']))
msg = '{0:<16} '.format(m['description'])
ret.append(self.curse_add_line(
msg, self.get_alert(m['count'], m['countmin'], m['countmax'])))
msg = "{0:<3} ".format(m['count'] if m['count'] > 1 else "")
msg = '{0:<3} '.format(m['count'] if m['count'] > 1 else '')
ret.append(self.curse_add_line(msg))
msg = "{0:13} ".format(_("RUNNING") if m['count'] >= 1 else _("NOT RUNNING"))
msg = '{0:13} '.format(_("RUNNING") if m['count'] >= 1 else _("NOT RUNNING"))
ret.append(self.curse_add_line(msg))
# Decode to UTF8 (only for Python 3)
try:
msg = "{0}".format(m['result'].decode('utf-8') if m['count'] >= 1 else "")
msg = m['result'].decode('utf-8') if m['count'] >= 1 else ''
except (UnicodeError, AttributeError):
try:
msg = "{0}".format(m['result'] if m['count'] >= 1 else "")
msg = m['result'] if m['count'] >= 1 else ''
except UnicodeError:
msg = "{0}".format(m['result'].encode('utf-8') if m['count'] >= 1 else "")
msg = m['result'].encode('utf-8') if m['count'] >= 1 else ''
ret.append(self.curse_add_line(msg, optional=True, splittable=True))
ret.append(self.curse_new_line())

View File

@ -180,30 +180,30 @@ class Plugin(GlancesPlugin):
# Build the string message
# Header
msg = "{0:9}".format(_("NETWORK"))
msg = '{0:9}'.format(_("NETWORK"))
ret.append(self.curse_add_line(msg, "TITLE"))
if args.network_cumul:
# Cumulative stats
if args.network_sum:
# Sum stats
msg = "{0:>14}".format(_("Rx+Tx"))
msg = '{0:>14}'.format(_("Rx+Tx"))
ret.append(self.curse_add_line(msg))
else:
# Rx/Tx stats
msg = "{0:>7}".format(_("Rx"))
msg = '{0:>7}'.format(_("Rx"))
ret.append(self.curse_add_line(msg))
msg = "{0:>7}".format(_("Tx"))
msg = '{0:>7}'.format(_("Tx"))
ret.append(self.curse_add_line(msg))
else:
# Bitrate stats
if args.network_sum:
# Sum stats
msg = "{0:>14}".format(_("Rx+Tx/s"))
msg = '{0:>14}'.format(_("Rx+Tx/s"))
ret.append(self.curse_add_line(msg))
else:
msg = "{0:>7}".format(_("Rx/s"))
msg = '{0:>7}'.format(_("Rx/s"))
ret.append(self.curse_add_line(msg))
msg = "{0:>7}".format(_("Tx/s"))
msg = '{0:>7}'.format(_("Tx/s"))
ret.append(self.curse_add_line(msg))
# Interface list (sorted by name)
for i in sorted(self.stats, key=lambda network: network['interface_name']):
@ -241,17 +241,17 @@ class Plugin(GlancesPlugin):
int(i['tx'] // i['time_since_update'] * 8)) + "b"
# New line
ret.append(self.curse_new_line())
msg = "{0:9}".format(ifname)
msg = '{0:9}'.format(ifname)
ret.append(self.curse_add_line(msg))
if args.network_sum:
msg = "{0:>14}".format(sx)
msg = '{0:>14}'.format(sx)
ret.append(self.curse_add_line(msg))
else:
msg = "{0:>7}".format(rx)
msg = '{0:>7}'.format(rx)
ret.append(self.curse_add_line(
msg, self.get_alert(int(i['rx'] // i['time_since_update'] * 8),
header=ifname + '_rx')))
msg = "{0:>7}".format(tx)
msg = '{0:>7}'.format(tx)
ret.append(self.curse_add_line(
msg, self.get_alert(int(i['tx'] // i['time_since_update'] * 8),
header=ifname + '_tx')))

View File

@ -153,42 +153,42 @@ class Plugin(GlancesPlugin):
# Build the string message
# Header
msg = "{0:8}".format(_("PER CPU"))
msg = '{0:8}'.format(_("PER CPU"))
ret.append(self.curse_add_line(msg, "TITLE"))
# Total CPU usage
for cpu in self.stats:
msg = " {0:>6.1%}".format((100 - cpu['idle']) / 100)
msg = ' {0:>6.1%}'.format((100 - cpu['idle']) / 100)
ret.append(self.curse_add_line(msg))
# User CPU
if 'user' in self.stats[0]:
# New line
ret.append(self.curse_new_line())
msg = "{0:8}".format(_("user:"))
msg = '{0:8}'.format(_("user:"))
ret.append(self.curse_add_line(msg))
for cpu in self.stats:
msg = " {0:>6.1%}".format(cpu['user'] / 100)
msg = ' {0:>6.1%}'.format(cpu['user'] / 100)
ret.append(self.curse_add_line(msg, self.get_alert(cpu['user'], header="user")))
# System CPU
if 'user' in self.stats[0]:
# New line
ret.append(self.curse_new_line())
msg = "{0:8}".format(_("system:"))
msg = '{0:8}'.format(_("system:"))
ret.append(self.curse_add_line(msg))
for cpu in self.stats:
msg = " {0:>6.1%}".format(cpu['system'] / 100)
msg = ' {0:>6.1%}'.format(cpu['system'] / 100)
ret.append(self.curse_add_line(msg, self.get_alert(cpu['system'], header="system")))
# IoWait CPU
if 'user' in self.stats[0]:
# New line
ret.append(self.curse_new_line())
msg = "{0:8}".format(_("iowait:"))
msg = '{0:8}'.format(_("iowait:"))
ret.append(self.curse_add_line(msg))
for cpu in self.stats:
msg = " {0:>6.1%}".format(cpu['iowait'] / 100)
msg = ' {0:>6.1%}'.format(cpu['iowait'] / 100)
ret.append(self.curse_add_line(msg, self.get_alert(cpu['iowait'], header="iowait")))
# Return the message with decoration

View File

@ -311,9 +311,9 @@ class GlancesPlugin(object):
"""
return self.curse_add_line('\n')
def auto_unit(self, val, low_precision=False):
def auto_unit(self, number, low_precision=False):
"""
Make a nice human readable string out of val
Make a nice human readable string out of number
Number of decimal places increases as quantity approaches 1
examples:
@ -340,21 +340,21 @@ class GlancesPlugin(object):
'K': 1024
}
for key in reversed(symbols):
value = float(val) / prefix[key]
for symbol in reversed(symbols):
value = float(number) / prefix[symbol]
if value > 1:
fixed_decimal_places = 0
decimal_precision = 0
if value < 10:
fixed_decimal_places = 2
decimal_precision = 2
elif value < 100:
fixed_decimal_places = 1
decimal_precision = 1
if low_precision:
if key in 'MK':
fixed_decimal_places = 0
if symbol in 'MK':
decimal_precision = 0
else:
fixed_decimal_places = min(1, fixed_decimal_places)
elif key in 'K':
fixed_decimal_places = 0
formatter = "{0:.%df}{1}" % fixed_decimal_places
return formatter.format(value, key)
return "{0!s}".format(val)
decimal_precision = min(1, decimal_precision)
elif symbol in 'K':
decimal_precision = 0
return '{0:.{decimal}f}{symbol}'.format(
value, decimal=decimal_precision, symbol=symbol)
return '{0!s}'.format(number)

View File

@ -84,7 +84,7 @@ class Plugin(GlancesPlugin):
# return ret
if args.disable_process:
msg = "{0} ".format(_("PROCESSES DISABLED (press 'z' to display)"))
msg = _("PROCESSES DISABLED (press 'z' to display)")
ret.append(self.curse_add_line(msg))
return ret
@ -93,28 +93,28 @@ class Plugin(GlancesPlugin):
# Build the string message
# Header
msg = "{0} ".format(_("TASKS"))
msg = _("TASKS ")
ret.append(self.curse_add_line(msg, "TITLE"))
# Compute processes
other = self.stats['total']
msg = "{0}".format(str(self.stats['total']))
msg = str(self.stats['total'])
ret.append(self.curse_add_line(msg))
if 'thread' in self.stats:
msg = " ({0} {1}),".format(str(self.stats['thread']), _("thr"))
msg = _(" ({0} thr),").format(self.stats['thread'])
ret.append(self.curse_add_line(msg))
if 'running' in self.stats:
other -= self.stats['running']
msg = " {0} {1},".format(str(self.stats['running']), _("run"))
msg = _(" {0} run,").format(self.stats['running'])
ret.append(self.curse_add_line(msg))
if 'sleeping' in self.stats:
other -= self.stats['sleeping']
msg = " {0} {1},".format(str(self.stats['sleeping']), _("slp"))
msg = _(" {0} slp,").format(self.stats['sleeping'])
ret.append(self.curse_add_line(msg))
msg = " {0} {1} ".format(str(other), _("oth"))
msg = _(" {0} oth ").format(other)
ret.append(self.curse_add_line(msg))
# Display sort information
@ -123,12 +123,12 @@ class Plugin(GlancesPlugin):
except AttributeError:
args.process_sorted_by = glances_processes.getsortkey()
if args.process_sorted_by == 'auto':
msg = "{0}".format(_("sorted automatically"))
msg = _("sorted automatically")
ret.append(self.curse_add_line(msg))
msg = " {0} {1}".format(_("by"), glances_processes.getsortkey())
msg = _(" by {0}").format(glances_processes.getsortkey())
ret.append(self.curse_add_line(msg))
else:
msg = "{0} {1}".format(_("sorted by"), args.process_sorted_by)
msg = _("sorted by {0}").format(args.process_sorted_by)
ret.append(self.curse_add_line(msg))
# Return the message with decoration

View File

@ -97,29 +97,29 @@ class Plugin(GlancesPlugin):
sort_style = 'SORT'
# Header
msg = "{0:>6}".format(_("CPU%"))
msg = '{0:>6}'.format(_("CPU%"))
ret.append(self.curse_add_line(msg, sort_style if process_sort_key == 'cpu_percent' else 'DEFAULT'))
msg = "{0:>6}".format(_("MEM%"))
msg = '{0:>6}'.format(_("MEM%"))
ret.append(self.curse_add_line(msg, sort_style if process_sort_key == 'memory_percent' else 'DEFAULT'))
msg = "{0:>6}".format(_("VIRT"))
msg = '{0:>6}'.format(_("VIRT"))
ret.append(self.curse_add_line(msg, optional=True))
msg = "{0:>6}".format(_("RES"))
msg = '{0:>6}'.format(_("RES"))
ret.append(self.curse_add_line(msg, optional=True))
msg = "{0:>6}".format(_("PID"))
msg = '{0:>6}'.format(_("PID"))
ret.append(self.curse_add_line(msg))
msg = " {0:10}".format(_("USER"))
msg = ' {0:10}'.format(_("USER"))
ret.append(self.curse_add_line(msg))
msg = "{0:>4}".format(_("NI"))
msg = '{0:>4}'.format(_("NI"))
ret.append(self.curse_add_line(msg))
msg = "{0:>2}".format(_("S"))
msg = '{0:>2}'.format(_("S"))
ret.append(self.curse_add_line(msg))
msg = "{0:>9}".format(_("TIME+"))
msg = '{0:>9}'.format(_("TIME+"))
ret.append(self.curse_add_line(msg, optional=True))
msg = "{0:>6}".format(_("IOR/s"))
msg = '{0:>6}'.format(_("IOR/s"))
ret.append(self.curse_add_line(msg, sort_style if process_sort_key == 'io_counters' else 'DEFAULT', optional=True))
msg = "{0:>6}".format(_("IOW/s"))
msg = '{0:>6}'.format(_("IOW/s"))
ret.append(self.curse_add_line(msg, sort_style if process_sort_key == 'io_counters' else 'DEFAULT', optional=True))
msg = " {0:8}".format(_("Command"))
msg = ' {0:8}'.format(_("Command"))
ret.append(self.curse_add_line(msg))
# Trying to display proc time
@ -129,35 +129,35 @@ class Plugin(GlancesPlugin):
for p in self.sortlist(process_sort_key):
ret.append(self.curse_new_line())
# CPU
msg = "{0:>6.1f}".format(p['cpu_percent'])
msg = '{0:>6.1f}'.format(p['cpu_percent'])
ret.append(self.curse_add_line(msg,
self.get_alert(p['cpu_percent'], header="cpu")))
# MEM
msg = "{0:>6.1f}".format(p['memory_percent'])
msg = '{0:>6.1f}'.format(p['memory_percent'])
ret.append(self.curse_add_line(msg,
self.get_alert(p['memory_percent'], header="mem")))
# VMS
msg = "{0:>6}".format(self.auto_unit(p['memory_info'][1], low_precision=False))
msg = '{0:>6}'.format(self.auto_unit(p['memory_info'][1], low_precision=False))
ret.append(self.curse_add_line(msg, optional=True))
# RSS
msg = "{0:>6}".format(self.auto_unit(p['memory_info'][0], low_precision=False))
msg = '{0:>6}'.format(self.auto_unit(p['memory_info'][0], low_precision=False))
ret.append(self.curse_add_line(msg, optional=True))
# PID
msg = "{0:>6}".format(p['pid'])
msg = '{0:>6}'.format(p['pid'])
ret.append(self.curse_add_line(msg))
# USER
msg = " {0:9}".format(p['username'][:9])
msg = ' {0:9}'.format(p['username'][:9])
ret.append(self.curse_add_line(msg))
# NICE
nice = p['nice']
msg = "{0:>5}".format(nice)
msg = '{0:>5}'.format(nice)
if nice != 0:
ret.append(self.curse_add_line(msg, decoration='NICE'))
else:
ret.append(self.curse_add_line(msg))
# STATUS
status = p['status']
msg = "{0:>2}".format(status)
msg = '{0:>2}'.format(status)
if status == 'R':
ret.append(self.curse_add_line(msg, decoration='STATUS'))
else:
@ -171,31 +171,31 @@ class Plugin(GlancesPlugin):
# See https://github.com/nicolargo/glances/issues/87
tag_proc_time = False
else:
msg = "{0}:{1}.{2}".format(str(dtime.seconds // 60 % 60),
msg = '{0}:{1}.{2}'.format(str(dtime.seconds // 60 % 60),
str(dtime.seconds % 60).zfill(2),
str(dtime.microseconds)[:2].zfill(2))
else:
msg = " "
msg = "{0:>9}".format(msg)
msg = ' '
msg = '{0:>9}'.format(msg)
ret.append(self.curse_add_line(msg, optional=True))
# IO read/write
if 'io_counters' in p:
# IO read
io_rs = (p['io_counters'][0] - p['io_counters'][2]) / p['time_since_update']
if io_rs == 0:
msg = "{0:>6}".format("0")
msg = '{0:>6}'.format("0")
else:
msg = "{0:>6}".format(self.auto_unit(io_rs, low_precision=False))
msg = '{0:>6}'.format(self.auto_unit(io_rs, low_precision=False))
ret.append(self.curse_add_line(msg, optional=True))
# IO write
io_ws = (p['io_counters'][1] - p['io_counters'][3]) / p['time_since_update']
if io_ws == 0:
msg = "{0:>6}".format("0")
msg = '{0:>6}'.format("0")
else:
msg = "{0:>6}".format(self.auto_unit(io_ws, low_precision=False))
msg = '{0:>6}'.format(self.auto_unit(io_ws, low_precision=False))
ret.append(self.curse_add_line(msg, optional=True))
else:
msg = "{0:>6}".format("?")
msg = '{0:>6}'.format("?")
ret.append(self.curse_add_line(msg, optional=True))
ret.append(self.curse_add_line(msg, optional=True))
# Command line
@ -203,7 +203,7 @@ class Plugin(GlancesPlugin):
# the bare process name instead
cmdline = p['cmdline']
if cmdline == "":
msg = " {0}".format(p['name'])
msg = ' {0}'.format(p['name'])
ret.append(self.curse_add_line(msg, splittable=True))
else:
try:
@ -211,11 +211,11 @@ class Plugin(GlancesPlugin):
args = ' '.join(cmdline.split()[1:])
path, basename = os.path.split(cmd)
if os.path.isdir(path):
msg = " {0}".format(path) + os.sep
msg = ' {0}'.format(path) + os.sep
ret.append(self.curse_add_line(msg, splittable=True))
ret.append(self.curse_add_line(basename, decoration='PROCESS', splittable=True))
else:
msg = " {0}".format(basename)
msg = ' {0}'.format(basename)
ret.append(self.curse_add_line(msg, decoration='PROCESS', splittable=True))
msg = " {0}".format(args)
ret.append(self.curse_add_line(msg, splittable=True))

View File

@ -118,20 +118,20 @@ class Plugin(GlancesPlugin):
# Build the string message
# Header
msg = "{0:18}".format(_("SENSORS"))
msg = '{0:18}'.format(_("SENSORS"))
ret.append(self.curse_add_line(msg, "TITLE"))
if is_py3:
msg = "{0:>5}".format(_("°C"))
msg = '{0:>5}'.format(_("°C"))
else:
msg = "{0:>6}".format(_("°C"))
msg = '{0:>6}'.format(_("°C"))
ret.append(self.curse_add_line(msg))
for item in self.stats:
# New line
ret.append(self.curse_new_line())
msg = "{0:18}".format(item['label'][:18])
msg = '{0:18}'.format(item['label'][:18])
ret.append(self.curse_add_line(msg))
msg = "{0:>5}".format(item['value'])
msg = '{0:>5}'.format(item['value'])
if item['type'] == 'battery':
try:
ret.append(self.curse_add_line(msg, self.get_alert(100 - item['value'], header=item['type'])))

View File

@ -122,17 +122,17 @@ class Plugin(GlancesPlugin):
ret.append(self.curse_add_line(msg, "TITLE"))
# System info
if self.stats['os_name'] == "Linux":
msg = " ({0} {1} / {2} {3})".format(self.stats['linux_distro'],
msg = ' ({0} {1} / {2} {3})'.format(self.stats['linux_distro'],
self.stats['platform'],
self.stats['os_name'],
self.stats['os_version'])
else:
try:
msg = " ({0} {1} {2})".format(self.stats['os_name'],
msg = ' ({0} {1} {2})'.format(self.stats['os_name'],
self.stats['os_version'],
self.stats['platform'])
except:
msg = " ({0})".format(self.stats['os_name'])
msg = ' ({0})'.format(self.stats['os_name'])
ret.append(self.curse_add_line(msg, optional=True))
# Return the message with decoration