From 84e75ec59decd6ef9a55d00d8197100d6873f239 Mon Sep 17 00:00:00 2001 From: echel0n Date: Thu, 27 Mar 2014 15:42:12 -0700 Subject: [PATCH] Added back in the code to clean up SB's cache files after a set amount of days have passed --- sickbeard/showUpdater.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/sickbeard/showUpdater.py b/sickbeard/showUpdater.py index 7e8156dc..34f944cc 100644 --- a/sickbeard/showUpdater.py +++ b/sickbeard/showUpdater.py @@ -51,6 +51,35 @@ class ShowUpdater(): else: return + # clean out cache directory, remove everything > 12 hours old + if sickbeard.CACHE_DIR: + for indexer in sickbeard.indexerApi().indexers: + cache_dir = sickbeard.indexerApi(indexer).cache + logger.log(u"Trying to clean cache folder " + cache_dir) + + # Does our cache_dir exists + if not ek.ek(os.path.isdir, cache_dir): + logger.log(u"Can't clean " + cache_dir + " if it doesn't exist", logger.WARNING) + else: + max_age = datetime.timedelta(hours=12) + # Get all our cache files + cache_files = ek.ek(os.listdir, cache_dir) + + for cache_file in cache_files: + cache_file_path = ek.ek(os.path.join, cache_dir, cache_file) + + if ek.ek(os.path.isfile, cache_file_path): + cache_file_modified = datetime.datetime.fromtimestamp( + ek.ek(os.path.getmtime, cache_file_path)) + + if update_datetime - cache_file_modified > max_age: + try: + ek.ek(os.remove, cache_file_path) + except OSError, e: + logger.log(u"Unable to clean " + cache_dir + ": " + repr(e) + " / " + str(e), + logger.WARNING) + break + # select 10 'Ended' tv_shows updated more than 90 days ago to include in this update stale_should_update = [] stale_update_date = (update_date - datetime.timedelta(days=90)).toordinal()