mirror of
https://github.com/gryf/wicd.git
synced 2026-01-31 21:15:51 +01:00
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.
This commit is contained in:
@@ -31,10 +31,11 @@ from wicd.misc import stringToNone, Noneify, to_unicode
|
|||||||
|
|
||||||
class ConfigManager(RawConfigParser):
|
class ConfigManager(RawConfigParser):
|
||||||
""" A class that can be used to manage a given configuration file. """
|
""" 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)
|
RawConfigParser.__init__(self)
|
||||||
self.config_file = path
|
self.config_file = path
|
||||||
self.debug = debug
|
self.debug = debug
|
||||||
|
self.mrk_ws = mark_whitespace
|
||||||
self.read(path)
|
self.read(path)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
@@ -60,6 +61,9 @@ class ConfigManager(RawConfigParser):
|
|||||||
self.add_section(section)
|
self.add_section(section)
|
||||||
if isinstance(value, basestring):
|
if isinstance(value, basestring):
|
||||||
value = to_unicode(value)
|
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)
|
RawConfigParser.set(self, section, str(option), value)
|
||||||
if save:
|
if save:
|
||||||
self.write()
|
self.write()
|
||||||
@@ -77,10 +81,16 @@ class ConfigManager(RawConfigParser):
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
if not self.has_section(section):
|
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):
|
if self.has_option(section, option):
|
||||||
ret = RawConfigParser.get(self, 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 default:
|
||||||
if self.debug:
|
if self.debug:
|
||||||
print ''.join(['found ', option, ' in configuration ',
|
print ''.join(['found ', option, ' in configuration ',
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ class WicdDaemon(dbus.service.Object):
|
|||||||
self.vpn_session = None
|
self.vpn_session = None
|
||||||
self.gui_open = False
|
self.gui_open = False
|
||||||
self.suspended = False
|
self.suspended = False
|
||||||
self.debug_mode = False
|
self._debug_mode = False
|
||||||
self.connection_state = misc.NOT_CONNECTED
|
self.connection_state = misc.NOT_CONNECTED
|
||||||
self.connection_info = [""]
|
self.connection_info = [""]
|
||||||
self.auto_connecting = False
|
self.auto_connecting = False
|
||||||
@@ -123,6 +123,13 @@ class WicdDaemon(dbus.service.Object):
|
|||||||
self.SetForcedDisconnect(True)
|
self.SetForcedDisconnect(True)
|
||||||
print "--no-autoconnect detected, not autoconnecting..."
|
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')
|
@dbus.service.method('org.wicd.daemon')
|
||||||
def Hello(self):
|
def Hello(self):
|
||||||
""" Returns the version number.
|
""" Returns the version number.
|
||||||
@@ -874,10 +881,18 @@ class WirelessDaemon(dbus.service.Object):
|
|||||||
self.hidden_essid = None
|
self.hidden_essid = None
|
||||||
self.daemon = daemon
|
self.daemon = daemon
|
||||||
self.wifi = wifi
|
self.wifi = wifi
|
||||||
self.debug_mode = debug
|
self._debug_mode = debug
|
||||||
self.forced_disconnect = False
|
self.forced_disconnect = False
|
||||||
self.config = ConfigManager(os.path.join(wpath.etc,
|
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')
|
@dbus.service.method('org.wicd.daemon.wireless')
|
||||||
def SetHiddenNetworkESSID(self, essid):
|
def SetHiddenNetworkESSID(self, essid):
|
||||||
@@ -1223,11 +1238,19 @@ class WiredDaemon(dbus.service.Object):
|
|||||||
object_path="/org/wicd/daemon/wired")
|
object_path="/org/wicd/daemon/wired")
|
||||||
self.daemon = daemon
|
self.daemon = daemon
|
||||||
self.wired = wired
|
self.wired = wired
|
||||||
self.debug_mode = debug
|
self._debug_mode = debug
|
||||||
self.forced_disconnect = False
|
self.forced_disconnect = False
|
||||||
self.WiredNetwork = {}
|
self.WiredNetwork = {}
|
||||||
self.config = ConfigManager(os.path.join(wpath.etc,
|
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')
|
@dbus.service.method('org.wicd.daemon.wired')
|
||||||
def GetWiredIP(self, ifconfig=""):
|
def GetWiredIP(self, ifconfig=""):
|
||||||
|
|||||||
Reference in New Issue
Block a user