| 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 """Python utility to detect invalid SKPs and remove from local dir.""" |
| 7 |
| 8 import glob |
| 9 import optparse |
| 10 import os |
| 11 import sys |
| 12 |
| 13 # Set the PYTHONPATH for this script to include shell_utils. |
| 14 sys.path.append( |
| 15 os.path.join(os.path.dirname(os.path.realpath(__file__)), os.pardir, |
| 16 os.pardir, os.pardir, 'slave', 'skia_slave_scripts')) |
| 17 from utils import shell_utils |
| 18 |
| 19 |
| 20 def IsSKPValid(path_to_skp, path_to_skpinfo): |
| 21 """Calls the skpinfo binary to see if the specified SKP is valid.""" |
| 22 skp_info_cmd = [path_to_skpinfo, '-i', path_to_skp] |
| 23 try: |
| 24 shell_utils.run(skp_info_cmd) |
| 25 return True |
| 26 except shell_utils.CommandFailedException: |
| 27 # Mark SKP as invalid if the skpinfo command gives a non 0 ret code. |
| 28 return False |
| 29 |
| 30 |
| 31 def RemoveInvalidSKPs(skp_dir, path_to_skpinfo): |
| 32 """Removes invalid SKPs from the provided local dir.""" |
| 33 invalid_skps = [] |
| 34 for path_to_skp in glob.glob(os.path.join(skp_dir, '*.skp')): |
| 35 if not IsSKPValid(path_to_skp, path_to_skpinfo): |
| 36 print '=====%s is invalid!=====' % path_to_skp |
| 37 invalid_skps.append(path_to_skp) |
| 38 # Delete the SKP from the local path. |
| 39 os.remove(path_to_skp) |
| 40 |
| 41 if invalid_skps: |
| 42 print '\n\n=====Deleted the following SKPs:=====' |
| 43 for invalid_skp in invalid_skps: |
| 44 print invalid_skp |
| 45 |
| 46 |
| 47 if '__main__' == __name__: |
| 48 option_parser = optparse.OptionParser() |
| 49 option_parser.add_option( |
| 50 '', '--skp_dir', help='Directory that contains the SKPs we want to check.') |
| 51 option_parser.add_option( |
| 52 '', '--path_to_skpinfo', help='Complete path to the skpinfo binary.') |
| 53 |
| 54 options, unused_args = option_parser.parse_args() |
| 55 if not (options.skp_dir and options.path_to_skpinfo): |
| 56 option_parser.error('Music specify skp_dir and path_to_skpinfo') |
| 57 |
| 58 RemoveInvalidSKPs(skp_dir=options.skp_dir, |
| 59 path_to_skpinfo=options.path_to_skpinfo) |
| 60 |
| OLD | NEW |