From 0d4d0f3126fa451aadb8097f13617eccfeb79ac2 Mon Sep 17 00:00:00 2001 From: Ruud Date: Sun, 9 Feb 2014 18:29:17 +0100 Subject: [PATCH] scandir --- couchpotato/core/_base/updater/main.py | 7 ++++--- couchpotato/core/downloaders/rtorrent/main.py | 3 ++- couchpotato/core/plugins/renamer/main.py | 17 +++++++++-------- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/couchpotato/core/_base/updater/main.py b/couchpotato/core/_base/updater/main.py index ef595ad7..4f96e929 100644 --- a/couchpotato/core/_base/updater/main.py +++ b/couchpotato/core/_base/updater/main.py @@ -13,6 +13,7 @@ import shutil import tarfile import time import traceback +from scandir import scandir import version import zipfile from six.moves import filter @@ -160,7 +161,7 @@ class BaseUpdater(Plugin): def deletePyc(self, only_excess = True): - for root, dirs, files in os.walk(ss(Env.get('app_dir'))): + for root, dirs, files in scandir.walk(ss(Env.get('app_dir'))): pyc_files = filter(lambda filename: filename.endswith('.pyc'), files) py_files = set(filter(lambda filename: filename.endswith('.py'), files)) @@ -308,11 +309,11 @@ class SourceUpdater(BaseUpdater): # Get list of files we want to overwrite self.deletePyc() existing_files = [] - for root, subfiles, filenames in os.walk(app_dir): + for root, subfiles, filenames in scandir.walk(app_dir): for filename in filenames: existing_files.append(os.path.join(root, filename)) - for root, subfiles, filenames in os.walk(path): + for root, subfiles, filenames in scandir.walk(path): for filename in filenames: fromfile = os.path.join(root, filename) tofile = os.path.join(app_dir, fromfile.replace(path + os.path.sep, '')) diff --git a/couchpotato/core/downloaders/rtorrent/main.py b/couchpotato/core/downloaders/rtorrent/main.py index 27177756..994980e8 100755 --- a/couchpotato/core/downloaders/rtorrent/main.py +++ b/couchpotato/core/downloaders/rtorrent/main.py @@ -10,6 +10,7 @@ from hashlib import sha1 from rtorrent import RTorrent from rtorrent.err import MethodError import os +from scandir import scandir log = CPLog(__name__) @@ -242,7 +243,7 @@ class rTorrent(Downloader): if torrent.is_multi_file() and torrent.directory.endswith(torrent.name): # Remove empty directories bottom up try: - for path, _, _ in os.walk(torrent.directory, topdown = False): + for path, _, _ in scandir.walk(torrent.directory, topdown = False): os.rmdir(path) except OSError: log.info('Directory "%s" contains extra files, unable to remove', torrent.directory) diff --git a/couchpotato/core/plugins/renamer/main.py b/couchpotato/core/plugins/renamer/main.py index 8cc14c97..42ec78fc 100755 --- a/couchpotato/core/plugins/renamer/main.py +++ b/couchpotato/core/plugins/renamer/main.py @@ -9,6 +9,7 @@ from couchpotato.core.plugins.base import Plugin from couchpotato.core.settings.model import Library, File, Profile, \ ReleaseInfo from couchpotato.environment import Env +from scandir import scandir from unrar2 import RarFile import errno import fnmatch @@ -186,7 +187,7 @@ class Renamer(Plugin): else: # Get all files from the specified folder try: - for root, folders, names in os.walk(media_folder): + for root, folders, names in scandir.walk(media_folder): files.extend([sp(os.path.join(root, name)) for name in names]) except: log.error('Failed getting files from %s: %s', (media_folder, traceback.format_exc())) @@ -635,7 +636,7 @@ Remove it if you want it to be renamed (again, or at least let it try again) # Tag all files in release folder else: - for root, folders, names in os.walk(release_download['folder']): + for root, folders, names in scandir.walk(release_download['folder']): tag_files.extend([os.path.join(root, name) for name in names]) for filename in tag_files: @@ -670,7 +671,7 @@ Remove it if you want it to be renamed (again, or at least let it try again) # Untag all files in release folder else: - for root, folders, names in os.walk(release_download['folder']): + for root, folders, names in scandir.walk(release_download['folder']): tag_files.extend([sp(os.path.join(root, name)) for name in names if not os.path.splitext(name)[1] == '.ignore']) folder = release_download['folder'] @@ -682,7 +683,7 @@ Remove it if you want it to be renamed (again, or at least let it try again) # Find all .ignore files in folder ignore_files = [] - for root, dirnames, filenames in os.walk(folder): + for root, dirnames, filenames in scandir.walk(folder): ignore_files.extend(fnmatch.filter([sp(os.path.join(root, filename)) for filename in filenames], '*%s.ignore' % tag)) # Match all found ignore files with the tag_files and delete if found @@ -711,11 +712,11 @@ Remove it if you want it to be renamed (again, or at least let it try again) # Find tag on all files in release folder else: - for root, folders, names in os.walk(release_download['folder']): + for root, folders, names in scandir.walk(release_download['folder']): tag_files.extend([sp(os.path.join(root, name)) for name in names if not os.path.splitext(name)[1] == '.ignore']) # Find all .ignore files in folder - for root, dirnames, filenames in os.walk(folder): + for root, dirnames, filenames in scandir.walk(folder): ignore_files.extend(fnmatch.filter([sp(os.path.join(root, filename)) for filename in filenames], '*%s.ignore' % tag)) # Match all found ignore files with the tag_files and return True found @@ -818,7 +819,7 @@ Remove it if you want it to be renamed (again, or at least let it try again) folder = sp(folder) loge = log.error if show_error else log.debug - for root, dirs, files in os.walk(folder): + for root, dirs, files in scandir.walk(folder): for dir_name in dirs: full_path = os.path.join(root, dir_name) @@ -1102,7 +1103,7 @@ Remove it if you want it to be renamed (again, or at least let it try again) check_file_date = False if not files: - for root, folders, names in os.walk(folder): + for root, folders, names in scandir.walk(folder): files.extend([sp(os.path.join(root, name)) for name in names]) # Find all archive files