diff options
| author | Giampaolo Rodola <g.rodola@gmail.com> | 2019-04-05 17:44:45 +0200 |
|---|---|---|
| committer | Giampaolo Rodola <g.rodola@gmail.com> | 2019-04-05 17:44:45 +0200 |
| commit | 90135fa7fa63a0eadd318374d455c04565ce1d8e (patch) | |
| tree | 97b0b608c2676559a74d90fe21b4e3d149c80e2f /scripts/ifconfig.py | |
| parent | b24c552bc0a18ba894ae39907167e903dcafa924 (diff) | |
| download | psutil-90135fa7fa63a0eadd318374d455c04565ce1d8e.tar.gz | |
move bytes2human() into psutil._common and reused it from scripts dir
Diffstat (limited to 'scripts/ifconfig.py')
| -rwxr-xr-x | scripts/ifconfig.py | 19 |
1 files changed, 1 insertions, 18 deletions
diff --git a/scripts/ifconfig.py b/scripts/ifconfig.py index e2a9ce53..ad62a44f 100755 --- a/scripts/ifconfig.py +++ b/scripts/ifconfig.py @@ -47,6 +47,7 @@ from __future__ import print_function import socket import psutil +from psutil._common import bytes2human af_map = { @@ -62,24 +63,6 @@ duplex_map = { } -def bytes2human(n): - """ - >>> bytes2human(10000) - '9.8 K' - >>> bytes2human(100001221) - '95.4 M' - """ - symbols = ('K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y') - prefix = {} - for i, s in enumerate(symbols): - prefix[s] = 1 << (i + 1) * 10 - for s in reversed(symbols): - if n >= prefix[s]: - value = float(n) / prefix[s] - return '%.2f%s' % (value, s) - return '%.2fB' % (n) - - def main(): stats = psutil.net_if_stats() io_counters = psutil.net_io_counters(pernic=True) |
