mirror of
https://github.com/nicolargo/glances.git
synced 2024-12-01 22:14:06 +03:00
Fix bare except: statements
This commit is contained in:
parent
5bdb9af329
commit
2140172c5b
@ -71,7 +71,7 @@ except ImportError:
|
|||||||
try:
|
try:
|
||||||
# get_cpu_percent method only available with PsUtil 0.2.0+
|
# get_cpu_percent method only available with PsUtil 0.2.0+
|
||||||
psutil.Process(os.getpid()).get_cpu_percent(interval=0)
|
psutil.Process(os.getpid()).get_cpu_percent(interval=0)
|
||||||
except:
|
except Exception:
|
||||||
psutil_get_cpu_percent_tag = False
|
psutil_get_cpu_percent_tag = False
|
||||||
else:
|
else:
|
||||||
psutil_get_cpu_percent_tag = True
|
psutil_get_cpu_percent_tag = True
|
||||||
@ -80,7 +80,7 @@ try:
|
|||||||
# (phy|virt)mem_usage methods only available with PsUtil 0.3.0+
|
# (phy|virt)mem_usage methods only available with PsUtil 0.3.0+
|
||||||
psutil.phymem_usage()
|
psutil.phymem_usage()
|
||||||
psutil.virtmem_usage()
|
psutil.virtmem_usage()
|
||||||
except:
|
except Exception:
|
||||||
psutil_mem_usage_tag = False
|
psutil_mem_usage_tag = False
|
||||||
else:
|
else:
|
||||||
psutil_mem_usage_tag = True
|
psutil_mem_usage_tag = True
|
||||||
@ -89,7 +89,7 @@ try:
|
|||||||
# disk_(partitions|usage) methods only available with PsUtil 0.3.0+
|
# disk_(partitions|usage) methods only available with PsUtil 0.3.0+
|
||||||
psutil.disk_partitions()
|
psutil.disk_partitions()
|
||||||
psutil.disk_usage('/')
|
psutil.disk_usage('/')
|
||||||
except:
|
except Exception:
|
||||||
psutil_fs_usage_tag = False
|
psutil_fs_usage_tag = False
|
||||||
else:
|
else:
|
||||||
psutil_fs_usage_tag = True
|
psutil_fs_usage_tag = True
|
||||||
@ -97,7 +97,7 @@ else:
|
|||||||
try:
|
try:
|
||||||
# disk_io_counters method only available with PsUtil 0.4.0+
|
# disk_io_counters method only available with PsUtil 0.4.0+
|
||||||
psutil.disk_io_counters()
|
psutil.disk_io_counters()
|
||||||
except:
|
except Exception:
|
||||||
psutil_disk_io_tag = False
|
psutil_disk_io_tag = False
|
||||||
else:
|
else:
|
||||||
psutil_disk_io_tag = True
|
psutil_disk_io_tag = True
|
||||||
@ -105,7 +105,7 @@ else:
|
|||||||
try:
|
try:
|
||||||
# network_io_counters method only available with PsUtil 0.4.0+
|
# network_io_counters method only available with PsUtil 0.4.0+
|
||||||
psutil.network_io_counters()
|
psutil.network_io_counters()
|
||||||
except:
|
except Exception:
|
||||||
psutil_network_io_tag = False
|
psutil_network_io_tag = False
|
||||||
else:
|
else:
|
||||||
psutil_network_io_tag = True
|
psutil_network_io_tag = True
|
||||||
@ -325,7 +325,7 @@ class glancesGrabFs:
|
|||||||
fs_current['mnt_point'] = fs_stat[fs].mountpoint
|
fs_current['mnt_point'] = fs_stat[fs].mountpoint
|
||||||
try:
|
try:
|
||||||
fs_usage = psutil.disk_usage(fs_current['mnt_point'])
|
fs_usage = psutil.disk_usage(fs_current['mnt_point'])
|
||||||
except:
|
except Exception:
|
||||||
continue
|
continue
|
||||||
fs_current['size'] = fs_usage.total
|
fs_current['size'] = fs_usage.total
|
||||||
fs_current['used'] = fs_usage.used
|
fs_current['used'] = fs_usage.used
|
||||||
@ -350,7 +350,7 @@ class glancesStats:
|
|||||||
# Init the fs stats
|
# Init the fs stats
|
||||||
try:
|
try:
|
||||||
self.glancesgrabfs = glancesGrabFs()
|
self.glancesgrabfs = glancesGrabFs()
|
||||||
except:
|
except Exception:
|
||||||
self.glancesgrabfs = {}
|
self.glancesgrabfs = {}
|
||||||
|
|
||||||
# Process list refresh
|
# Process list refresh
|
||||||
@ -387,14 +387,14 @@ class glancesStats:
|
|||||||
self.host['os_version'] = " ".join(os_version[::2])
|
self.host['os_version'] = " ".join(os_version[::2])
|
||||||
else:
|
else:
|
||||||
self.host['os_version'] = ""
|
self.host['os_version'] = ""
|
||||||
except:
|
except Exception:
|
||||||
self.host['os_version'] = ""
|
self.host['os_version'] = ""
|
||||||
|
|
||||||
# CPU
|
# CPU
|
||||||
percent = 0
|
percent = 0
|
||||||
try:
|
try:
|
||||||
self.cputime_old
|
self.cputime_old
|
||||||
except:
|
except Exception:
|
||||||
self.cputime_old = psutil.cpu_times()
|
self.cputime_old = psutil.cpu_times()
|
||||||
self.cputime_total_old = (self.cputime_old.user +
|
self.cputime_total_old = (self.cputime_old.user +
|
||||||
self.cputime_old.system +
|
self.cputime_old.system +
|
||||||
@ -402,19 +402,19 @@ class glancesStats:
|
|||||||
# Only available on some OS
|
# Only available on some OS
|
||||||
try:
|
try:
|
||||||
self.cputime_total_old += self.cputime_old.nice
|
self.cputime_total_old += self.cputime_old.nice
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
try:
|
try:
|
||||||
self.cputime_total_old += self.cputime_old.iowait
|
self.cputime_total_old += self.cputime_old.iowait
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
try:
|
try:
|
||||||
self.cputime_total_old += self.cputime_old.irq
|
self.cputime_total_old += self.cputime_old.irq
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
try:
|
try:
|
||||||
self.cputime_total_old += self.cputime_old.softirq
|
self.cputime_total_old += self.cputime_old.softirq
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
self.cpu = {}
|
self.cpu = {}
|
||||||
else:
|
else:
|
||||||
@ -426,19 +426,19 @@ class glancesStats:
|
|||||||
# Only available on some OS
|
# Only available on some OS
|
||||||
try:
|
try:
|
||||||
self.cputime_total_new += self.cputime_new.nice
|
self.cputime_total_new += self.cputime_new.nice
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
try:
|
try:
|
||||||
self.cputime_total_new += self.cputime_new.iowait
|
self.cputime_total_new += self.cputime_new.iowait
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
try:
|
try:
|
||||||
self.cputime_total_new += self.cputime_new.irq
|
self.cputime_total_new += self.cputime_new.irq
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
try:
|
try:
|
||||||
self.cputime_total_new += self.cputime_new.softirq
|
self.cputime_total_new += self.cputime_new.softirq
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
percent = 100 / (self.cputime_total_new -
|
percent = 100 / (self.cputime_total_new -
|
||||||
self.cputime_total_old)
|
self.cputime_total_old)
|
||||||
@ -456,7 +456,7 @@ class glancesStats:
|
|||||||
self.cputime_old.nice) * percent}
|
self.cputime_old.nice) * percent}
|
||||||
self.cputime_old = self.cputime_new
|
self.cputime_old = self.cputime_new
|
||||||
self.cputime_total_old = self.cputime_total_new
|
self.cputime_total_old = self.cputime_total_new
|
||||||
except:
|
except Exception:
|
||||||
self.cpu = {}
|
self.cpu = {}
|
||||||
|
|
||||||
# LOAD
|
# LOAD
|
||||||
@ -465,14 +465,14 @@ class glancesStats:
|
|||||||
self.load = {'min1': getload[0],
|
self.load = {'min1': getload[0],
|
||||||
'min5': getload[1],
|
'min5': getload[1],
|
||||||
'min15': getload[2]}
|
'min15': getload[2]}
|
||||||
except:
|
except Exception:
|
||||||
self.load = {}
|
self.load = {}
|
||||||
|
|
||||||
# MEM
|
# MEM
|
||||||
try:
|
try:
|
||||||
# Only for Linux
|
# Only for Linux
|
||||||
cachemem = psutil.cached_phymem() + psutil.phymem_buffers()
|
cachemem = psutil.cached_phymem() + psutil.phymem_buffers()
|
||||||
except:
|
except Exception:
|
||||||
cachemem = 0
|
cachemem = 0
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -482,7 +482,7 @@ class glancesStats:
|
|||||||
'used': phymem.used,
|
'used': phymem.used,
|
||||||
'free': phymem.free,
|
'free': phymem.free,
|
||||||
'percent': phymem.percent}
|
'percent': phymem.percent}
|
||||||
except:
|
except Exception:
|
||||||
self.mem = {}
|
self.mem = {}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -491,7 +491,7 @@ class glancesStats:
|
|||||||
'used': virtmem.used,
|
'used': virtmem.used,
|
||||||
'free': virtmem.free,
|
'free': virtmem.free,
|
||||||
'percent': virtmem.percent}
|
'percent': virtmem.percent}
|
||||||
except:
|
except Exception:
|
||||||
self.memswap = {}
|
self.memswap = {}
|
||||||
|
|
||||||
# NET
|
# NET
|
||||||
@ -499,13 +499,13 @@ class glancesStats:
|
|||||||
self.network = []
|
self.network = []
|
||||||
try:
|
try:
|
||||||
self.network_old
|
self.network_old
|
||||||
except:
|
except Exception:
|
||||||
if psutil_network_io_tag:
|
if psutil_network_io_tag:
|
||||||
self.network_old = psutil.network_io_counters(True)
|
self.network_old = psutil.network_io_counters(True)
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
self.network_new = psutil.network_io_counters(True)
|
self.network_new = psutil.network_io_counters(True)
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
for net in self.network_new:
|
for net in self.network_new:
|
||||||
@ -516,7 +516,7 @@ class glancesStats:
|
|||||||
self.network_old[net].bytes_recv)
|
self.network_old[net].bytes_recv)
|
||||||
netstat['tx'] = (self.network_new[net].bytes_sent -
|
netstat['tx'] = (self.network_new[net].bytes_sent -
|
||||||
self.network_old[net].bytes_sent)
|
self.network_old[net].bytes_sent)
|
||||||
except:
|
except Exception:
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
self.network.append(netstat)
|
self.network.append(netstat)
|
||||||
@ -527,13 +527,13 @@ class glancesStats:
|
|||||||
self.diskio = []
|
self.diskio = []
|
||||||
try:
|
try:
|
||||||
self.diskio_old
|
self.diskio_old
|
||||||
except:
|
except Exception:
|
||||||
if psutil_disk_io_tag:
|
if psutil_disk_io_tag:
|
||||||
self.diskio_old = psutil.disk_io_counters(True)
|
self.diskio_old = psutil.disk_io_counters(True)
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
self.diskio_new = psutil.disk_io_counters(True)
|
self.diskio_new = psutil.disk_io_counters(True)
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
for disk in self.diskio_new:
|
for disk in self.diskio_new:
|
||||||
@ -546,7 +546,7 @@ class glancesStats:
|
|||||||
diskstat['write_bytes'] = (
|
diskstat['write_bytes'] = (
|
||||||
self.diskio_new[disk].write_bytes -
|
self.diskio_new[disk].write_bytes -
|
||||||
self.diskio_old[disk].write_bytes)
|
self.diskio_old[disk].write_bytes)
|
||||||
except:
|
except Exception:
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
self.diskio.append(diskstat)
|
self.diskio.append(diskstat)
|
||||||
@ -556,7 +556,7 @@ class glancesStats:
|
|||||||
if psutil_fs_usage_tag:
|
if psutil_fs_usage_tag:
|
||||||
try:
|
try:
|
||||||
self.fs = self.glancesgrabfs.get()
|
self.fs = self.glancesgrabfs.get()
|
||||||
except:
|
except Exception:
|
||||||
self.fs = {}
|
self.fs = {}
|
||||||
|
|
||||||
# PROCESS
|
# PROCESS
|
||||||
@ -566,7 +566,7 @@ class glancesStats:
|
|||||||
self.process_first_grab = False
|
self.process_first_grab = False
|
||||||
try:
|
try:
|
||||||
self.process_all
|
self.process_all
|
||||||
except:
|
except Exception:
|
||||||
self.process_all = [proc for proc in psutil.process_iter()]
|
self.process_all = [proc for proc in psutil.process_iter()]
|
||||||
self.process_first_grab = True
|
self.process_first_grab = True
|
||||||
self.process = []
|
self.process = []
|
||||||
@ -582,12 +582,12 @@ class glancesStats:
|
|||||||
if not proc.is_running():
|
if not proc.is_running():
|
||||||
try:
|
try:
|
||||||
self.process_all.remove(proc)
|
self.process_all.remove(proc)
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
except psutil.error.NoSuchProcess:
|
except psutil.error.NoSuchProcess:
|
||||||
try:
|
try:
|
||||||
self.process_all.remove(proc)
|
self.process_all.remove(proc)
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
# Global stats
|
# Global stats
|
||||||
@ -618,7 +618,7 @@ class glancesStats:
|
|||||||
procstat['proc_name'] = proc.name
|
procstat['proc_name'] = proc.name
|
||||||
procstat['proc_cmdline'] = " ".join(proc.cmdline)
|
procstat['proc_cmdline'] = " ".join(proc.cmdline)
|
||||||
self.process.append(procstat)
|
self.process.append(procstat)
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# If it is the first grab then empty process list
|
# If it is the first grab then empty process list
|
||||||
@ -697,7 +697,7 @@ class glancesStats:
|
|||||||
real_used_phymem = self.mem['used'] - self.mem['cache']
|
real_used_phymem = self.mem['used'] - self.mem['cache']
|
||||||
try:
|
try:
|
||||||
memtotal = (real_used_phymem * 100) / self.mem['total']
|
memtotal = (real_used_phymem * 100) / self.mem['total']
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
if memtotal > limits.getSTDWarning():
|
if memtotal > limits.getSTDWarning():
|
||||||
@ -763,22 +763,22 @@ class glancesScreen:
|
|||||||
if hasattr(curses, 'use_default_colors'):
|
if hasattr(curses, 'use_default_colors'):
|
||||||
try:
|
try:
|
||||||
curses.use_default_colors()
|
curses.use_default_colors()
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
if hasattr(curses, 'noecho'):
|
if hasattr(curses, 'noecho'):
|
||||||
try:
|
try:
|
||||||
curses.noecho()
|
curses.noecho()
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
if hasattr(curses, 'cbreak'):
|
if hasattr(curses, 'cbreak'):
|
||||||
try:
|
try:
|
||||||
curses.cbreak()
|
curses.cbreak()
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
if hasattr(curses, 'curs_set'):
|
if hasattr(curses, 'curs_set'):
|
||||||
try:
|
try:
|
||||||
curses.curs_set(0)
|
curses.curs_set(0)
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# Init colors
|
# Init colors
|
||||||
|
Loading…
Reference in New Issue
Block a user