From 3d2ee71e140154e97ce37345af287150cfce5e05 Mon Sep 17 00:00:00 2001 From: Zack Cerza Date: Fri, 29 Apr 2016 13:16:56 -0600 Subject: [PATCH] Move subdir removal logic into separate function Signed-off-by: Zack Cerza --- teuthology/prune.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/teuthology/prune.py b/teuthology/prune.py index 2b5114ce87..95937e1f68 100644 --- a/teuthology/prune.py +++ b/teuthology/prune.py @@ -148,11 +148,18 @@ def maybe_remove_remotes(run_dir, days, dry_run=False): if (should_preserve(item) or not os.path.isdir(item) or not is_old_enough(item, days)): continue - # Does it have a remote subdir? - remote_path = os.path.join(item, 'remote') - if not os.path.isdir(remote_path): - continue - log.info("{job} is {days} days old; removing remote logs".format( - job=item, days=days)) - if not dry_run: - remove(remote_path) + _maybe_remove_subdir(item, 'remote', days, 'remote logs', dry_run) + + +def _maybe_remove_subdir(job_dir, subdir, days, description, dry_run=False): + # Does the subdir exist? + subdir_path = os.path.join(job_dir, subdir) + if not os.path.isdir(subdir_path): + return + log.info("{job} is {days} days old; removing {desc}".format( + job=job_dir, + days=days, + desc=description, + )) + if not dry_run: + remove(subdir_path) -- 2.39.5