Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added force option to skip prompting the user if they want files deleted #12

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions bin/testcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: let's use a more meaningful name - force_deletion?

'''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'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use a boolean flag here.

e.g.

if force_deletion:
  delete_files = True
else:
  ...
  delete_files = ans == 'y'

And then we have a clearer test in the next if block.

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.')
Expand Down Expand Up @@ -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)
Expand Down