Skip to content

Commit

Permalink
cleanup_unused: allow dryrun
Browse files Browse the repository at this point in the history
  • Loading branch information
vieting committed Aug 1, 2023
1 parent 155c9f0 commit 7d842bf
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions sisyphus/cleaner.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,11 @@ def remove_directories(dirs, message, move_postfix='.cleanup', mode='remove', fo
if len(dirs) == 0:
return

if mode == 'dryrun':
for dir in dirs:
logging.info('Would remove: %s' % dir)
return

input_var = 'UNSET'
while input_var.lower() not in ('n', 'y', ''):
input_var = input("Calculate size of affected directories? (Y/n): ")
Expand Down Expand Up @@ -295,12 +300,13 @@ def cleanup_keep_value(min_keep_value, load_from: str = '', mode: str = 'remove'
force=False)


def cleanup_unused(load_from: str = '', job_dirs=None):
def cleanup_unused(load_from: str = '', job_dirs=None, mode='remove'):
""" Check work directory and remove all subdirectories which do not belong to the given list of directories.
If no input is given it removes everything that is not in the current graph
:param load_from: File name to load list with used directories
:param job_dirs: Already loaded list of used directories
:param mode: Cleanup mode (e.g. 'remove' or 'dryrun')
:return:
"""
if job_dirs:
Expand All @@ -310,4 +316,4 @@ def cleanup_unused(load_from: str = '', job_dirs=None):
else:
job_dirs = list_all_graph_directories()
to_remove = search_for_unused(job_dirs, verbose=True)
remove_directories(to_remove, 'Not used in graph', mode='remove', force=False)
remove_directories(to_remove, 'Not used in graph', mode=mode, force=False)

0 comments on commit 7d842bf

Please sign in to comment.