def delete_folder(folder, check_empty=True): """ Removes a folder from the filesystem :param folder: Path to folder to remove :param check_empty: Boolean, check if the folder is empty before removing it, defaults to True :return: True on success, False on failure """ # check if it's a folder if not os.path.isdir(folder): return False # check if it isn't TV_DOWNLOAD_DIR if sickrage.srCore.srConfig.TV_DOWNLOAD_DIR: if real_path(folder) == real_path( sickrage.srCore.srConfig.TV_DOWNLOAD_DIR): return False # check if it's empty folder when wanted checked try: if check_empty: check_files = os.listdir(folder) if check_files: sickrage.srCore.srLogger.info( "Not deleting folder {} found the following files: {}". format(folder, check_files)) return False sickrage.srCore.srLogger.info("Deleting folder (if it's empty): " + folder) os.rmdir(folder) else: sickrage.srCore.srLogger.info("Deleting folder: " + folder) removetree(folder) except (OSError, IOError) as e: sickrage.srCore.srLogger.warning( "Warning: unable to delete folder: {}: {}".format(folder, e)) return False return True
def delete_folder(folder, check_empty=True): """ Removes a folder from the filesystem :param folder: Path to folder to remove :param check_empty: Boolean, check if the folder is empty before removing it, defaults to True :return: True on success, False on failure """ # check if it's a folder if not os.path.isdir(folder): return False # check if it isn't TV_DOWNLOAD_DIR if sickrage.app.config.tv_download_dir: if real_path(folder) == real_path(sickrage.app.config.tv_download_dir): return False # check if it's empty folder when wanted checked try: if check_empty: check_files = os.listdir(folder) if check_files: sickrage.app.log.info( "Not deleting folder {} found the following files: {}".format(folder, check_files)) return False sickrage.app.log.info("Deleting folder (if it's empty): " + folder) shutil.rmtree(folder) else: sickrage.app.log.info("Deleting folder: " + folder) shutil.rmtree(folder) except (OSError, IOError) as e: sickrage.app.log.warning("Warning: unable to delete folder: {}: {}".format(folder, e)) return False return True
def validateDir(process_path, release_name, failed, result): """ Check if directory is valid for processing :param process_path: Directory to check :param release_name: Original NZB/Torrent name :param failed: Previously failed objects :param result: Previous results :return: True if dir is valid for processing, False if not """ result.output += logHelper("Processing folder " + process_path, sickrage.app.log.DEBUG) upper_name = os.path.basename(process_path).upper() if upper_name.startswith('_FAILED_') or upper_name.endswith('_FAILED_'): result.output += logHelper("The directory name indicates it failed to extract.", sickrage.app.log.DEBUG) failed = True elif upper_name.startswith('_UNDERSIZED_') or upper_name.endswith('_UNDERSIZED_'): result.output += logHelper("The directory name indicates that it was previously rejected for being undersized.", sickrage.app.log.DEBUG) failed = True elif upper_name.startswith('_UNPACK') or upper_name.endswith('_UNPACK'): result.output += logHelper( "The directory name indicates that this release is in the process of being unpacked.", sickrage.app.log.DEBUG) result.missed_files.append("{0} : Being unpacked".format(process_path)) return False if failed: process_failed(process_path, release_name, result) result.missed_files.append("{0} : Failed download".format(process_path)) return False if sickrage.app.config.tv_download_dir and real_path(process_path) != real_path( sickrage.app.config.tv_download_dir) and is_hidden_folder(process_path): result.output += logHelper("Ignoring hidden folder: {0}".format(process_path), sickrage.app.log.DEBUG) result.missed_files.append("{0} : Hidden folder".format(process_path)) return False # make sure the dir isn't inside a show dir for show in sickrage.app.showlist: if process_path.lower().startswith(os.path.realpath(show.location).lower() + os.sep) or \ process_path.lower() == os.path.realpath(show.location).lower(): result.output += logHelper( "Cannot process an episode that's already been moved to its show dir, skipping " + process_path, sickrage.app.log.WARNING) return False for current_directory, directory_names, file_names in os.walk(process_path, topdown=False, followlinks=sickrage.app.config.processor_follow_symlinks): sync_files = filter(is_sync_file, file_names) if sync_files and sickrage.app.config.postpone_if_sync_files: result.output += logHelper("Found temporary sync files: {0} in path: {1}".format(sync_files, os.path.join(process_path, sync_files[ 0]))) result.output += logHelper("Skipping post processing for folder: {0}".format(process_path)) result.missed_files.append("{0} : Sync files found".format(os.path.join(process_path, sync_files[0]))) continue found_files = filter(is_media_file, file_names) if sickrage.app.config.unpack == 1: found_files += filter(is_rar_file, file_names) if current_directory != sickrage.app.config.tv_download_dir and found_files: found_files.append(os.path.basename(current_directory)) for found_file in found_files: try: NameParser().parse(found_file, cache_result=False) except (InvalidNameException, InvalidShowException) as e: pass else: return True result.output += logHelper("{0} : No processable items found in folder".format(process_path), sickrage.app.log.DEBUG) return False
def validateDir(self, process_path, release_name, failed): """ Check if directory is valid for processing :param process_path: Directory to check :param release_name: Original NZB/Torrent name :param failed: Previously failed objects :return: True if dir is valid for processing, False if not """ self.log("Processing folder " + process_path, sickrage.app.log.DEBUG) upper_name = os.path.basename(process_path).upper() if upper_name.startswith('_FAILED_') or upper_name.endswith('_FAILED_'): self.log("The directory name indicates it failed to extract.", sickrage.app.log.DEBUG) failed = True elif upper_name.startswith('_UNDERSIZED_') or upper_name.endswith('_UNDERSIZED_'): self.log( "The directory name indicates that it was previously rejected for being undersized.", sickrage.app.log.DEBUG) failed = True elif upper_name.startswith('_UNPACK') or upper_name.endswith('_UNPACK'): self.log( "The directory name indicates that this release is in the process of being unpacked.", sickrage.app.log.DEBUG) self.missed_files.append("{0} : Being unpacked".format(process_path)) return False if failed: self.process_failed(process_path, release_name) self.missed_files.append("{0} : Failed download".format(process_path)) return False if sickrage.app.config.tv_download_dir and real_path(process_path) != real_path( sickrage.app.config.tv_download_dir) and is_hidden_folder(process_path): self.log("Ignoring hidden folder: {0}".format(process_path), sickrage.app.log.DEBUG) self.missed_files.append("{0} : Hidden folder".format(process_path)) return False # make sure the dir isn't inside a show dir for show in get_show_list(): if process_path.lower().startswith(os.path.realpath(show.location).lower() + os.sep) or \ process_path.lower() == os.path.realpath(show.location).lower(): self.log("Cannot process an episode that's already been moved to its show dir, skipping " + process_path, sickrage.app.log.WARNING) return False for current_directory, directory_names, file_names in os.walk(process_path, topdown=False, followlinks=sickrage.app.config.processor_follow_symlinks): sync_files = list(filter(is_sync_file, file_names)) if sync_files and sickrage.app.config.postpone_if_sync_files: self.log("Found temporary sync files: {0} in path: {1}".format(sync_files, os.path.join( process_path, sync_files[ 0]))) self.log("Skipping post processing for folder: {0}".format(process_path)) self.missed_files.append("{0} : Sync files found".format(os.path.join(process_path, sync_files[0]))) continue found_files = list(filter(is_media_file, file_names)) if sickrage.app.config.unpack == 1: found_files += list(filter(is_rar_file, file_names)) if current_directory != sickrage.app.config.tv_download_dir and found_files: found_files.append(os.path.basename(current_directory)) for found_file in found_files: try: NameParser().parse(found_file, cache_result=False) except (InvalidNameException, InvalidShowException) as e: pass else: return True self.log("Folder {} : No processable items found in folder".format(process_path), sickrage.app.log.DEBUG) return False