diff --git a/CHANGES.md b/CHANGES.md index e442bb0c..6802e5f6 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -28,6 +28,7 @@ [develop changelog] * Fix sorting results +* Change remove deprecated files ### 0.17.6 (2018-09-22 09:45:00 UTC) diff --git a/_cleaner.py b/_cleaner.py index 0448acda..3f52dbab 100644 --- a/_cleaner.py +++ b/_cleaner.py @@ -4,6 +4,32 @@ import os import shutil parent_dir = os.path.abspath(os.path.dirname(__file__)) +cleaned_file = os.path.abspath(os.path.join(parent_dir, '.cleaned004.tmp')) +test = os.path.abspath(os.path.join(parent_dir, 'lib', 'requests', 'packages')) +if not os.path.isfile(cleaned_file) or os.path.exists(test): + dead_dirs = [os.path.abspath(os.path.join(parent_dir, *d)) for d in [ + ('lib', 'requests', 'packages'), + ('lib', 'pynma') + ]] + + for dirpath, dirnames, filenames in os.walk(parent_dir): + for dead_dir in filter(lambda x: x in dead_dirs, [os.path.abspath(os.path.join(dirpath, d)) for d in dirnames]): + try: + shutil.rmtree(dead_dir) + except (StandardError, Exception): + pass + + for filename in [fn for fn in filenames if os.path.splitext(fn)[-1].lower() in ('.pyc', '.pyo')]: + try: + os.remove(os.path.abspath(os.path.join(dirpath, filename))) + except (StandardError, Exception): + pass + + with open(cleaned_file, 'wb') as fp: + fp.write('This file exists to prevent a rerun delete of *.pyc, *.pyo files') + fp.flush() + os.fsync(fp.fileno()) + cleaned_file = os.path.abspath(os.path.join(parent_dir, '.cleaned003.tmp')) test = os.path.abspath(os.path.join(parent_dir, 'lib', 'imdb')) if not os.path.isfile(cleaned_file) or os.path.exists(test):