mirror of
https://github.com/nicolargo/glances.git
synced 2024-09-22 10:08:02 +03:00
flake8 fixes
This commit is contained in:
parent
4355f4053f
commit
6d5663ec7c
@ -89,7 +89,7 @@ if not is_Windows:
|
||||
sys.exit(1)
|
||||
|
||||
try:
|
||||
# PSUtil is the main lib used to grab stats
|
||||
# psutil is the main library used to grab stats
|
||||
import psutil
|
||||
except ImportError:
|
||||
print(_('PsUtil module not found. Glances cannot start.'))
|
||||
@ -102,7 +102,7 @@ if psutil_version < (0, 4, 1):
|
||||
sys.exit(1)
|
||||
|
||||
try:
|
||||
# virtual_memory() only available with PsUtil 0.6+
|
||||
# virtual_memory() only available from psutil >= 0.6
|
||||
psutil.virtual_memory()
|
||||
except Exception:
|
||||
psutil_mem_vm = False
|
||||
@ -115,7 +115,7 @@ else:
|
||||
# get_io_counters() not available on OS X
|
||||
psutil_get_io_counter_tag = False
|
||||
|
||||
# Sensors (optional; only available on Linux)
|
||||
# sensors library (optional; Linux-only)
|
||||
if is_Linux:
|
||||
try:
|
||||
import sensors
|
||||
@ -126,6 +126,15 @@ if is_Linux:
|
||||
else:
|
||||
sensors_lib_tag = False
|
||||
|
||||
# batinfo library (optional; Linux-only)
|
||||
if is_Linux:
|
||||
try:
|
||||
import batinfo
|
||||
except ImportError:
|
||||
batinfo_lib_tag = False
|
||||
else:
|
||||
batinfo_lib_tag = True
|
||||
|
||||
try:
|
||||
# HTML output (optional)
|
||||
import jinja2
|
||||
@ -142,15 +151,6 @@ except ImportError:
|
||||
else:
|
||||
csv_lib_tag = True
|
||||
|
||||
if (is_Linux):
|
||||
try:
|
||||
# Import the batinfo lib (optionnal)
|
||||
import batinfo
|
||||
except ImportError:
|
||||
batinfo_lib_tag = False
|
||||
else:
|
||||
batinfo_lib_tag = True
|
||||
|
||||
# Default tag
|
||||
sensors_tag = False
|
||||
hddtemp_tag = False
|
||||
@ -712,6 +712,7 @@ class glancesGrabSensors:
|
||||
if self.initok:
|
||||
sensors.cleanup()
|
||||
|
||||
|
||||
class glancesGrabHDDTemp:
|
||||
"""
|
||||
Get hddtemp stats using a socket connection
|
||||
@ -899,15 +900,14 @@ class glancesGrabBat:
|
||||
"""
|
||||
Init batteries stats
|
||||
"""
|
||||
|
||||
if (batinfo_lib_tag):
|
||||
try:
|
||||
self.bat = batinfo.batteries()
|
||||
except:
|
||||
self.initok = False
|
||||
else:
|
||||
self.initok = True
|
||||
self.__update__()
|
||||
if batinfo_lib_tag:
|
||||
try:
|
||||
self.bat = batinfo.batteries()
|
||||
except:
|
||||
self.initok = False
|
||||
else:
|
||||
self.initok = True
|
||||
self.__update__()
|
||||
|
||||
def __update__(self):
|
||||
"""
|
||||
@ -918,25 +918,24 @@ class glancesGrabBat:
|
||||
self.bat.update()
|
||||
self.bat_list = self.bat.stat
|
||||
else:
|
||||
self.bat_list = []
|
||||
self.bat_list = []
|
||||
|
||||
def get(self):
|
||||
# Update the stats
|
||||
# Update the stats
|
||||
self.__update__()
|
||||
return self.bat_list
|
||||
|
||||
def getcapacitypercent(self):
|
||||
|
||||
if not self.initok or self.bat_list == []:
|
||||
return []
|
||||
# Init the bsum (sum of percent) and bcpt (number of batteries)
|
||||
# and Loop over batteries (yes a computer could have more than 1 battery)
|
||||
bsum = 0
|
||||
for bcpt in range(len(self.get())):
|
||||
bsum = bsum + int(self.bat_list[bcpt].capacity)
|
||||
bcpt = bcpt + 1
|
||||
# Return the global percent
|
||||
return int(bsum / bcpt)
|
||||
if not self.initok or self.bat_list == []:
|
||||
return []
|
||||
# Init the bsum (sum of percent) and bcpt (number of batteries)
|
||||
# and Loop over batteries (yes a computer could have more than 1 battery)
|
||||
bsum = 0
|
||||
for bcpt in range(len(self.get())):
|
||||
bsum = bsum + int(self.bat_list[bcpt].capacity)
|
||||
bcpt = bcpt + 1
|
||||
# Return the global percent
|
||||
return int(bsum / bcpt)
|
||||
|
||||
|
||||
class GlancesStats:
|
||||
@ -978,7 +977,7 @@ class GlancesStats:
|
||||
self.hddtemp_tag = False
|
||||
|
||||
if batinfo_lib_tag:
|
||||
self.glancesgrabbat = glancesGrabBat()
|
||||
self.glancesgrabbat = glancesGrabBat()
|
||||
|
||||
# Init the process list
|
||||
self.process_list_refresh = True
|
||||
@ -1246,7 +1245,7 @@ class GlancesStats:
|
||||
|
||||
# BATERRIES INFORMATION
|
||||
if batinfo_lib_tag:
|
||||
self.batpercent = self.glancesgrabbat.getcapacitypercent()
|
||||
self.batpercent = self.glancesgrabbat.getcapacitypercent()
|
||||
|
||||
# DISK I/O
|
||||
if diskio_tag and not self.diskio_error_tag:
|
||||
@ -1355,10 +1354,10 @@ class GlancesStats:
|
||||
return []
|
||||
|
||||
def getBatPercent(self):
|
||||
if batinfo_lib_tag:
|
||||
return self.batpercent
|
||||
else:
|
||||
return []
|
||||
if batinfo_lib_tag:
|
||||
return self.batpercent
|
||||
else:
|
||||
return []
|
||||
|
||||
def getDiskIO(self):
|
||||
if diskio_tag:
|
||||
@ -2045,15 +2044,15 @@ class glancesScreen:
|
||||
cpu_offset = self.displayCpu(stats.getCpu(), stats.getPerCpu(), processlist)
|
||||
load_offset = self.displayLoad(stats.getLoad(), stats.getCore(), processlist, cpu_offset)
|
||||
self.displayMem(stats.getMem(), stats.getMemSwap(), processlist, load_offset)
|
||||
network_count = self.displayNetwork(stats.getNetwork(), error = stats.network_error_tag)
|
||||
network_count = self.displayNetwork(stats.getNetwork(), error=stats.network_error_tag)
|
||||
sensors_count = self.displaySensors(stats.getSensors(),
|
||||
self.network_y + network_count)
|
||||
hddtemp_count = self.displayHDDTemp(stats.getHDDTemp(),
|
||||
self.network_y + network_count + sensors_count)
|
||||
diskio_count = self.displayDiskIO(stats.getDiskIO(),
|
||||
offset_y = self.network_y + sensors_count +
|
||||
offset_y=self.network_y + sensors_count +
|
||||
network_count + hddtemp_count,
|
||||
error = stats.diskio_error_tag)
|
||||
error=stats.diskio_error_tag)
|
||||
fs_count = self.displayFs(stats.getFs(),
|
||||
self.network_y + sensors_count +
|
||||
network_count + diskio_count +
|
||||
@ -2476,7 +2475,7 @@ class glancesScreen:
|
||||
self.mem_y + 3, self.mem_x + offset_x + 39,
|
||||
format(self.__autoUnit(memswap['free']), '>5'), 8)
|
||||
|
||||
def displayNetwork(self, network, error = False):
|
||||
def displayNetwork(self, network, error=False):
|
||||
"""
|
||||
Display the network interface bitrate
|
||||
If error = True, then display a grab error message
|
||||
@ -2506,7 +2505,7 @@ class glancesScreen:
|
||||
self.term_window.addnstr(self.network_y, self.network_x + 10,
|
||||
format(_(rx_column_name), '>5'), 5)
|
||||
self.term_window.addnstr(self.network_y, self.network_x + 18,
|
||||
format(_(tx_column_name), '>5'), 5)
|
||||
format(_(tx_column_name), '>5'), 5)
|
||||
|
||||
if error:
|
||||
# If there is a grab error
|
||||
@ -2652,7 +2651,7 @@ class glancesScreen:
|
||||
return ret
|
||||
return 0
|
||||
|
||||
def displayDiskIO(self, diskio, offset_y=0, error = False):
|
||||
def displayDiskIO(self, diskio, offset_y=0, error=False):
|
||||
# Disk input/output rate
|
||||
if not self.diskio_tag:
|
||||
return 0
|
||||
@ -3036,9 +3035,9 @@ class glancesScreen:
|
||||
tag_proc_time = False
|
||||
else:
|
||||
dtime = "{0}:{1}.{2}".format(
|
||||
str(dtime.seconds // 60 % 60),
|
||||
str(dtime.seconds % 60).zfill(2),
|
||||
str(dtime.microseconds)[:2].zfill(2))
|
||||
str(dtime.seconds // 60 % 60),
|
||||
str(dtime.seconds % 60).zfill(2),
|
||||
str(dtime.microseconds)[:2].zfill(2))
|
||||
self.term_window.addnstr(
|
||||
self.process_y + 3 + processes, process_x + 47,
|
||||
format(dtime, '>8'), 8)
|
||||
@ -3269,7 +3268,6 @@ class glancesScreen:
|
||||
'{0:{width}}{1}'.format(*key, width=width), 38)
|
||||
key_table_y += 1
|
||||
|
||||
|
||||
def displayBat(self, batpercent):
|
||||
# Display the current batteries capacities % - Center
|
||||
if not batinfo_lib_tag or batpercent == []:
|
||||
@ -3279,15 +3277,14 @@ class glancesScreen:
|
||||
# Build the message to display
|
||||
bat_msg = "%d%%" % batpercent
|
||||
# Display the message (if possible)
|
||||
if (screen_y > self.bat_y and
|
||||
screen_x > self.bat_x + len(bat_msg)):
|
||||
if (screen_y > self.bat_y and
|
||||
screen_x > self.bat_x + len(bat_msg)):
|
||||
center = (screen_x // 2) - len(bat_msg) // 2
|
||||
self.term_window.addnstr(
|
||||
max(self.bat_y, screen_y - 1),
|
||||
self.bat_x + center,
|
||||
bat_msg, len(bat_msg))
|
||||
|
||||
|
||||
def displayNow(self, now):
|
||||
# Display the current date and time (now...) - Right
|
||||
if not now:
|
||||
|
Loading…
Reference in New Issue
Block a user