aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Reck <jreck@google.com>2016-08-23 20:49:28 +0000
committerandroid-build-merger <android-build-merger@google.com>2016-08-23 20:49:28 +0000
commit0b63bd97ed180a8d1d59db00157e0f346d9b14ed (patch)
tree8f3ada0560147845db9bb905c3812bcbd788b0cd
parentd671d0289c80543d9b3bc4ba8171fb221027946e (diff)
parent2e44c74d3278196387157aabbb816ee8e66eb1fa (diff)
downloadchromium-trace-0b63bd97ed180a8d1d59db00157e0f346d9b14ed.tar.gz
Prune old pyc files am: b1cc17c51c
am: 2e44c74d32 Change-Id: If01357ed60ce2e67bf0e2a827eade3d400ec509d
-rwxr-xr-xsystrace.py28
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())