From 742bf5f8ced362906b1c5621ee2365653973806b Mon Sep 17 00:00:00 2001 From: Dan O'Reilly Date: Sat, 13 Dec 2008 17:32:54 -0500 Subject: [PATCH 1/2] Use RawConfigParser instead of ConfigParser --- wicd/configmanager.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/wicd/configmanager.py b/wicd/configmanager.py index 4b2844a..90b0c6f 100644 --- a/wicd/configmanager.py +++ b/wicd/configmanager.py @@ -24,15 +24,15 @@ reusable for other purposes as well. # along with this program. If not, see . # -from ConfigParser import ConfigParser +from ConfigParser import RawConfigParser from wicd.misc import stringToNone -class ConfigManager(ConfigParser): +class ConfigManager(RawConfigParser): """ A class that can be used to manage a given configuration file. """ def __init__(self, path): - ConfigParser.__init__(self) + RawConfigParser.__init__(self) self.config_file = path self.read(path) @@ -58,7 +58,7 @@ class ConfigManager(ConfigParser): if not self.has_section(section): self.add_section(section) - ConfigParser.set(self, section, str(option), str(value)) + RawConfigParser.set(self, section, str(option), str(value)) if save: self.write() @@ -78,7 +78,7 @@ class ConfigManager(ConfigParser): self.add_section(section) if self.has_option(section, option): - ret = ConfigParser.get(self, section, option) + ret = RawConfigParser.get(self, section, option) if default: print ''.join(['found ', option, ' in configuration ', ret]) else: @@ -101,7 +101,7 @@ class ConfigManager(ConfigParser): def write(self): """ Writes the loaded config file to disk. """ configfile = open(self.config_file, 'w') - ConfigParser.write(self, configfile) + RawConfigParser.write(self, configfile) configfile.close() def remove_section(self,section): @@ -112,7 +112,7 @@ class ConfigManager(ConfigParser): """ if self.has_section(section): - ConfigParser.remove_section(self, section) + RawConfigParser.remove_section(self, section) def reload(self): self.read(self.config_file) From 41c975a22a3869d603e6f0878fb9a98f49676b4f Mon Sep 17 00:00:00 2001 From: Dan O'Reilly Date: Sat, 13 Dec 2008 19:39:15 -0500 Subject: [PATCH 2/2] Make sure autoconnect.py never blocks Tweak configmanager to not write a default value unless one is specified in the get call. --- wicd/autoconnect.py | 14 ++++++-------- wicd/configmanager.py | 11 +++++++---- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/wicd/autoconnect.py b/wicd/autoconnect.py index 546daf7..472a2d1 100755 --- a/wicd/autoconnect.py +++ b/wicd/autoconnect.py @@ -20,25 +20,23 @@ import dbus import time import gobject +import sys from dbus.mainloop.glib import DBusGMainLoop DBusGMainLoop(set_as_default=True) bus = dbus.SystemBus() proxy_obj = bus.get_object('org.wicd.daemon', '/org/wicd/daemon') daemon = dbus.Interface(proxy_obj, 'org.wicd.daemon') +loop = gobject.MainLoop() -def reply_handle(): - loop.quit() -def error_handle(e): + +def handler(*args): loop.quit() print daemon.Hello() time.sleep(3) daemon.SetSuspend(False) if not daemon.CheckIfConnecting(): - print daemon.AutoConnect(True, reply_handler=reply_handle, - error_handler=error_handle) daemon.SetForcedDisconnect(False) - -loop = gobject.MainLoop() -loop.run() + daemon.AutoConnect(True, reply_handler=handler, error_handler=handler) + diff --git a/wicd/configmanager.py b/wicd/configmanager.py index 90b0c6f..2b130a9 100644 --- a/wicd/configmanager.py +++ b/wicd/configmanager.py @@ -66,7 +66,7 @@ class ConfigManager(RawConfigParser): """ Calls the set_option method. """ self.set_option(*args, **kargs) - def get_option(self, section, option, default=None): + def get_option(self, section, option, default="__None__"): """ Wrapper around ConfigParser.get. Automatically adds any missing sections, adds the ability @@ -82,10 +82,13 @@ class ConfigManager(RawConfigParser): if default: print ''.join(['found ', option, ' in configuration ', ret]) else: - print ''.join(['did not find ', option, + if default != "__None__": + print ''.join(['did not find ', option, ' in configuration, setting default ', str(default)]) - self.set(section, option, str(default), save=True) - ret = default + self.set(section, option, str(default), save=True) + ret = default + else: + ret = None # Try to intelligently handle the type of the return value. try: