From f6d7579859833d69f682bb1a62c07a780fb4ebd5 Mon Sep 17 00:00:00 2001 From: Dan O'Reilly Date: Tue, 20 Jan 2009 00:32:56 -0500 Subject: [PATCH] Add support for writing config data with whitespace kept intact. Propgate debug setting to the ConfigManager instances. Don't write essid key sections to the config file if we're not actually using them. --- wicd/configmanager.py | 14 ++++++++++++-- wicd/wicd-daemon.py | 33 ++++++++++++++++++++++++++++----- 2 files changed, 40 insertions(+), 7 deletions(-) diff --git a/wicd/configmanager.py b/wicd/configmanager.py index b636678..29d4320 100644 --- a/wicd/configmanager.py +++ b/wicd/configmanager.py @@ -31,10 +31,11 @@ from wicd.misc import stringToNone, Noneify, to_unicode class ConfigManager(RawConfigParser): """ A class that can be used to manage a given configuration file. """ - def __init__(self, path, debug=False): + def __init__(self, path, debug=False, mark_whitespace="`'`"): RawConfigParser.__init__(self) self.config_file = path self.debug = debug + self.mrk_ws = mark_whitespace self.read(path) def __repr__(self): @@ -60,6 +61,9 @@ class ConfigManager(RawConfigParser): self.add_section(section) if isinstance(value, basestring): value = to_unicode(value) + if value.startswith(' ') or value.endswith(' '): + value = "%(ws)s%(value)s%(ws)s" % {"value" : value, + "ws" : self.mrk_ws} RawConfigParser.set(self, section, str(option), value) if save: self.write() @@ -77,10 +81,16 @@ class ConfigManager(RawConfigParser): """ if not self.has_section(section): - self.add_section(section) + if default != "__None__": + self.add_section(section) + else: + return None if self.has_option(section, option): ret = RawConfigParser.get(self, section, option) + if (isinstance(ret, basestring) and ret.startswith(self.mrk_ws) + and ret.endswith(self.mrk_ws)): + ret = ret[3:-3] if default: if self.debug: print ''.join(['found ', option, ' in configuration ', diff --git a/wicd/wicd-daemon.py b/wicd/wicd-daemon.py index 8087c87..8fb98bb 100644 --- a/wicd/wicd-daemon.py +++ b/wicd/wicd-daemon.py @@ -91,7 +91,7 @@ class WicdDaemon(dbus.service.Object): self.vpn_session = None self.gui_open = False self.suspended = False - self.debug_mode = False + self._debug_mode = False self.connection_state = misc.NOT_CONNECTED self.connection_info = [""] self.auto_connecting = False @@ -123,6 +123,13 @@ class WicdDaemon(dbus.service.Object): self.SetForcedDisconnect(True) print "--no-autoconnect detected, not autoconnecting..." + def get_debug_mode(self): + return self._debug_mode + def set_debug_mode(self, mode): + self._debug_mode = mode + self.config.debug = mode + debug_mode = property(get_debug_mode, set_debug_mode) + @dbus.service.method('org.wicd.daemon') def Hello(self): """ Returns the version number. @@ -874,10 +881,18 @@ class WirelessDaemon(dbus.service.Object): self.hidden_essid = None self.daemon = daemon self.wifi = wifi - self.debug_mode = debug + self._debug_mode = debug self.forced_disconnect = False self.config = ConfigManager(os.path.join(wpath.etc, - "wireless-settings.conf")) + "wireless-settings.conf"), + debug=debug) + + def get_debug_mode(self): + return self._debug_mode + def set_debug_mode(self, mode): + self._debug_mode = mode + self.config.debug = mode + debug_mode = property(get_debug_mode, set_debug_mode) @dbus.service.method('org.wicd.daemon.wireless') def SetHiddenNetworkESSID(self, essid): @@ -1223,11 +1238,19 @@ class WiredDaemon(dbus.service.Object): object_path="/org/wicd/daemon/wired") self.daemon = daemon self.wired = wired - self.debug_mode = debug + self._debug_mode = debug self.forced_disconnect = False self.WiredNetwork = {} self.config = ConfigManager(os.path.join(wpath.etc, - "wired-settings.conf")) + "wired-settings.conf"), + debug=debug) + + def get_debug_mode(self): + return self._debug_mode + def set_debug_mode(self, mode): + self._debug_mode = mode + self.config.debug = mode + debug_mode = property(get_debug_mode, set_debug_mode) @dbus.service.method('org.wicd.daemon.wired') def GetWiredIP(self, ifconfig=""):