Fix bugs with unicode torrents in AutoAdd plugin.

This commit is contained in:
Chase Sterling 2010-09-13 02:20:06 -04:00
parent 3e2f6c4060
commit d898def9ec
1 changed files with 11 additions and 11 deletions

View File

@ -102,9 +102,11 @@ class Core(CorePluginBase):
if self.core_cfg.config.get('autoadd_enable'): if self.core_cfg.config.get('autoadd_enable'):
# Disable core autoadd # Disable core autoadd
self.core_cfg['autoadd_enable'] = False self.core_cfg['autoadd_enable'] = False
self.core_cfg.save()
# Check if core autoadd folder is already added in plugin # Check if core autoadd folder is already added in plugin
for watchdir in self.watchdirs: for watchdir in self.watchdirs:
if os.path.abspath(self.core_cfg['autoadd_location']) == watchdir['abspath']: if os.path.abspath(self.core_cfg['autoadd_location']) == watchdir['abspath']:
watchdir['enabled'] = True
break break
else: else:
# didn't find core watchdir, add it # didn't find core watchdir, add it
@ -130,7 +132,7 @@ class Core(CorePluginBase):
def set_options(self, watchdir_id, options): def set_options(self, watchdir_id, options):
"""Update the options for a watch folder.""" """Update the options for a watch folder."""
watchdir_id = str(watchdir_id) watchdir_id = str(watchdir_id)
options = self._clean_unicode(options) options = self._make_unicode(options)
CheckInput(watchdir_id in self.watchdirs , _("Watch folder does not exist.")) CheckInput(watchdir_id in self.watchdirs , _("Watch folder does not exist."))
if options.has_key('path'): if options.has_key('path'):
options['abspath'] = os.path.abspath(options['path']) options['abspath'] = os.path.abspath(options['path'])
@ -194,7 +196,6 @@ class Core(CorePluginBase):
if OPTIONS_AVAILABLE.get(option): if OPTIONS_AVAILABLE.get(option):
if watchdir.get(option+'_toggle', True): if watchdir.get(option+'_toggle', True):
opts[option] = value opts[option] = value
opts = self._clean_unicode(opts)
for filename in os.listdir(watchdir["abspath"]): for filename in os.listdir(watchdir["abspath"]):
if filename.split(".")[-1] == "torrent": if filename.split(".")[-1] == "torrent":
try: try:
@ -276,6 +277,7 @@ class Core(CorePluginBase):
@export @export
def set_config(self, config): def set_config(self, config):
"""Sets the config dictionary.""" """Sets the config dictionary."""
config = self._make_unicode(config)
for key in config.keys(): for key in config.keys():
self.config[key] = config[key] self.config[key] = config[key]
self.config.save() self.config.save()
@ -290,20 +292,18 @@ class Core(CorePluginBase):
def get_watchdirs(self): def get_watchdirs(self):
return self.watchdirs.keys() return self.watchdirs.keys()
def _clean_unicode(self, options): def _make_unicode(self, options):
opts = {} opts = {}
for key, value in options.iteritems(): for key in options:
if isinstance(key, unicode): if isinstance(options[key], str):
key = str(key) options[key] = unicode(options[key], "utf8")
if isinstance(value, unicode): opts[key] = options[key]
value = str(value)
opts[key] = value
return opts return opts
@export() @export()
def add(self, options={}): def add(self, options={}):
"""Add a watch folder.""" """Add a watch folder."""
options = self._clean_unicode(options) options = self._make_unicode(options)
abswatchdir = os.path.abspath(options['path']) abswatchdir = os.path.abspath(options['path'])
CheckInput(os.path.isdir(abswatchdir) , _("Path does not exist.")) CheckInput(os.path.isdir(abswatchdir) , _("Path does not exist."))
CheckInput(os.access(abswatchdir, os.R_OK|os.W_OK), "You must have read and write access to watch folder.") CheckInput(os.access(abswatchdir, os.R_OK|os.W_OK), "You must have read and write access to watch folder.")