From 7c849c835f3d2cc0f7a68a1c6436b75c60872020 Mon Sep 17 00:00:00 2001
From: Alan De Smet <alan.desmet@ssec.wisc.edu>
Date: Fri, 20 Aug 2021 20:55:40 +0000
Subject: [PATCH] Allow multiple symlink destinations
aitf relies on the behavior
---
example/aitf-data-for-run | 35 ++++++++++++++++++-----------------
1 file changed, 18 insertions(+), 17 deletions(-)
diff --git a/example/aitf-data-for-run b/example/aitf-data-for-run
index ad97e0d..3478132 100755
--- a/example/aitf-data-for-run
+++ b/example/aitf-data-for-run
@@ -53,11 +53,11 @@ def parse_args():
metavar='DATE',
help='scan time ancillary data is needed for')
- ap.add_argument('destination', type=arg_directory,
+ ap.add_argument('destination', type=arg_directory, nargs='+',
metavar='FINAL_PATH',
- help='write required files here, possibly as symbolic links')
+ help='write symbolic links to required files here (actual files may be placed in the first destination provided)')
- add_cache_dir_arg(ap)
+ add_cache_dir_arg(ap, '--cache')
ap.add_argument('--cache-only', action='store_true',
help='do not download; only use files already in cache')
@@ -89,10 +89,10 @@ def main():
aitf.conlog.setup_logging()
args = parse_args()
- cache_dir = args.dir
+ cache_dir = args.cache
if not os.access(cache_dir, os.W_OK):
- logging.warning(f'I do not appear to be able to have write access to "{cache_dir}". Downloading directly into {args.destination}')
- args.dir = args.destination
+ logging.warning(f'I do not appear to be able to have write access to "{cache_dir}". Downloading directly into {args.destination[0]}')
+ args.cache = args.destination[0]
do_download = not args.cache_only
@@ -100,29 +100,30 @@ def main():
logging.progress("Acquiring SST")
sststats = aitf.ancil.SST.DownloadStatistics()
- sst_files = aitf.ancil.SST.download_for_time(args.scan_time, args.dir, do_download = do_download, download_stats = sststats)
+ sst_files = aitf.ancil.SST.download_for_time(args.scan_time, args.cache, do_download = do_download, download_stats = sststats)
log_download_report("SST Download Summary", sststats)
# using SST instead of GFS to show that
# DownloadStatistics are interchangable.
logging.progress("Acquiring GFS")
gfsstats = aitf.ancil.SST.DownloadStatistics()
- gfs_files = aitf.ancil.GFS.download_for_time(args.scan_time, args.dir, do_download = do_download, download_stats = sststats)
+ gfs_files = aitf.ancil.GFS.download_for_time(args.scan_time, args.cache, do_download = do_download, download_stats = sststats)
log_download_report("GFS Download Summary", gfsstats)
log_download_report("Total Download Summary", sststats + gfsstats)
logging.progress("Symbolically linking into place")
all_files = list(sst_files) + list(gfs_files)
- for file in all_files:
- f = os.path.relpath(file, args.dir)
- src = os.path.join(args.dir, f)
- dst = hack_oisst_preliminary_filename(os.path.join(args.destination, f))
- dst_dir = os.path.dirname(dst)
- os.makedirs(dst_dir, exist_ok=True)
- logging.info(src + ' -> ' + dst)
- if src != dst:
- os.symlink(src, dst)
+ for destination in args.destination:
+ for file in all_files:
+ f = os.path.relpath(file, args.cache)
+ src = os.path.join(args.cache, f)
+ dst = hack_oisst_preliminary_filename(os.path.join(destination, f))
+ dst_dir = os.path.dirname(dst)
+ os.makedirs(dst_dir, exist_ok=True)
+ logging.info(src + ' -> ' + dst)
+ if src != dst: # src==dst if we set args.cache to args.destination[0]
+ os.symlink(src, dst)
except csppfetch.DownloadsFailedException as e:
logging.fatal(str(e))
--
GitLab