From 973b79396f06a0d7d967dd1a9c29323a21124139 Mon Sep 17 00:00:00 2001 From: Peter Byrne Date: Tue, 7 Jun 2022 15:37:22 +0100 Subject: [PATCH] Added force option to skip prompting the user if they want files deleted --- bin/testcode.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/bin/testcode.py b/bin/testcode.py index 3b7ce13..a584e23 100755 --- a/bin/testcode.py +++ b/bin/testcode.py @@ -212,6 +212,8 @@ def parse_cmdline_args(args): parser.add_option('-v', '--verbose', default=1, action="count", dest='verbose', help='Increase verbosity of output. Can be ' 'specified multiple times.') + parser.add_option('--force', default=False, action='store_true', + help='Confirm deleting files older than X days without prompt.') (options, args) = parser.parse_args(args) @@ -519,24 +521,28 @@ def diff_tests(tests, diff_program, verbose=1): diff_popen.wait() os.chdir(cwd) -def tidy_tests(tests, ndays): +def tidy_tests(tests, ndays, force=False): '''Tidy up test directories. tests: list of tests. ndays: test files older than ndays are deleted. +force: delete files without user confirmation ''' epoch_time = time.time() - 86400*ndays test_globs = ['test.out*','test.err*'] - print( - 'Delete all %s files older than %s days from each job directory?' - % (' '.join(test_globs), ndays) - ) - ans = '' - while ans != 'y' and ans != 'n': - ans = testcode2.compatibility.compat_input('Confirm [y/n]: ') + if force: + ans = 'y' + else: + print( + 'Delete all %s files older than %s days from each job directory?' + % (' '.join(test_globs), ndays) + ) + ans = '' + while ans != 'y' and ans != 'n': + ans = testcode2.compatibility.compat_input('Confirm [y/n]: ') if ans == 'n': print('No files deleted.') @@ -791,7 +797,7 @@ def main(args): if 'diff' in actions: diff_tests(tests, user_options['diff'], verbose) if 'tidy' in actions: - tidy_tests(tests, options.older_than) + tidy_tests(tests, options.older_than, options.force) if 'make-benchmarks' in actions: make_benchmarks(test_programs, tests, userconfig, start_time, options.insert)