From 4b236c6ed690ef5f6249ce48dcf06f187a3db830 Mon Sep 17 00:00:00 2001 From: Ruud Date: Tue, 3 Jun 2014 22:25:17 +0200 Subject: [PATCH] Only cleanup source folders --- couchpotato/core/_base/_core.py | 3 ++- couchpotato/core/plugins/base.py | 20 +++++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/couchpotato/core/_base/_core.py b/couchpotato/core/_base/_core.py index ca45ceb0..91cb97e9 100644 --- a/couchpotato/core/_base/_core.py +++ b/couchpotato/core/_base/_core.py @@ -77,7 +77,8 @@ class Core(Plugin): return True def cleanUpFolders(self): - self.deleteEmptyFolder(Env.get('app_dir'), show_error = False) + only_clean = ['couchpotato', 'libs', 'init'] + self.deleteEmptyFolder(Env.get('app_dir'), show_error = False, only_clean = only_clean) def available(self, **kwargs): return { diff --git a/couchpotato/core/plugins/base.py b/couchpotato/core/plugins/base.py index dae522f4..af314bfd 100644 --- a/couchpotato/core/plugins/base.py +++ b/couchpotato/core/plugins/base.py @@ -140,13 +140,31 @@ class Plugin(object): return False - def deleteEmptyFolder(self, folder, show_error = True): + def deleteEmptyFolder(self, folder, show_error = True, only_clean = None): folder = sp(folder) + allowed_dirs = [] + if only_clean: + for item in os.listdir(folder): + full_path = os.path.join(folder, item) + if item in only_clean and os.path.isdir(full_path): + allowed_dirs.append(full_path) + for root, dirs, files in os.walk(folder): for dir_name in dirs: full_path = os.path.join(root, dir_name) + + if only_clean: + allow = False + for allowed_dir in allowed_dirs: + if allowed_dir in full_path: + allow = True + break + + if not allow: + continue + if len(os.listdir(full_path)) == 0: try: os.rmdir(full_path)