From 824ac86d18293a22e1b4bf79ac0c98fd68d7f63e Mon Sep 17 00:00:00 2001 From: mano3m Date: Sat, 7 Dec 2013 22:11:16 +0100 Subject: [PATCH] Fix fnmatch fnmatch does not accept regular expressions as presumed in 0c4851e43608ace7c5c6243486a8eb516619c75e See http://docs.python.org/2/library/fnmatch.html This patch actually completely broke tagging. All we need to do is make sure any [ or ] used is conbverted into [[] or []]. Fixes #2557 and #2362 --- couchpotato/core/helpers/variable.py | 3 +++ couchpotato/core/plugins/renamer/main.py | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/couchpotato/core/helpers/variable.py b/couchpotato/core/helpers/variable.py index 7d35b99..1cf1f48 100644 --- a/couchpotato/core/helpers/variable.py +++ b/couchpotato/core/helpers/variable.py @@ -11,6 +11,9 @@ import sys log = CPLog(__name__) +def fnEscape(pattern): + return pattern.replace('[','[[').replace(']','[]]').replace('[[','[[]') + def link(src, dst): if os.name == 'nt': import ctypes diff --git a/couchpotato/core/plugins/renamer/main.py b/couchpotato/core/plugins/renamer/main.py index 3734845..119d82b 100755 --- a/couchpotato/core/plugins/renamer/main.py +++ b/couchpotato/core/plugins/renamer/main.py @@ -3,7 +3,7 @@ from couchpotato.api import addApiView from couchpotato.core.event import addEvent, fireEvent, fireEventAsync from couchpotato.core.helpers.encoding import toUnicode, ss, sp from couchpotato.core.helpers.variable import getExt, mergeDicts, getTitle, \ - getImdb, link, symlink, tryInt, splitString + getImdb, link, symlink, tryInt, splitString, fnEscape from couchpotato.core.logger import CPLog from couchpotato.core.plugins.base import Plugin from couchpotato.core.settings.model import Library, File, Profile, Release, \ @@ -644,7 +644,7 @@ Remove it if you want it to be renamed (again, or at least let it try again) # Match all found ignore files with the tag_files and delete if found for tag_file in tag_files: - ignore_file = fnmatch.filter(ignore_files, '%s.%s.ignore' % (re.escape(os.path.splitext(tag_file)[0]), tag if tag else '*')) + ignore_file = fnmatch.filter(ignore_files, fnEscape('%s.%s.ignore' % (os.path.splitext(tag_file)[0], tag if tag else '*'))) for filename in ignore_file: try: os.remove(filename) @@ -677,7 +677,7 @@ Remove it if you want it to be renamed (again, or at least let it try again) # Match all found ignore files with the tag_files and return True found for tag_file in tag_files: - ignore_file = fnmatch.filter(ignore_files, '%s.%s.ignore' % (os.path.splitext(tag_file)[0], tag if tag else '*')) + ignore_file = fnmatch.filter(ignore_files, fnEscape('%s.%s.ignore' % (os.path.splitext(tag_file)[0], tag if tag else '*'))) if ignore_file: return True