From 040aa6fd9d328cc663c3d6def7b02350668686d4 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Thu, 13 May 2021 14:45:23 +0800 Subject: [PATCH] artiq_flash: improve openocd not found error message --- artiq/frontend/artiq_flash.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/artiq/frontend/artiq_flash.py b/artiq/frontend/artiq_flash.py index 6e7319a1c..8868b3fda 100755 --- a/artiq/frontend/artiq_flash.py +++ b/artiq/frontend/artiq_flash.py @@ -79,13 +79,18 @@ Prerequisites: help="actions to perform, default: flash everything") return parser +def which_openocd(): + openocd = shutil.which("openocd") + if not openocd: + raise FileNotFoundError("OpenOCD is required but was not found in PATH. Is it installed?") + return openocd def scripts_path(): p = ["share", "openocd", "scripts"] if os.name == "nt": p.insert(0, "Library") p = os.path.abspath(os.path.join( - os.path.dirname(os.path.realpath(shutil.which("openocd"))), + os.path.dirname(os.path.realpath(which_openocd())), "..", *p)) return p @@ -93,7 +98,7 @@ def scripts_path(): def proxy_path(): p = ["share", "bscan-spi-bitstreams"] p = os.path.abspath(os.path.join( - os.path.dirname(os.path.realpath(shutil.which("openocd"))), + os.path.dirname(os.path.realpath(which_openocd())), "..", *p)) return p