From 4f2e5b645cc14fe7cccffb64d3922d6a7fc328bd Mon Sep 17 00:00:00 2001 From: Martin Braun Date: Tue, 30 Oct 2018 11:21:18 -0700 Subject: utils: Downloader stall on error for Windows users If platform.system() is 'Windows', the Python script will stall on error before terminating, e.g., when an import is missing or when an unexpected Exception occurred during the execution. The rationale is that many Windows users run this script directly, without a shell, and wouldn't have a way to see error messages from the script in that case. --- host/utils/uhd_images_downloader.py.in | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) (limited to 'host/utils') diff --git a/host/utils/uhd_images_downloader.py.in b/host/utils/uhd_images_downloader.py.in index 0c19e9167..f01eaed11 100644 --- a/host/utils/uhd_images_downloader.py.in +++ b/host/utils/uhd_images_downloader.py.in @@ -18,6 +18,9 @@ import shutil import sys import tempfile import zipfile +import platform +# For all the non-core-library imports, we will be extra paranoid and be very +# nice with error messages so that everyone understands what's up. try: from urllib.parse import urljoin # Python 3 except ImportError: @@ -26,8 +29,27 @@ try: from builtins import input except ImportError: input = raw_input -from six import iteritems -import requests +try: + from six import iteritems +except ImportError: + sys.stdout.write( + "[ERROR] Missing module 'six'! Please install it, e.g., by " + "running 'pip install six' or any other tool that can install " + "Python modules.\n") + if platform.system() == 'Windows': + input('Hit Enter to continue.') + exit(0) +try: + import requests +except ImportError: + sys.stdout.write( + "[ERROR] Missing module 'requests'! Please install it, e.g., by " + "running 'pip install requests' or any other tool that can install " + "Python modules.\n") + if platform.system() == 'Windows': + input('Hit Enter to continue.') + exit(0) + _DEFAULT_TARGET_REGEX = "(fpga|fw|windrv)_default" @@ -523,6 +545,12 @@ def main(): "You can run this again with the '--verbose' flag to see more information\n" "If the problem persists, please email the output to: {contact}" .format(contact=_CONTACT, ex=ex)) + # Again, we wait on Windows systems because if this is executed in a + # window, and immediately fails, the user doesn't have a way to see the + # error message, and if they're not very savvy, they won't know how to + # execute this in a shell. + if not _YES and platform.system() == 'Windows': + input('Hit Enter to continue.') return 1 log("INFO", "Images download complete.") return 0 -- cgit v1.2.3