Skip to content

Commit

Permalink
Merge pull request #388 from phw/PICARD-642-config-upgrade-error
Browse files Browse the repository at this point in the history
Fix errors during configuration update when reading obsolete options.
  • Loading branch information
zas committed Dec 18, 2014
2 parents 055a1ba + c78cce5 commit 0e43410
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
24 changes: 14 additions & 10 deletions picard/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,10 @@ def __init__(self, config, name):
self.__name = name

def __getitem__(self, name):
key = "%s/%s" % (self.__name, name)
opt = Option.get(self.__name, name)
if opt is None:
return None
self.lock_for_read()
try:
if self.__config.contains(key):
return opt.convert(self.raw_value(name))
return opt.default
except:
return opt.default
finally:
self.unlock()
return self.value(name, opt, opt.default)

def __setitem__(self, name, value):
self.lock_for_write()
Expand Down Expand Up @@ -82,6 +73,19 @@ def raw_value(self, key):

return value

def value(self, name, type, default=None):
"""Return an option value converted to the given Option type."""
key = "%s/%s" % (self.__name, name)
self.lock_for_read()
try:
if self.__config.contains(key):
return type.convert(self.raw_value(name))
return default
except:
return default
finally:
self.unlock()


class Config(QtCore.QSettings):

Expand Down
8 changes: 4 additions & 4 deletions picard/config_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def remove_va_file_naming_format(merge=True):
_s["file_naming_format"] = (
"$if($eq(%%compilation%%,1),\n$noop(Various Artist "
"albums)\n%s,\n$noop(Single Artist Albums)\n%s)" % (
_s["va_file_naming_format"],
_s.value("va_file_naming_format", config.TextOption),
_s["file_naming_format"]
))
_s.remove("va_file_naming_format")
Expand All @@ -52,7 +52,7 @@ def remove_va_file_naming_format(merge=True):
if ("va_file_naming_format" in _s and "use_va_format" in _s):
msgbox = QtGui.QMessageBox()

if _s["use_va_format"].toBool():
if _s.value("use_va_format", config.BoolOption):
remove_va_file_naming_format()
msgbox.information(msgbox,
_("Various Artists file naming scheme removal"),
Expand All @@ -62,7 +62,7 @@ def remove_va_file_naming_format(merge=True):
"merged with that of single artist albums."),
QtGui.QMessageBox.Ok)

elif (_s["va_file_naming_format"] !=
elif (_s.value("va_file_naming_format", config.TextOption) !=
r"$if2(%albumartist%,%artist%)/%album%/$if($gt(%totaldis"
"cs%,1),%discnumber%-,)$num(%tracknumber%,2) %artist% - "
"%title%"):
Expand Down Expand Up @@ -92,7 +92,7 @@ def upgrade_to_v1_3_0_dev_1():
old_opt = "windows_compatible_filenames"
new_opt = "windows_compatibility"
if old_opt in _s:
_s[new_opt] = _s[old_opt]
_s[new_opt] = _s.value(old_opt, config.BoolOption, True)
_s.remove(old_opt)


Expand Down

0 comments on commit 0e43410

Please sign in to comment.