summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2019-02-27 15:42:00 +0100
committerGiampaolo Rodola <g.rodola@gmail.com>2019-02-27 15:42:00 +0100
commit25beb1467448e68cd88803f8289e20c8423d760e (patch)
tree77ebe2a66dc497c8ba7c9c61dde4d50692d20c8f
parent52253a519609d6d8990d9d6812ea9bed0204c81c (diff)
downloadpsutil-25beb1467448e68cd88803f8289e20c8423d760e.tar.gz
add printerr() and exit() to shared utils module
-rwxr-xr-xscripts/internal/download_exes.py20
-rw-r--r--scripts/internal/scriptutils.py14
2 files changed, 20 insertions, 14 deletions
diff --git a/scripts/internal/download_exes.py b/scripts/internal/download_exes.py
index efe4ef18..3d84b500 100755
--- a/scripts/internal/download_exes.py
+++ b/scripts/internal/download_exes.py
@@ -19,10 +19,9 @@ import errno
import os
import requests
import shutil
-import sys
from psutil import __version__ as PSUTIL_VERSION
-from scriptutils import hilite
+from scriptutils import printerr, exit
BASE_URL = 'https://ci.appveyor.com/api'
@@ -31,12 +30,6 @@ TIMEOUT = 30
COLORS = True
-def exit(msg=""):
- if msg:
- print(hilite(msg, ok=False), file=sys.stderr)
- sys.exit(1)
-
-
def safe_makedirs(path):
try:
os.makedirs(path)
@@ -106,8 +99,9 @@ def get_file_urls(options):
urls.append(file_url)
if not urls:
exit("no artifacts found")
- for url in sorted(urls, key=lambda x: os.path.basename(x)):
- yield url
+ else:
+ for url in sorted(urls, key=lambda x: os.path.basename(x)):
+ yield url
def rename_27_wheels():
@@ -133,9 +127,9 @@ def run(options):
url = fut_to_url[fut]
try:
local_fname = fut.result()
- except Exception as _:
- exc = _
- print("error while downloading %s: %s" % (url, exc))
+ except Exception:
+ printerr("error while downloading %s" % (url))
+ raise
else:
completed += 1
print("downloaded %-45s %s" % (
diff --git a/scripts/internal/scriptutils.py b/scripts/internal/scriptutils.py
index 7369804c..3ee416f8 100644
--- a/scripts/internal/scriptutils.py
+++ b/scripts/internal/scriptutils.py
@@ -6,11 +6,13 @@
"""Utils shared by all files in scripts/internal."""
+from __future__ import print_function
import sys
from psutil._compat import lru_cache
-__all__ = ['hilite']
+
+__all__ = ['hilite', 'printerr', 'exit']
@lru_cache()
@@ -40,3 +42,13 @@ def hilite(s, ok=True, bold=False):
if bold:
attr.append('1')
return '\x1b[%sm%s\x1b[0m' % (';'.join(attr), s)
+
+
+def printerr(s):
+ print(hilite(s, ok=False), file=sys.stderr)
+
+
+def exit(msg=""):
+ if msg:
+ printerr(msg)
+ sys.exit(1)