aboutsummaryrefslogtreecommitdiffstats
path: root/host/utils/uhd_images_downloader.py.in
diff options
context:
space:
mode:
authorSteve Czabaniuk <steve.czabaniuk@ni.com>2020-06-17 09:47:02 -0500
committerAaron Rossetto <aaron.rossetto@ni.com>2020-06-22 14:37:24 -0500
commitaad2ccfa7ceebfabde5606893cd4bc7f3a84e40b (patch)
tree85c8d0b4ca269418c590e0f733380c76df037edc /host/utils/uhd_images_downloader.py.in
parent1d71d453de8991d9121f7ad07c10a2c186b6d03e (diff)
downloaduhd-aad2ccfa7ceebfabde5606893cd4bc7f3a84e40b.tar.gz
uhd-aad2ccfa7ceebfabde5606893cd4bc7f3a84e40b.tar.bz2
uhd-aad2ccfa7ceebfabde5606893cd4bc7f3a84e40b.zip
utils: Make uhd_images_downloader raise warning for invalid paths
This makes the utility warn the user when they pass a path argument that is invalid; the utility falls back to defaults if this occurs.
Diffstat (limited to 'host/utils/uhd_images_downloader.py.in')
-rw-r--r--host/utils/uhd_images_downloader.py.in32
1 files changed, 21 insertions, 11 deletions
diff --git a/host/utils/uhd_images_downloader.py.in b/host/utils/uhd_images_downloader.py.in
index 4d04342c1..5a0d2fa1d 100644
--- a/host/utils/uhd_images_downloader.py.in
+++ b/host/utils/uhd_images_downloader.py.in
@@ -101,12 +101,11 @@ def parse_args():
description=__doc__)
parser.add_argument('-t', '--types', action='append',
help="RegEx to select image sets from the manifest file.")
- parser.add_argument('-i', '--install-location',
- default=None,
+ parser.add_argument('-i', '--install-location', type=str, default=None,
help="Set custom install location for images")
- parser.add_argument('-m', '--manifest-location', type=str, default="",
+ parser.add_argument('-m', '--manifest-location', type=str, default=None,
help="Set custom location for the manifest file")
- parser.add_argument('-I', '--inventory-location', type=str, default="",
+ parser.add_argument('-I', '--inventory-location', type=str, default=None,
help="Set custom location for the inventory file")
parser.add_argument('-l', '--list-targets', action="store_true", default=False,
help="Print targets in the manifest file to stdout, and exit.\n"
@@ -225,11 +224,16 @@ def get_manifest_raw(args):
needs to be parsed to be of any practical use.
"""
# If we're given a path to a manifest file, use it
- if os.path.exists(args.manifest_location):
+ if args.manifest_location:
manifest_fn = args.manifest_location
- log("INFO", "Using manifest file at location: {}".format(manifest_fn))
- with open(manifest_fn, 'r') as manifest_file:
- manifest_raw = manifest_file.read()
+ if os.path.exists(manifest_fn):
+ log("INFO", "Using manifest file at location: {}".format(manifest_fn))
+ with open(manifest_fn, 'r') as manifest_file:
+ manifest_raw = manifest_file.read()
+ else:
+ log("WARN", "Invalid manifest file specified: {}, using default"
+ .format(manifest_fn))
+ manifest_raw = _MANIFEST_CONTENTS
# Otherwise, use the CMake Magic manifest
else:
manifest_raw = _MANIFEST_CONTENTS
@@ -553,10 +557,16 @@ def main():
return False
# Read the inventory into a dictionary we can perform lookups on
- if os.path.isfile(args.inventory_location):
- inventory_fn = args.inventory_location
+ default_inventory_fn = os.path.join(images_dir, _INVENTORY_FILENAME)
+ if args.inventory_location:
+ if os.path.isfile(args.inventory_location):
+ inventory_fn = args.inventory_location
+ else:
+ log("WARN", "Invalid inentory file specified: {}, using default: {}"
+ .format(args.inventory_location, default_inventory_fn))
+ inventory_fn = default_inventory_fn
else:
- inventory_fn = os.path.join(images_dir, _INVENTORY_FILENAME)
+ inventory_fn = default_inventory_fn
inventory = parse_inventory(inventory_fn=inventory_fn)
log("TRACE", "Inventory: {}\n{}".format(
os.path.abspath(inventory_fn),