Properly handle config format migration.
This commit is contained in:
parent
efe1367d24
commit
636a479170
|
@ -74,22 +74,20 @@ class LadiConfiguration(SafeConfigParser):
|
|||
for k in opt:
|
||||
self.set(section, k, opt[k])
|
||||
|
||||
self.appdict = appdict
|
||||
return 0
|
||||
|
||||
def __init__ (self, args = None):
|
||||
|
||||
SafeConfigParser.__init__(self)
|
||||
self.appdict = {}
|
||||
|
||||
try:
|
||||
self.read(config_filename)
|
||||
for section in self.sections():
|
||||
self.appdict[section] = dict(self.items(section))
|
||||
except MissingSectionHeaderError:
|
||||
if yaml:
|
||||
self._migrate_configuration()
|
||||
self.save()
|
||||
if self._migrate_configuration() == 0:
|
||||
self.save()
|
||||
else: # new empty file
|
||||
pass
|
||||
# go on otherwise
|
||||
except:
|
||||
raise MalformedConfigError()
|
||||
|
@ -98,18 +96,19 @@ class LadiConfiguration(SafeConfigParser):
|
|||
"""Returns the section named <app_name> from the global configuration.
|
||||
|
||||
If the section doesn't exist, returns an empty dictionary."""
|
||||
try:
|
||||
if app_name in self.appdict:
|
||||
return self.appdict[app_name]
|
||||
else:
|
||||
return {}
|
||||
except:
|
||||
return {}
|
||||
appdict = {}
|
||||
if self.has_section(app_name):
|
||||
for opt in self.options(app_name):
|
||||
appdict[opt] = self.get(app_name, opt)
|
||||
return appdict
|
||||
|
||||
# Saves the section named <app_name> into the global config
|
||||
def set_config_section (self, app_name, param_dict):
|
||||
"""Save the section named <app_name> into the global configuration."""
|
||||
self.appdict[app_name] = param_dict
|
||||
if not self.has_section(app_name):
|
||||
self.add_section(app_name)
|
||||
for k in param_dict:
|
||||
self.set(app_name, k, str(param_dict[k]))
|
||||
|
||||
# This writes the config file to the disk
|
||||
def save (self):
|
||||
|
|
|
@ -31,7 +31,7 @@ from .. import A2jController
|
|||
from .. import LadishProxy
|
||||
|
||||
# Default launcher menu :
|
||||
menu_default = [{"Logs": "ladilog"}]
|
||||
menu_default = {"Logs": "ladilog"}
|
||||
|
||||
class LadiManager(object):
|
||||
def __init__(self, menu_config_array, jack_autostart = False):
|
||||
|
@ -44,9 +44,7 @@ class LadiManager(object):
|
|||
self.menu_array = menu_config_array
|
||||
# Add some defaults if we don't already have a menu
|
||||
if not self.menu_array:
|
||||
self.menu_array = []
|
||||
for element in menu_default:
|
||||
self.menu_array.append(element)
|
||||
self.menu_array = menu_default
|
||||
|
||||
self.proc_list = []
|
||||
|
||||
|
|
Loading…
Reference in New Issue