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/disk_usage.py | |
| parent | b24c552bc0a18ba894ae39907167e903dcafa924 (diff) | |
| download | psutil-90135fa7fa63a0eadd318374d455c04565ce1d8e.tar.gz | |
move bytes2human() into psutil._common and reused it from scripts dir
Diffstat (limited to 'scripts/disk_usage.py')
| -rwxr-xr-x | scripts/disk_usage.py | 18 |
1 files changed, 1 insertions, 17 deletions
diff --git a/scripts/disk_usage.py b/scripts/disk_usage.py index 37f4da0c..1860401f 100755 --- a/scripts/disk_usage.py +++ b/scripts/disk_usage.py @@ -18,23 +18,7 @@ Device Total Used Free Use % Type Mount import sys import os import psutil - - -def bytes2human(n): - # http://code.activestate.com/recipes/578019 - # >>> bytes2human(10000) - # '9.8K' - # >>> bytes2human(100001221) - # '95.4M' - 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 '%.1f%s' % (value, s) - return "%sB" % n +from psutil._common import bytes2human def main(): |
