Encoding file paths
This commit is contained in:
1 parent
469d4abcb0
commit
5b2f1248e0
4 files changed
+18
-26
No files matched your search
@@ -1,5 +1,6 @@
|
|||||||
from couchpotato.api import addApiView
|
from couchpotato.api import addApiView
|
||||||
from couchpotato.core.event import addEvent, fireEvent, fireEventAsync
|
from couchpotato.core.event import addEvent, fireEvent, fireEventAsync
|
||||||
|
from couchpotato.core.helpers.encoding import ss
|
||||||
from couchpotato.core.helpers.request import jsonified
|
from couchpotato.core.helpers.request import jsonified
|
||||||
from couchpotato.core.logger import CPLog
|
from couchpotato.core.logger import CPLog
|
||||||
from couchpotato.core.plugins.base import Plugin
|
from couchpotato.core.plugins.base import Plugin
|
||||||
@@ -120,7 +121,7 @@ class BaseUpdater(Plugin):
|
|||||||
|
|
||||||
def deletePyc(self, only_excess = True):
|
def deletePyc(self, only_excess = True):
|
||||||
|
|
||||||
for root, dirs, files in os.walk(Env.get('app_dir')):
|
for root, dirs, files in os.walk(ss(Env.get('app_dir'))):
|
||||||
|
|
||||||
pyc_files = filter(lambda filename: filename.endswith('.pyc'), files)
|
pyc_files = filter(lambda filename: filename.endswith('.pyc'), files)
|
||||||
py_files = set(filter(lambda filename: filename.endswith('.py'), files))
|
py_files = set(filter(lambda filename: filename.endswith('.py'), files))
|
||||||
@@ -269,7 +270,7 @@ class SourceUpdater(BaseUpdater):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
def replaceWith(self, path):
|
def replaceWith(self, path):
|
||||||
app_dir = Env.get('app_dir')
|
app_dir = ss(Env.get('app_dir'))
|
||||||
|
|
||||||
# Get list of files we want to overwrite
|
# Get list of files we want to overwrite
|
||||||
self.deletePyc(only_excess = False)
|
self.deletePyc(only_excess = False)
|
||||||
|
|||||||
@@ -35,6 +35,10 @@ def toUnicode(original, *args):
|
|||||||
ascii_text = str(original).encode('string_escape')
|
ascii_text = str(original).encode('string_escape')
|
||||||
return toUnicode(ascii_text)
|
return toUnicode(ascii_text)
|
||||||
|
|
||||||
|
def ss(original, *args):
|
||||||
|
from couchpotato.environment import Env
|
||||||
|
return toUnicode(original, *args).encode(Env.get('encoding'))
|
||||||
|
|
||||||
def ek(original, *args):
|
def ek(original, *args):
|
||||||
if isinstance(original, (str, unicode)):
|
if isinstance(original, (str, unicode)):
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -34,34 +34,30 @@ class CPLog(object):
|
|||||||
|
|
||||||
def safeMessage(self, msg, replace_tuple = ()):
|
def safeMessage(self, msg, replace_tuple = ()):
|
||||||
|
|
||||||
if not hasattr(self, 'Env'):
|
from couchpotato.environment import Env
|
||||||
from couchpotato.environment import Env
|
from couchpotato.core.helpers.encoding import ss
|
||||||
from couchpotato.core.helpers.encoding import toUnicode
|
|
||||||
|
|
||||||
self.Env = Env
|
msg = ss(msg)
|
||||||
self.toUnicode = toUnicode
|
|
||||||
|
|
||||||
msg = self.toUnicode(msg)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
msg = msg % replace_tuple
|
msg = msg % replace_tuple
|
||||||
except:
|
except:
|
||||||
try:
|
try:
|
||||||
if isinstance(replace_tuple, tuple):
|
if isinstance(replace_tuple, tuple):
|
||||||
msg = msg % tuple([self.toUnicode(x).encode(self.Env.get('encoding')) for x in list(replace_tuple)])
|
msg = msg % tuple([ss(x) for x in list(replace_tuple)])
|
||||||
else:
|
else:
|
||||||
msg = msg % self.toUnicode(replace_tuple).encode(self.Env.get('encoding'))
|
msg = msg % ss(replace_tuple)
|
||||||
except:
|
except:
|
||||||
self.error('Failed encoding stuff to log: %s' % traceback.format_exc())
|
self.error('Failed encoding stuff to log: %s' % traceback.format_exc())
|
||||||
|
|
||||||
if not self.Env.get('dev'):
|
if not Env.get('dev'):
|
||||||
|
|
||||||
for replace in self.replace_private:
|
for replace in self.replace_private:
|
||||||
msg = re.sub('(%s=)[^\&]+' % replace, '%s=xxx' % replace, msg)
|
msg = re.sub('(%s=)[^\&]+' % replace, '%s=xxx' % replace, msg)
|
||||||
|
|
||||||
# Replace api key
|
# Replace api key
|
||||||
try:
|
try:
|
||||||
api_key = self.Env.setting('api_key')
|
api_key = Env.setting('api_key')
|
||||||
if api_key:
|
if api_key:
|
||||||
msg = msg.replace(api_key, 'API_KEY')
|
msg = msg.replace(api_key, 'API_KEY')
|
||||||
except:
|
except:
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
from couchpotato import get_session
|
from couchpotato import get_session
|
||||||
from couchpotato.core.event import fireEvent, addEvent
|
from couchpotato.core.event import fireEvent, addEvent
|
||||||
from couchpotato.core.helpers.encoding import toUnicode, simplifyString
|
from couchpotato.core.helpers.encoding import toUnicode, simplifyString, ss
|
||||||
from couchpotato.core.helpers.variable import getExt, getImdb, tryInt
|
from couchpotato.core.helpers.variable import getExt, getImdb, tryInt
|
||||||
from couchpotato.core.logger import CPLog
|
from couchpotato.core.logger import CPLog
|
||||||
from couchpotato.core.plugins.base import Plugin
|
from couchpotato.core.plugins.base import Plugin
|
||||||
from couchpotato.core.settings.model import File, Movie
|
from couchpotato.core.settings.model import File, Movie
|
||||||
from couchpotato.environment import Env
|
|
||||||
from enzyme.exceptions import NoParserError, ParseError
|
from enzyme.exceptions import NoParserError, ParseError
|
||||||
from guessit import guess_movie_info
|
from guessit import guess_movie_info
|
||||||
from subliminal.videos import Video
|
from subliminal.videos import Video
|
||||||
@@ -133,7 +132,7 @@ class Scanner(Plugin):
|
|||||||
|
|
||||||
def scan(self, folder = None, files = [], simple = False, newer_than = 0):
|
def scan(self, folder = None, files = [], simple = False, newer_than = 0):
|
||||||
|
|
||||||
folder = os.path.normpath(folder)
|
folder = ss(os.path.normpath(folder))
|
||||||
|
|
||||||
if not folder or not os.path.isdir(folder):
|
if not folder or not os.path.isdir(folder):
|
||||||
log.error('Folder doesn\'t exists: %s', folder)
|
log.error('Folder doesn\'t exists: %s', folder)
|
||||||
@@ -147,19 +146,11 @@ class Scanner(Plugin):
|
|||||||
if len(files) == 0:
|
if len(files) == 0:
|
||||||
try:
|
try:
|
||||||
files = []
|
files = []
|
||||||
for root, dirs, walk_files in os.walk(toUnicode(folder)):
|
for root, dirs, walk_files in os.walk(folder):
|
||||||
for filename in walk_files:
|
for filename in walk_files:
|
||||||
files.append(os.path.join(root, filename))
|
files.append(os.path.join(root, filename))
|
||||||
except:
|
except:
|
||||||
try:
|
log.error('Failed getting files from %s: %s', (folder, traceback.format_exc()))
|
||||||
files = []
|
|
||||||
folder = toUnicode(folder).encode(Env.get('encoding'))
|
|
||||||
log.info('Trying to convert unicode to str path: %s, %s', (folder, type(folder)))
|
|
||||||
for root, dirs, walk_files in os.walk(folder):
|
|
||||||
for filename in walk_files:
|
|
||||||
files.append(os.path.join(root, filename))
|
|
||||||
except:
|
|
||||||
log.error('Failed getting files from %s: %s', (folder, traceback.format_exc()))
|
|
||||||
|
|
||||||
db = get_session()
|
db = get_session()
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user