diff options
author | Han Shen <shenhan@chromium.org> | 2014-04-23 11:05:22 -0700 |
---|---|---|
committer | chrome-internal-fetch <chrome-internal-fetch@google.com> | 2014-04-24 08:35:00 +0000 |
commit | a58a824b41a0121439794cd8a2392364e4d6975c (patch) | |
tree | 5a24201561bcccd4523397d19ac46f34fdc283d3 /auto_delete_nightly_test_data.py | |
parent | f4220a30480a945c93d6fdf6fb5853b3ba36c6d1 (diff) | |
download | toolchain-utils-a58a824b41a0121439794cd8a2392364e4d6975c.tar.gz |
Add necessary output to auto_delete_nightly_test_data script and return with meaning exit code.
The script did not have any output in case of a success run, which
means we do not get emails about this cron job. Also the exit code was
always 0. Fixed by adding print statements and return correct exit
code.
TEST=None
BUG=None
Change-Id: If06a4d57a94387494f9c1b30fea765f66e6e0f56
Reviewed-on: https://chrome-internal-review.googlesource.com/161302
Reviewed-by: Caroline Tice <cmtice@google.com>
Commit-Queue: Han Shen <shenhan@google.com>
Tested-by: Han Shen <shenhan@google.com>
Diffstat (limited to 'auto_delete_nightly_test_data.py')
-rwxr-xr-x | auto_delete_nightly_test_data.py | 39 |
1 files changed, 31 insertions, 8 deletions
diff --git a/auto_delete_nightly_test_data.py b/auto_delete_nightly_test_data.py index 86f8e558..f990f125 100755 --- a/auto_delete_nightly_test_data.py +++ b/auto_delete_nightly_test_data.py @@ -6,6 +6,7 @@ __author__ = 'shenhan@google.com (Han Shen)' import datetime import optparse import os +import re import sys from utils import command_executer @@ -20,29 +21,50 @@ def CleanNumberedDir(s, dry_run=False): chromeos_dirs = [os.path.join(s, x) for x in os.listdir(s) if misc.IsChromeOsTree(os.path.join(s, x))] ce = command_executer.GetCommandExecuter() + all_succeeded = True for cd in chromeos_dirs: - misc.DeleteChromeOsTree(cd, dry_run=dry_run) - ## Now delete the numbered dir + if misc.DeleteChromeOsTree(cd, dry_run=dry_run): + print 'Successfully removed chromeos tree "{0}".'.format(cd) + else: + all_succeeded = False + print 'Failed to remove chromeos tree "{0}", please check.'.format(cd) + + ## Now delete the numbered dir Before forcibly removing the directory, just + ## check 's' to make sure it is sane. + if not re.search('^' + constants.CROSTC_WORKSPACE + '/(' + + '|'.join(DIR_BY_WEEKDAY) + ')', s): + print 'Trying to delete an invalid dir, please check.' + return False + cmd = 'rm -fr {0}'.format(s) if dry_run: print cmd else: - ce.RunCommand(cmd, return_output=True, terminated_timeout=480) + if ce.RunCommand(cmd, return_output=False, print_to_console=True, + terminated_timeout=480) == 0: + print 'Successfully removed "{0}".'.format(s) + else: + all_succeeded = False + print 'Failed to remove "{0}", please check.'.format(s) + return all_succeeded def CleanDatedDir(dated_dir, dry_run=False): # List subdirs under dir subdirs = [os.path.join(dated_dir, x) for x in os.listdir(dated_dir) if os.path.isdir(os.path.join(dated_dir, x))] + all_succeeded = True for s in subdirs: - CleanNumberedDir(s, dry_run) + if not CleanNumberedDir(s, dry_run): + all_succeeded = False + return all_succeeded def ProcessArguments(argv): """Process arguments.""" parser = optparse.OptionParser( description='Automatically delete nightly test data directories.', - usage='auto_delete.py options') + usage='auto_delete_nightly_test_data.py options') parser.add_option('-d', '--dry_run', dest='dry_run', default=False, action='store_true', help='Only print command line, do not execute anything.') @@ -63,6 +85,7 @@ def Main(argv): # options.days_to_preserve away from today. s = d - 7 e = d - options.days_to_preserve + rv = 0 for i in range(s + 1, e): if i <= 0: ## Wrap around if index is negative. 6 is from i + 7 - 1, because @@ -70,9 +93,9 @@ def Main(argv): dated_dir = DIR_BY_WEEKDAY[i+6] else: dated_dir = DIR_BY_WEEKDAY[i-1] - CleanDatedDir(os.path.join( - constants.CROSTC_WORKSPACE, dated_dir), options.dry_run) - return 0 + rv += 0 if CleanDatedDir(os.path.join( + constants.CROSTC_WORKSPACE, dated_dir), options.dry_run) else 1 + return rv if __name__ == '__main__': |