| # Copyright 2014 The Chromium Authors. All rights reserved. |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| def RemoveAllStalePycFiles(base_dir): |
| """Scan directories for old .pyc files without a .py file and delete them.""" |
| for dirname, _, filenames in os.walk(base_dir): |
| if '.svn' in dirname or '.git' in dirname: |
| for filename in filenames: |
| root, ext = os.path.splitext(filename) |
| pyc_path = os.path.join(dirname, filename) |
| py_path = os.path.join(dirname, root + '.py') |
| if not os.path.exists(py_path): |
| # Wrap OS calls in try/except in case another process touched this file. |
| # Wrap OS calls in try/except in case another process touched this dir. |
| if __name__ == '__main__': |
| for path in sys.argv[1:]: |
| RemoveAllStalePycFiles(path) |