Browse Source

Cleaner empty dir cleanup

pull/3362/head
Ruud 11 years ago
parent
commit
ab2b2cfe6e
  1. 20
      couchpotato/core/plugins/base.py

20
couchpotato/core/plugins/base.py

@ -143,28 +143,16 @@ class Plugin(object):
def deleteEmptyFolder(self, folder, show_error = True, only_clean = None): def deleteEmptyFolder(self, folder, show_error = True, only_clean = None):
folder = sp(folder) folder = sp(folder)
allowed_dirs = []
if only_clean:
for item in os.listdir(folder): for item in os.listdir(folder):
full_path = os.path.join(folder, item) full_folder = 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): if not only_clean or (item in only_clean and os.path.isdir(full_folder)):
for root, dirs, files in os.walk(full_folder):
for dir_name in dirs: for dir_name in dirs:
full_path = os.path.join(root, dir_name) 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: if len(os.listdir(full_path)) == 0:
try: try:
os.rmdir(full_path) os.rmdir(full_path)

Loading…
Cancel
Save