From 8260c2efa514b20585fb69d37795e41b6d5fe9ea Mon Sep 17 00:00:00 2001 From: Alan De Smet <alan.desmet@ssec.wisc.edu> Date: Fri, 12 May 2023 09:53:32 -0500 Subject: [PATCH] Bugfixes - There is no keep_old argument. - The argument should be temporal_dir, not temporal-dir. That trick only works with optional arguments where --temporal-dir turns into temporal_dir. --- example/aitf-clean-temporal | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/example/aitf-clean-temporal b/example/aitf-clean-temporal index 914e0ac..45cea89 100755 --- a/example/aitf-clean-temporal +++ b/example/aitf-clean-temporal @@ -21,6 +21,7 @@ import os import sys import logging +import datetime import aitf.ancil import aitf.conlog @@ -58,7 +59,7 @@ def parse_args(): TEMPORAL_INVALID = "not specified filler noise" TEMPORAL_CACHE_ENV = 'CSPP_GEO_AITF_TEMPORAL_CACHE' TEMPORAL_DEFAULT = os.environ.get(TEMPORAL_CACHE_ENV, TEMPORAL_INVALID) - ap.add_argument("temporal-dir", metavar = "DIR", nargs='?', + ap.add_argument("temporal_dir", metavar = "DIR", nargs='?', help = f'temporal directory to clean (default: environment variable {TEMPORAL_CACHE_ENV}', default=TEMPORAL_DEFAULT) @@ -104,19 +105,17 @@ def main(): else: log_download_report = no_cleanup_report - if not args.keep_old: - from datetime import datetime - stats = csppfetch.CleaningStats() - with PIDLockFile(args.temporal_dir+"cleaning-process.pid") as has_lock: - if has_lock: - csppfetch.delete_old_files(args.temporal_dir+"/L1b", args.oldest, stats) - csppfetch.delete_old_files(args.temporal_dir+"/L2", args.oldest, stats) - if args.want_summary: - sys.stdout.write('Expiring Old Data Summary\n') - sys.stdout.write(f' Removed {stats.num_deleted} files totaling {stats.size_deleted} bytes\n') - sys.stdout.write(f' Kept {stats.num_kept} files totaling {stats.size_kept} bytes\n') - else: # No lock - sys.stdout.write("Cleaning skipped; another process is already doing so.") + stats = csppfetch.CleaningStats() + with PIDLockFile(args.temporal_dir+"cleaning-process.pid") as has_lock: + if has_lock: + csppfetch.delete_old_files(args.temporal_dir+"/L1b", args.oldest, stats) + csppfetch.delete_old_files(args.temporal_dir+"/L2", args.oldest, stats) + if args.want_summary: + sys.stdout.write('Expiring Old Temporal Data Summary\n') + sys.stdout.write(f' Removed {stats.num_deleted} files totaling {stats.size_deleted} bytes\n') + sys.stdout.write(f' Kept {stats.num_kept} files totaling {stats.size_kept} bytes\n') + else: # No lock + sys.stdout.write("Cleaning skipped; another process is already doing so.") return 0 -- GitLab