OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2014 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. |
| 5 |
| 6 """Delete files in directories matching a pattern. |
| 7 """ |
| 8 |
| 9 import glob |
| 10 import optparse |
| 11 import os |
| 12 import shutil |
| 13 import sys |
| 14 |
| 15 from util import build_utils |
| 16 |
| 17 def main(): |
| 18 parser = optparse.OptionParser() |
| 19 parser.add_option( |
| 20 '--stamp', |
| 21 help='File to touch when deletion is done.') |
| 22 parser.add_option( |
| 23 '--pattern', |
| 24 help='Pattern for matching Files to delete.') |
| 25 parser.add_option( |
| 26 '--keep', |
| 27 help='Files to keep even if they matches the pattern.') |
| 28 |
| 29 options, args = parser.parse_args() |
| 30 |
| 31 if not options.pattern or not args: |
| 32 print 'No --pattern or target directories given' |
| 33 return |
| 34 |
| 35 for target_dir in args: |
| 36 target_pattern = os.path.join(target_dir, options.pattern) |
| 37 matching_files = glob.glob(target_pattern) |
| 38 |
| 39 keep_pattern = os.path.join(target_dir, options.keep) |
| 40 files_to_keep = glob.glob(keep_pattern) |
| 41 |
| 42 for target_file in matching_files: |
| 43 if target_file in files_to_keep: |
| 44 continue |
| 45 |
| 46 if os.path.isfile(target_file): |
| 47 print "Deleting %s ..." % target_file |
| 48 os.remove(target_file) |
| 49 |
| 50 if options.stamp: |
| 51 build_utils.Touch(options.stamp) |
| 52 |
| 53 if __name__ == '__main__': |
| 54 sys.exit(main()) |
| 55 |
OLD | NEW |