summaryrefslogtreecommitdiff
path: root/scripts/internal
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2019-04-05 17:44:45 +0200
committerGiampaolo Rodola <g.rodola@gmail.com>2019-04-05 17:44:45 +0200
commit90135fa7fa63a0eadd318374d455c04565ce1d8e (patch)
tree97b0b608c2676559a74d90fe21b4e3d149c80e2f /scripts/internal
parentb24c552bc0a18ba894ae39907167e903dcafa924 (diff)
downloadpsutil-90135fa7fa63a0eadd318374d455c04565ce1d8e.tar.gz
move bytes2human() into psutil._common and reused it from scripts dir
Diffstat (limited to 'scripts/internal')
-rwxr-xr-xscripts/internal/download_exes.py19
1 files changed, 1 insertions, 18 deletions
diff --git a/scripts/internal/download_exes.py b/scripts/internal/download_exes.py
index 41e303f8..1b72a177 100755
--- a/scripts/internal/download_exes.py
+++ b/scripts/internal/download_exes.py
@@ -21,6 +21,7 @@ import requests
import shutil
from psutil import __version__ as PSUTIL_VERSION
+from psutil._common import bytes2human
from scriptutils import printerr, exit
@@ -50,24 +51,6 @@ def safe_rmtree(path):
shutil.rmtree(path, onerror=onerror)
-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 '%.2f B' % (n)
-
-
def download_file(url):
local_fname = url.split('/')[-1]
local_fname = os.path.join('dist', local_fname)