glances: cleanup end of line whitespace

there were a lot of lines with end of line whitespace. Clean it all up.
pull/130/head
Brandon Philips 2012-11-28 21:22:11 -08:00
parent d04b03036e
commit 4d472ac771
2 changed files with 106 additions and 106 deletions

View File

@ -106,7 +106,7 @@ else:
try:
# virtual_memory() is only available with PsUtil 0.6+
psutil.virtual_memory()
except:
except:
try:
# (phy|virt)mem_usage methods only available with PsUtil 0.3.0+
psutil.phymem_usage()
@ -283,7 +283,7 @@ class glancesLogs:
Else:
Update the existing item
"""
# Add Top process sort depending on alert type
if (item_type.startswith("MEM")):
# MEM
@ -484,7 +484,7 @@ class glancesStats:
self.glancesgrabfs = glancesGrabFs()
except Exception:
self.glancesgrabfs = {}
# Init the sensors stats (optionnal)
if sensors_tag:
try:
@ -494,12 +494,12 @@ class glancesStats:
# Process list refresh
self.process_list_refresh = True
# Init the all_stats used by the server
# all_stats is a dict of dicts filled by the server
if (self.server_tag):
self.all_stats = collections.defaultdict(dict)
# Cached informations (no need to be refreshed)
# Host and OS informations
if (not self.client_tag):
@ -531,28 +531,28 @@ class glancesStats:
"""
Get process (proc) statistics
!!! No performance gap (CPU %)
!!! Without: 1.5 - 2.0
!!! Without: 1.5 - 2.0
!!! With: 2.0 - 2.2
"""
procstat = proc.as_dict(['get_memory_info', 'get_cpu_percent', 'get_memory_percent',
'pid', 'username', 'get_nice',
'get_cpu_times', 'name', 'status', 'cmdline'])
if psutil_get_io_counter_tag:
procstat['io_counters'] = proc.get_io_counters()
procstat['io_counters'] = proc.get_io_counters()
procstat['status'] = str(procstat['status'])[:1].upper()
procstat['cmdline'] = " ".join(procstat['cmdline'])
return procstat
def __get_process_stats__(self, proc):
"""
Get process (proc) statistics
"""
procstat = {}
procstat['memory_info'] = proc.get_memory_info()
if psutil_get_cpu_percent_tag:
procstat['cpu_percent'] = \
proc.get_cpu_percent(interval=0)
@ -582,7 +582,7 @@ class glancesStats:
procstat['cpu_times'] = proc.get_cpu_times()
procstat['name'] = proc.name
procstat['cmdline'] = " ".join(proc.cmdline)
return procstat
@ -602,7 +602,7 @@ class glancesStats:
if input_stats != {}:
self.cpu = input_stats["cpu"]
else:
if not hasattr(self, 'cputime_old'):
if not hasattr(self, 'cputime_old'):
self.cputime_old = psutil.cpu_times()
self.cputime_total_old = (self.cputime_old.user +
self.cputime_old.system +
@ -664,10 +664,10 @@ class glancesStats:
if input_stats != {}:
self.percpu = input_stats["percpu"]
else:
if not hasattr(self, 'percputime_old'):
if not hasattr(self, 'percputime_old'):
self.percputime_old = psutil.cpu_times(percpu = True)
self.percputime_total_old = []
for i in range(len(self.percputime_old)):
for i in range(len(self.percputime_old)):
self.percputime_total_old.append(self.percputime_old[i].user +
self.percputime_old[i].system +
self.percputime_old[i].idle)
@ -675,13 +675,13 @@ class glancesStats:
for i in range(len(self.percputime_old)):
if hasattr(self.percputime_old[i], 'nice'):
self.percputime_total_old[i] += self.percputime_old[i].nice
for i in range(len(self.percputime_old)):
for i in range(len(self.percputime_old)):
if hasattr(self.percputime_old[i], 'iowait'):
self.percputime_total_old[i] += self.percputime_old[i].iowait
for i in range(len(self.percputime_old)):
for i in range(len(self.percputime_old)):
if hasattr(self.percputime_old[i], 'irq'):
self.percputime_total_old[i] += self.percputime_old[i].irq
for i in range(len(self.percputime_old)):
for i in range(len(self.percputime_old)):
if hasattr(self.percputime_old[i], 'softirq'):
self.percputime_total_old[i] += self.percputime_old[i].softirq
self.percpu = []
@ -689,26 +689,26 @@ class glancesStats:
try:
self.percputime_new = psutil.cpu_times(percpu = True)
self.percputime_total_new = []
for i in range(len(self.percputime_new)):
for i in range(len(self.percputime_new)):
self.percputime_total_new.append(self.percputime_new[i].user +
self.percputime_new[i].system +
self.percputime_new[i].idle)
self.percputime_new[i].idle)
# Only available on some OS
for i in range(len(self.percputime_new)):
if hasattr(self.percputime_new[i], 'nice'):
if hasattr(self.percputime_new[i], 'nice'):
self.percputime_total_new[i] += self.percputime_new[i].nice
for i in range(len(self.percputime_new)):
if hasattr(self.percputime_new[i], 'iowait'):
for i in range(len(self.percputime_new)):
if hasattr(self.percputime_new[i], 'iowait'):
self.percputime_total_new[i] += self.percputime_new[i].iowait
for i in range(len(self.percputime_new)):
if hasattr(self.percputime_new[i], 'irq'):
for i in range(len(self.percputime_new)):
if hasattr(self.percputime_new[i], 'irq'):
self.percputime_total_new[i] += self.percputime_new[i].irq
for i in range(len(self.percputime_new)):
if hasattr(self.percputime_new[i], 'softirq'):
for i in range(len(self.percputime_new)):
if hasattr(self.percputime_new[i], 'softirq'):
self.percputime_total_new[i] += self.percputime_new[i].softirq
perpercent = []
self.percpu = []
for i in range(len(self.percputime_new)):
for i in range(len(self.percputime_new)):
perpercent.append(100 / (self.percputime_total_new[i] -
self.percputime_total_old[i]))
cpu = {'kernel':
@ -723,7 +723,7 @@ class glancesStats:
if hasattr(self.percputime_new[i], 'nice'):
cpu['nice'] = (self.percputime_new[i].nice -
self.percputime_old[i].nice) * perpercent[i]
self.percpu.append(cpu)
self.percpu.append(cpu)
self.percputime_old = self.percputime_new
self.percputime_total_old = self.percputime_total_new
except Exception:
@ -736,7 +736,7 @@ class glancesStats:
if input_stats != {}:
self.load = input_stats["load"]
else:
if hasattr(os, 'getloadavg'):
if hasattr(os, 'getloadavg'):
getload = os.getloadavg()
self.load = {'min1': getload[0],
'min5': getload[1],
@ -768,7 +768,7 @@ class glancesStats:
self.memswap = {'total': virtmem.total,
'used': virtmem.used,
'free': virtmem.free,
'percent': virtmem.percent}
'percent': virtmem.percent}
else:
# For olders PsUtil version
# Physical memory (RAM)
@ -788,7 +788,7 @@ class glancesStats:
else:
self.mem = {}
# Virtual memory (SWAP)
if hasattr(psutil, 'virtmem_usage'):
if hasattr(psutil, 'virtmem_usage'):
virtmem = psutil.virtmem_usage()
self.memswap = {'total': virtmem.total,
'used': virtmem.used,
@ -807,8 +807,8 @@ class glancesStats:
else:
if psutil_network_io_tag:
self.network = []
if hasattr(psutil, 'network_io_counters'):
if not hasattr(self, 'network_old'):
if hasattr(psutil, 'network_io_counters'):
if not hasattr(self, 'network_old'):
self.network_old = psutil.network_io_counters(True)
else:
self.network_new = psutil.network_io_counters(True)
@ -849,8 +849,8 @@ class glancesStats:
else:
if psutil_disk_io_tag:
self.diskio = []
if psutil_disk_io_tag and hasattr(psutil, 'disk_io_counters'):
if not hasattr(self, 'diskio_old'):
if psutil_disk_io_tag and hasattr(psutil, 'disk_io_counters'):
if not hasattr(self, 'diskio_old'):
self.diskio_old = psutil.disk_io_counters(True)
else:
self.diskio_new = psutil.disk_io_counters(True)
@ -894,7 +894,7 @@ class glancesStats:
else:
if self.process_list_refresh:
self.process_first_grab = False
if not hasattr(self, 'process_all'):
if not hasattr(self, 'process_all'):
self.process_all = [proc for proc in psutil.process_iter()]
self.process_first_grab = True
self.process = []
@ -1373,9 +1373,9 @@ class glancesScreen:
cs_status:
"None": standalone or server mode
"Connected": Client is connected to the server
"Disconnected": Client is disconnected from the server
"Disconnected": Client is disconnected from the server
"""
# Get stats for processes (used in another functions for logs)
processcount = stats.getProcessCount()
processlist = stats.getProcessList(screen.getProcessSortedBy())
@ -1385,12 +1385,12 @@ class glancesScreen:
self.displayLoad(stats.getLoad(), stats.getCore(), processlist, cpu_offset)
self.displayMem(stats.getMem(), stats.getMemSwap(), processlist, cpu_offset)
network_count = self.displayNetwork(stats.getNetwork())
sensors_count = self.displaySensors(stats.getSensors(),
sensors_count = self.displaySensors(stats.getSensors(),
self.network_y + network_count)
diskio_count = self.displayDiskIO(stats.getDiskIO(),
self.network_y + sensors_count + network_count)
fs_count = self.displayFs(stats.getFs(),
self.network_y + sensors_count +
self.network_y + sensors_count +
network_count + diskio_count)
log_count = self.displayLog(self.network_y + sensors_count + network_count +
diskio_count + fs_count)
@ -1409,7 +1409,7 @@ class glancesScreen:
cs_status:
"None": standalone or server mode
"Connected": Client is connected to the server
"Disconnected": Client is disconnected from the server
"Disconnected": Client is disconnected from the server
"""
# Flush display
self.erase()
@ -1421,9 +1421,9 @@ class glancesScreen:
cs_status:
"None": standalone or server mode
"Connected": Client is connected to the server
"Disconnected": Client is disconnected from the server
"Disconnected": Client is disconnected from the server
"""
# flush display
self.flush(stats, cs_status = cs_status)
@ -1462,7 +1462,7 @@ class glancesScreen:
# Get screen size
screen_x = self.screen.getmaxyx()[1]
screen_y = self.screen.getmaxyx()[0]
# Is it possible to display extended stats ?
# If yes then tag_extendedcpu = True
tag_extendedcpu = screen_x > self.cpu_x + 79 + 17
@ -1474,14 +1474,14 @@ class glancesScreen:
tag_percpu = screen_x > self.cpu_x + 79 + (len(percpu)-1)*10
else:
tag_percpu = False
# Compute x offset
if (tag_percpu):
offset_x = (len(percpu)-1)*10
elif (tag_extendedcpu):
offset_x = 17
offset_x = 17
else:
offset_x = 0
offset_x = 0
# Display CPU stats
if (screen_y > self.cpu_y + 5 and tag_percpu):
@ -1517,7 +1517,7 @@ class glancesScreen:
# No alert for IDLE
self.term_window.addnstr(self.cpu_y + 3, self.cpu_x + 10 + i*10,
"%.1f" % percpu[i]['idle'], 8)
elif (screen_y > self.cpu_y + 5 and
screen_x > self.cpu_x + 18):
# Display summary information
@ -1532,8 +1532,8 @@ class glancesScreen:
self.term_window.addnstr(self.cpu_y, self.cpu_x + 10,
"%.1f%%" % (100 - cpu['idle']), 8)
self.term_window.addnstr(self.cpu_y + 1, self.cpu_x,
self.term_window.addnstr(self.cpu_y + 1, self.cpu_x,
_("User:"), 8)
alert = self.__getCpuAlert(cpu['user'])
logs.add(alert, "CPU user", cpu['user'], proclist)
@ -1549,13 +1549,13 @@ class glancesScreen:
"%.1f" % cpu['kernel'], 8,
self.__colors_list[alert])
# No alert for IDLE
self.term_window.addnstr(self.cpu_y + 3, self.cpu_x,
self.term_window.addnstr(self.cpu_y + 3, self.cpu_x,
_("Idle:"), 8)
self.term_window.addnstr(self.cpu_y + 3, self.cpu_x + 10,
"%.1f" % cpu['idle'], 8)
if (screen_y > self.cpu_y + 5 and tag_extendedcpu):
# Display extended CPU stats whenspace is available
# Display extended CPU stats whenspace is available
self.term_window.addnstr(self.cpu_y + 1, self.cpu_x + 17,
_("IO Wait:"), 8)
try:
@ -1565,7 +1565,7 @@ class glancesScreen:
except:
self.term_window.addnstr(self.cpu_y + 1, self.cpu_x + 27,
"N/A", 8)
self.term_window.addnstr(self.cpu_y + 2, self.cpu_x + 17,
self.term_window.addnstr(self.cpu_y + 2, self.cpu_x + 17,
_("IRQ:"), 8)
try:
self.term_window.addnstr(self.cpu_y + 2, self.cpu_x + 27,
@ -1573,7 +1573,7 @@ class glancesScreen:
except:
self.term_window.addnstr(self.cpu_y + 2, self.cpu_x + 27,
"N/A", 8)
self.term_window.addnstr(self.cpu_y + 3, self.cpu_x + 17,
self.term_window.addnstr(self.cpu_y + 3, self.cpu_x + 17,
_("Nice:"), 8)
try:
self.term_window.addnstr(self.cpu_y + 3, self.cpu_x + 27,
@ -1744,7 +1744,7 @@ class glancesScreen:
screen_x > self.sensors_x + 28):
# Sensors header
self.term_window.addnstr(self.sensors_y, self.sensors_x,
_("Sensors"), 8, self.title_color
_("Sensors"), 8, self.title_color
if self.hascolors else curses.A_UNDERLINE)
self.term_window.addnstr(self.sensors_y, self.sensors_x+22,
_("C"), 3)
@ -1963,7 +1963,7 @@ class glancesScreen:
if not psutil_get_io_counter_tag:
tag_io = False
# VMS
self.term_window.addnstr(
self.process_y + 2, process_x,
@ -2023,7 +2023,7 @@ class glancesScreen:
self.term_window.addnstr(
self.process_y + 2, process_x + process_name_x,
_("IO_W"), 6)
process_name_x += 8
process_name_x += 8
# PROCESS NAME
self.term_window.addnstr(
self.process_y + 2, process_x + process_name_x,
@ -2094,7 +2094,7 @@ class glancesScreen:
# TIME+
if tag_proc_time:
process_time = processlist[processes]['cpu_times']
try:
try:
dtime = timedelta(seconds=sum(process_time))
except:
# Catched on some Amazon EC2 server
@ -2131,7 +2131,7 @@ class glancesScreen:
self.__autoUnit(io_write), 6)
except:
pass
# display process command line
max_process_name = screen_x - process_x - process_name_x
process_name = processlist[processes]['name']
@ -2151,7 +2151,7 @@ class glancesScreen:
cs_status:
"None": standalone or server mode
"Connected": Client is connected to the server
"Disconnected": Client is disconnected from the server
"Disconnected": Client is disconnected from the server
"""
# Caption
@ -2165,7 +2165,7 @@ class glancesScreen:
msg_client = _("Disconnected from")+" "+format(server_ip)
msg_client_style = self.ifCRITICAL_color2 if self.hascolors else curses.A_UNDERLINE
msg_help = _("Press 'h' for help")
if (client_tag):
if (client_tag):
if (screen_y > self.caption_y and
screen_x > self.caption_x + len(msg_client)):
self.term_window.addnstr(max(self.caption_y, screen_y - 1),
@ -2173,16 +2173,16 @@ class glancesScreen:
msg_client_style)
if (screen_x > self.caption_x + len(msg_client)+3+len(msg_help)):
self.term_window.addnstr(max(self.caption_y, screen_y - 1),
self.caption_x+len(msg_client), " | "+msg_help, 3+len(msg_help))
self.caption_x+len(msg_client), " | "+msg_help, 3+len(msg_help))
else:
self.term_window.addnstr(max(self.caption_y, screen_y - 1),
self.caption_x, msg_help, len(msg_help))
def displayHelp(self):
"""
Show the help panel
"""
if not self.help_tag:
return 0
screen_x = self.screen.getmaxyx()[1]
@ -2318,7 +2318,7 @@ class glancesHtml:
# Init refresh time
self.__refresh_time = refresh_time
# Set the root path
self.root_path = htmlfolder + '/'
@ -2383,7 +2383,7 @@ class glancesHtml:
elif current > limits.getLOADWarning(core):
return 'WARNING'
elif current > limits.getLOADCareful(core):
return 'CAREFUL'
return 'CAREFUL'
return 'OK'
def __getLoadColor(self, load, core=1):
@ -2495,7 +2495,7 @@ class GlancesHandler(SimpleXMLRPCRequestHandler):
Main XMLRPC handler
"""
rpc_paths = ('/RPC2',)
def log_message(self, format, *args):
# No message displayed on the server side
pass
@ -2504,27 +2504,27 @@ class GlancesHandler(SimpleXMLRPCRequestHandler):
class GlancesInstance():
"""
All the methods of this class are published as XML RPC methods
"""
"""
def __init__(self, refresh_time = 1):
self.timer = Timer(0)
self.refresh_time = refresh_time
def __update__(self):
# Never update more than 1 time per refresh_time
if self.timer.finished():
stats.update()
stats.update()
self.timer = Timer(self.refresh_time)
def init(self):
# Return the Glances version
return __version__
# Return the Glances version
return __version__
def getAll(self):
# Update and return all the stats
self.__update__()
return json.dumps(stats.getAll())
def getCpu(self):
# Update and return CPU stats
self.__update__()
@ -2554,20 +2554,20 @@ class GlancesInstance():
class GlancesServer():
"""
This class creates and manages the TCP client
"""
"""
def __init__(self, bind_address, bind_port = 61209,
RequestHandler = GlancesHandler,
def __init__(self, bind_address, bind_port = 61209,
RequestHandler = GlancesHandler,
refresh_time = 1):
self.server = SimpleXMLRPCServer((bind_address, bind_port),
requestHandler = RequestHandler)
self.server.register_introspection_functions()
self.server.register_instance(GlancesInstance(refresh_time))
return
def serve_forever(self):
self.server.serve_forever()
def server_close(self):
self.server.server_close()
@ -2643,7 +2643,7 @@ def end():
# Stop the client loop
#~ client.client_quit()
pass
# Stop the classical CLI loop
screen.end()
@ -2681,10 +2681,10 @@ def main():
server_tag = True
else:
server_tag = False
# Set the default refresh time
refresh_time = 2
# Set the default TCP port for client and server
server_port = 61209
bind_ip = "0.0.0.0"
@ -2692,8 +2692,8 @@ def main():
# Manage args
try:
opts, args = getopt.getopt(sys.argv[1:], "B:bdemnho:f:t:vsc:p:",
["bind", "bytepersec", "diskio", "mount",
"sensors", "netrate", "help", "output",
["bind", "bytepersec", "diskio", "mount",
"sensors", "netrate", "help", "output",
"file", "time", "version", "server",
"client", "port"])
except getopt.GetoptError as err:
@ -2773,7 +2773,7 @@ def main():
if html_tag or csv_tag:
print(_("Error: Can not use both -c and -o flag"))
sys.exit(2)
if html_tag:
if not html_lib_tag:
print(_("Error: Need Jinja2 library to export into HTML"))
@ -2812,25 +2812,25 @@ def main():
sensors_tag = True
elif server_tag:
sensors_tag = True
# Init Glances depending of the mode (standalone, client, server)
# Init Glances depending of the mode (standalone, client, server)
if server_tag:
# Init the server
print(_("Glances server is running on")+ " %s:%s" % (bind_ip, server_port))
server = GlancesServer(bind_ip, server_port, GlancesHandler, refresh_time)
# Init stats
stats = glancesStats(server_tag = True)
stats = glancesStats(server_tag = True)
elif client_tag:
# Init the client (displaying server stat in the CLI)
client = GlancesClient(server_ip, server_port)
# Test if client and server are in the same major version
if not client.client_init():
print(_("Error: The server version is not compatible"))
sys.exit(2)
# Init Limits
limits = glancesLimits()
@ -2841,10 +2841,10 @@ def main():
stats = glancesStats(client_tag = True)
# Init screen
screen = glancesScreen(refresh_time=refresh_time)
screen = glancesScreen(refresh_time=refresh_time)
else:
# Init the classical CLI
# Init Limits
limits = glancesLimits()
@ -2869,13 +2869,13 @@ def main():
# Glances - Main loop
#####################
if server_tag:
# Start the server loop
server.serve_forever()
elif client_tag:
# Start the client (CLI) loop
while True:
while True:
# Get server system informations
server_stats = client.client_get()
if server_stats == {}:

View File

@ -27,29 +27,29 @@ import glances
import multiprocessing
class TestGlancesStat(unittest.TestCase):
def setUp(self):
self.stats = glances.glancesStats()
self.stats.update()
self.stats.update()
def test_Glances_getCore(self):
self.assertEqual(self.stats.getCore(), multiprocessing.cpu_count())
def test_Glances_getCpu(self):
self.stats.update()
self.stats.update()
self.assertEqual(len(self.stats.getCpu()), 4)
def test_Glances_getPerCpu(self):
self.stats.update()
self.stats.update()
self.assertEqual(len(self.stats.getPerCpu()), multiprocessing.cpu_count())
def test_Glances_getMem(self):
self.stats.update()
self.stats.update()
self.assertTrue(len(self.stats.getMem()) > 2)
def test_Glances_getMemSwap(self):
self.stats.update()
self.stats.update()
self.assertTrue(len(self.stats.getMemSwap()) > 2)
if __name__ == '__main__':
unittest.main()