Updating clean script for new buildbot configurations.

BUG=None
TEST=None

Review URL: https://webrtc-codereview.appspot.com/485008

git-svn-id: http://webrtc.googlecode.com/svn/trunk@2033 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
kjellander@webrtc.org 2012-04-16 14:41:11 +00:00
parent 3629a3cc0e
commit 050f212881

View File

@ -7,7 +7,7 @@
# in the file PATENTS. All contributing project authors may # in the file PATENTS. All contributing project authors may
# be found in the AUTHORS file in the root of the source tree. # be found in the AUTHORS file in the root of the source tree.
__author__ = "ivinnichenko@webrtc.org (Illya Vinnichenko)" __author__ = 'ivinnichenko@webrtc.org (Illya Vinnichenko)'
"""This script will prune sufficiently old files and empty directories. """This script will prune sufficiently old files and empty directories.
@ -26,16 +26,16 @@ import time
# The path is considered whitelisted if any of these entries appear # The path is considered whitelisted if any of these entries appear
# at some point in the path # at some point in the path
WHITELIST = ["buildbot.tac", "master.cfg", "public_html", "changes.pck", WHITELIST = ['buildbot', 'buildbot.tac', 'Makefile', 'master.cfg',
"webrtc_buildbot"] 'public_html', 'slaves.cfg', 'state.sqlite', 'twistd.pid']
def is_whitelisted(path): def is_whitelisted(path):
"""Check if file is whitelisted. '''Check if file is whitelisted.
Args: Args:
path: file path. path: file path.
""" '''
for entry in WHITELIST: for entry in WHITELIST:
if entry in path: if entry in path:
return True return True
@ -47,11 +47,11 @@ def delete_directory(directory):
os.rmdir(directory) os.rmdir(directory)
return True return True
except OSError as exception: except OSError as exception:
if "not empty" in str(exception): if 'not empty' in str(exception):
# This is normal, ignore it # This is normal, ignore it
pass pass
else: else:
print "Could not remove directory %s: reason %s." % (directory, exception) print 'Could not remove directory %s: reason %s.' % (directory, exception)
return False return False
@ -59,19 +59,19 @@ def delete_file(file):
try: try:
os.remove(file) os.remove(file)
except OSError as exception: except OSError as exception:
print "Unexpectedly failed to remove file %s: reason %s." % (file, print 'Unexpectedly failed to remove file %s: reason %s.' % (file,
exception) exception)
def log_removal(file_or_directory, time_stamp, verbose): def log_removal(file_or_directory, time_stamp, verbose):
if verbose: if verbose:
str_stamp = time.strftime("%a, %d %b %Y %H:%M:%S +0000", str_stamp = time.strftime('%a, %d %b %Y %H:%M:%S +0000',
time.gmtime(time_stamp)) time.gmtime(time_stamp))
print "Removing [%s], stamped on %s" % (file_or_directory, str_stamp) print 'Removing [%s], stamped on %s' % (file_or_directory, str_stamp)
def remove_old_files_and_directories(path, num_days, verbose, skip_dirs): def remove_old_files_and_directories(path, num_days, verbose, skip_dirs):
"""Removes all files under path that are older than num_days days. '''Removes all files under path that are older than num_days days.
The algorithm also tried to delete all directories, except for those who The algorithm also tried to delete all directories, except for those who
contain files that are sufficiently new. contain files that are sufficiently new.
@ -82,7 +82,7 @@ def remove_old_files_and_directories(path, num_days, verbose, skip_dirs):
path: The starting point. path: The starting point.
num_days: days limit for removal. num_days: days limit for removal.
verbose: print every cmd? verbose: print every cmd?
""" '''
current_time = time.time() current_time = time.time()
limit = 60 * 60 * 24 * num_days limit = 60 * 60 * 24 * num_days
@ -108,30 +108,30 @@ def remove_old_files_and_directories(path, num_days, verbose, skip_dirs):
def main(): def main():
usage = "usage: %prog -p <base path> -n <number of days> [-q] [-d]" usage = 'usage: %prog -p <base path> -n <number of days> [-q] [-d]'
parser = OptionParser(usage) parser = OptionParser(usage)
parser.add_option("-p", "--path", dest="cleanup_path", help="base directory") parser.add_option('-p', '--path', dest='cleanup_path', help='base directory')
parser.add_option("-n", "--num_days", dest="num_days", help="number of days") parser.add_option('-n', '--num_days', dest='num_days', help='number of days')
parser.add_option("-q", "--quiet", parser.add_option('-q', '--quiet',
action="store_false", dest="verbose", default=True, action='store_false', dest='verbose', default=True,
help="don't print status messages to stdout") help='do not print status messages to stdout')
parser.add_option("-d", "--delete-dirs-too", parser.add_option('-d', '--delete-dirs-too',
action="store_false", dest="skip_dirs", default=True, action='store_false', dest='skip_dirs', default=True,
help="number of days") help='number of days')
options, args = parser.parse_args() options, args = parser.parse_args()
if not options.cleanup_path: if not options.cleanup_path:
print "You must specify base directory" print 'You must specify base directory'
sys.exit(2) sys.exit(2)
if not options.num_days: if not options.num_days:
print "You must specify number of days old" print 'You must specify number of days old'
sys.exit(2) sys.exit(2)
if options.verbose: if options.verbose:
print "Cleaning up everything in %s older than %s days" % ( print 'Cleaning up everything in %s older than %s days' % (
options.cleanup_path, options.num_days) options.cleanup_path, options.num_days)
remove_old_files_and_directories(options.cleanup_path, int(options.num_days), remove_old_files_and_directories(options.cleanup_path, int(options.num_days),
options.verbose, options.skip_dirs) options.verbose, options.skip_dirs)
if __name__ == "__main__": if __name__ == '__main__':
main() main()