diff options
author | Chris Craik <ccraik@google.com> | 2016-08-23 20:51:36 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2016-08-23 20:51:36 +0000 |
commit | 3bdd2133dfa9f135eaf03e7d07d22dc5cf892778 (patch) | |
tree | 8f3ada0560147845db9bb905c3812bcbd788b0cd | |
parent | 1f4523cb80916948344960b056c32045fc072fdf (diff) | |
parent | 69fd07151d23ad503a7f69b7edcd8ec5ac28942b (diff) | |
download | chromium-trace-3bdd2133dfa9f135eaf03e7d07d22dc5cf892778.tar.gz |
Merge "Prune old pyc files"
am: 69fd07151d
Change-Id: I3d5cd9d9e3156c346a7dcc1c6f7606e03822df1a
-rwxr-xr-x | systrace.py | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/systrace.py b/systrace.py index d96c67a0..71da6500 100755 --- a/systrace.py +++ b/systrace.py @@ -17,7 +17,33 @@ systrace_dir = os.path.abspath( os.path.join(os.path.dirname(__file__), 'catapult', 'systrace')) sys.path.insert(0, systrace_dir) -from systrace import run_systrace +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 '.git' in dirname: + continue + for filename in filenames: + root, ext = os.path.splitext(filename) + if ext != '.pyc': + continue + + pyc_path = os.path.join(dirname, filename) + py_path = os.path.join(dirname, root + '.py') + + try: + if not os.path.exists(py_path): + os.remove(pyc_path) + except OSError: + # Wrap OS calls in try/except in case another process touched this file. + pass + + try: + os.removedirs(dirname) + except OSError: + # Wrap OS calls in try/except in case another process touched this dir. + pass if __name__ == '__main__': + RemoveAllStalePycFiles(os.path.dirname(__file__)) + from systrace import run_systrace sys.exit(run_systrace.main()) |