
Use //third_party/pywebsocket instead. * tools/remove_stale_pyc_files.py We should walk in bottom-up order in order to remove nested directories containing only *.pyc. Change-Id: I7adff11285218025ab80f4f8e1a8fc9d039c4385 Reviewed-on: https://chromium-review.googlesource.com/1004567 Reviewed-by: Adam Rice <ricea@chromium.org> Reviewed-by: Nico Weber <thakis@chromium.org> Commit-Queue: Kent Tamura <tkent@chromium.org> Cr-Commit-Position: refs/heads/master@{#550924}
40 lines
1.1 KiB
Python
Executable File
40 lines
1.1 KiB
Python
Executable File
#!/usr/bin/env python
|
|
# 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.
|
|
|
|
import os
|
|
import sys
|
|
|
|
|
|
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, topdown=False):
|
|
if '.svn' in dirname or '.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__':
|
|
for path in sys.argv[1:]:
|
|
RemoveAllStalePycFiles(path)
|