Unicode os.walk as backup
This commit is contained in:
@@ -5,6 +5,7 @@ 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
|
from couchpotato.core.settings.model import File
|
||||||
|
from couchpotato.environment import Env
|
||||||
from enzyme.exceptions import NoParserError, ParseError
|
from enzyme.exceptions import NoParserError, ParseError
|
||||||
import enzyme
|
import enzyme
|
||||||
import logging
|
import logging
|
||||||
@@ -143,10 +144,21 @@ class Scanner(Plugin):
|
|||||||
|
|
||||||
# Scan all files of the folder if no files are set
|
# Scan all files of the folder if no files are set
|
||||||
if len(files) == 0:
|
if len(files) == 0:
|
||||||
files = []
|
try:
|
||||||
for root, dirs, walk_files in os.walk(toUnicode(folder)):
|
files = []
|
||||||
for filename in walk_files:
|
for root, dirs, walk_files in os.walk(toUnicode(folder)):
|
||||||
files.append(os.path.join(root, filename))
|
for filename in walk_files:
|
||||||
|
files.append(os.path.join(root, filename))
|
||||||
|
except:
|
||||||
|
try:
|
||||||
|
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()))
|
||||||
|
|
||||||
for file_path in files:
|
for file_path in files:
|
||||||
|
|
||||||
@@ -287,9 +299,9 @@ class Scanner(Plugin):
|
|||||||
break
|
break
|
||||||
|
|
||||||
# Leftover "sorted" files
|
# Leftover "sorted" files
|
||||||
for type in group['files']:
|
for file_type in group['files']:
|
||||||
if not type is 'leftover':
|
if not file_type is 'leftover':
|
||||||
group['files']['leftover'] -= set(group['files'][type])
|
group['files']['leftover'] -= set(group['files'][file_type])
|
||||||
|
|
||||||
# Delete the unsorted list
|
# Delete the unsorted list
|
||||||
del group['unsorted_files']
|
del group['unsorted_files']
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ class Settings(object):
|
|||||||
return tryInt(self.p.get(section, option))
|
return tryInt(self.p.get(section, option))
|
||||||
|
|
||||||
def getUnicode(self, section, option):
|
def getUnicode(self, section, option):
|
||||||
value = self.p.get(section, option)
|
value = self.p.get(section, option).decode('unicode_escape')
|
||||||
return toUnicode(value).strip()
|
return toUnicode(value).strip()
|
||||||
|
|
||||||
def getValues(self):
|
def getValues(self):
|
||||||
@@ -153,7 +153,7 @@ class Settings(object):
|
|||||||
# See if a value handler is attached, use that as value
|
# See if a value handler is attached, use that as value
|
||||||
new_value = fireEvent('setting.save.%s.%s' % (section, option), value, single = True)
|
new_value = fireEvent('setting.save.%s.%s' % (section, option), value, single = True)
|
||||||
|
|
||||||
self.set(section, option, new_value if new_value else value)
|
self.set(section, option, (new_value if new_value else value).encode('unicode_escape'))
|
||||||
self.save()
|
self.save()
|
||||||
|
|
||||||
return jsonified({
|
return jsonified({
|
||||||
|
|||||||
Reference in New Issue
Block a user