diff options
-rw-r--r-- | host/utils/uhd_images_downloader.py.in | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/host/utils/uhd_images_downloader.py.in b/host/utils/uhd_images_downloader.py.in index ebfdd9669..6655274dd 100644 --- a/host/utils/uhd_images_downloader.py.in +++ b/host/utils/uhd_images_downloader.py.in @@ -22,6 +22,10 @@ try: from urllib.parse import urljoin # Python 3 except ImportError: from urlparse import urljoin # Python 2 +try: + from builtins import input +except ImportError: + input = raw_input from six import iteritems import requests @@ -43,6 +47,7 @@ _LOG_LEVELS = {"TRACE": 1, "WARN": 4, "ERROR": 5} _LOG_LEVEL = _LOG_LEVELS["INFO"] +_YES = False def log(level, message): @@ -81,6 +86,8 @@ def parse_args(): help="Keep the downloaded images archives in the image directory") parser.add_argument("-T", "--test", action="store_true", default=False, help="Verify the downloaded archives before extracting them") + parser.add_argument("-y", "--yes", action="store_true", default=False, + help="Answer all questions with 'yes' (for scripting purposes).") parser.add_argument("-n", "--dry-run", action="store_true", default=False, help="Print selected target without actually downloading them.") parser.add_argument("--refetch", action="store_true", default=False, @@ -93,6 +100,24 @@ def parse_args(): return parser.parse_args() +def ask_permission(question, default_no=True): + """ + Ask the question, and have the user type y or n on the keyboard. If the + global variable _YES is true, this always returns True without asking the + question. Otherwise, return True if the answer is 'yes', 'y', or something + similar. + """ + if _YES: + log("DEBUG", "Assuming the answer is 'yes' for this question: " + + question) + return True + postfix = "[y/N]" if default_no else "[Y/n]" + answer = input(question + " " + postfix) + if answer and answer[0].lower() == 'y': + return True + return False + + class TemporaryDirectory: """Class to create a temporary directory""" def __enter__(self): |