Permalink
Browse files

Support [ui] section in configuration file. And some small clean-ups …

…of config.py.

Some future questions:
 + Should we really overwrite the config file?
 + Should all config sections be implemented as dicts such as UiConfig?
  • Loading branch information...
1 parent cf42f4c commit 7852b1f78809a4a67d990fc5676eb9961def1edd @sliem sliem committed Jul 27, 2011
Showing with 15 additions and 15 deletions.
  1. +15 −15 dandelionpy/dandelion/config.py
View
30 dandelionpy/dandelion/config.py
@@ -68,13 +68,9 @@ def load(self, confparser):
# TODO for python 3.2; replace with fallback arg.
if confparser.has_option(ServerConfig._SECTION_NAME, ServerConfig._PORT_NAME):
self._port = confparser.getint(ServerConfig._SECTION_NAME, ServerConfig._PORT_NAME)
- else:
- self._port = ServerConfig._PORT_DEFAULT
if confparser.has_option(ServerConfig._SECTION_NAME, ServerConfig._IP_NAME):
self._ip = confparser.get(ServerConfig._SECTION_NAME, ServerConfig._IP_NAME)
- else:
- self._ip = ServerConfig._IP_DEFAULT
def store(self, confparser):
confparser.add_section(ServerConfig._SECTION_NAME)
@@ -240,18 +236,25 @@ def __getitem__(self, key):
return self.uidict[key]
def __setitem__(self, key, value):
- self.uidict[key] = value #?
+ self.uidict[key] = value
-
- # load tillräcklig för att ladda confparsers configs om de finns??
def load(self, confparser):
if not confparser.has_section(UiConfig._SECTION_NAME):
#raise ConfigException
confparser.add_section(UiConfig._SECTION_NAME)
+ for key in confparser[UiConfig._SECTION_NAME]:
+ if key in self.uidict:
+ self.uidict[key] = confparser[UiConfig._SECTION_NAME][key]
+ else:
+ pass # TODO complain in a user friendly way
+
def store(self, confparser):
confparser.add_section(UiConfig._SECTION_NAME)
+ for key in self.uidict:
+ confparser.set(UiConfig._SECTION_NAME, key, self.uidict[key])
+
class IdentityConfig(Config):
_SECTION_NAME = 'identity'
@@ -269,13 +272,8 @@ def store(self, confparser):
class ConfigManager:
- def __init__(self, config_file=None):
-
- if config_file is None:
- self._cfg_file_name = 'dandelion.conf'
- else:
- self._cfg_file_name = config_file
-
+ def __init__(self, config_file='dandelion.conf'):
+ self._cfg_file_name = config_file
self._server_config = ServerConfig()
self._synchronizer_config = SynchronizerConfig()
self._discoverer_config = DiscovererConfig()
@@ -325,7 +323,8 @@ def write_file(self):
confparser = configparser.ConfigParser()
self._server_config.store(confparser)
-
+ self._ui_config.store(confparser)
+
with open(self._cfg_file_name, 'w') as configfile:
confparser.write(configfile)
@@ -335,3 +334,4 @@ def read_file(self):
confparser.read(self._cfg_file_name)
self._server_config.load(confparser)
+ self._ui_config.load(confparser)

0 comments on commit 7852b1f

Please sign in to comment.