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'):
# Disable core autoadd
self.core_cfg['autoadd_enable'] = False
self.core_cfg.save()
# Check if core autoadd folder is already added in plugin
for watchdir in self.watchdirs:
if os.path.abspath(self.core_cfg['autoadd_location']) == watchdir['abspath']:
watchdir['enabled'] = True
break
else:
# didn't find core watchdir, add it
@ -130,7 +132,7 @@ class Core(CorePluginBase):
def set_options(self, watchdir_id, options):
"""Update the options for a watch folder."""
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."))
if options.has_key('path'):
options['abspath'] = os.path.abspath(options['path'])
@ -194,7 +196,6 @@ class Core(CorePluginBase):
if OPTIONS_AVAILABLE.get(option):
if watchdir.get(option+'_toggle', True):
opts[option] = value
opts = self._clean_unicode(opts)
for filename in os.listdir(watchdir["abspath"]):
if filename.split(".")[-1] == "torrent":
try:
@ -276,6 +277,7 @@ class Core(CorePluginBase):
@export
def set_config(self, config):
"""Sets the config dictionary."""
config = self._make_unicode(config)
for key in config.keys():
self.config[key] = config[key]
self.config.save()
@ -290,20 +292,18 @@ class Core(CorePluginBase):
def get_watchdirs(self):
return self.watchdirs.keys()
def _clean_unicode(self, options):
def _make_unicode(self, options):
opts = {}
for key, value in options.iteritems():
if isinstance(key, unicode):
key = str(key)
if isinstance(value, unicode):
value = str(value)
opts[key] = value
for key in options:
if isinstance(options[key], str):
options[key] = unicode(options[key], "utf8")
opts[key] = options[key]
return opts
@export()
def add(self, options={}):
"""Add a watch folder."""
options = self._clean_unicode(options)
options = self._make_unicode(options)
abswatchdir = os.path.abspath(options['path'])
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.")