From 06f0be97b5a1880c70def283893fdf474508ad5e Mon Sep 17 00:00:00 2001 From: JackDandy Date: Sun, 23 Sep 2018 23:16:51 +0100 Subject: [PATCH] Change remove deprecated files. --- CHANGES.md | 1 + _cleaner.py | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) 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):