1
0
mirror of https://github.com/gryf/wicd.git synced 2026-03-02 23:05:54 +01:00

Merged with r242 of mainline experimental (1.6) branch.

This commit is contained in:
Andrew Psaltis
2009-01-17 15:15:14 -05:00
3 changed files with 15 additions and 12 deletions

View File

@@ -26,14 +26,15 @@ reusable for other purposes as well.
from ConfigParser import RawConfigParser from ConfigParser import RawConfigParser
from wicd.misc import stringToNone, Noneify 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): def __init__(self, path, debug=False):
RawConfigParser.__init__(self) RawConfigParser.__init__(self)
self.config_file = path self.config_file = path
self.debug = debug
self.read(path) self.read(path)
def __repr__(self): def __repr__(self):
@@ -57,8 +58,9 @@ class ConfigManager(RawConfigParser):
""" """
if not self.has_section(section): if not self.has_section(section):
self.add_section(section) self.add_section(section)
if isinstance(value, basestring):
RawConfigParser.set(self, section, str(option), str(value)) value = to_unicode(value)
RawConfigParser.set(self, section, str(option), value)
if save: if save:
self.write() self.write()
@@ -80,11 +82,13 @@ class ConfigManager(RawConfigParser):
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 default: if default:
print ''.join(['found ', option, ' in configuration ', ret]) if self.debug:
print ''.join(['found ', option, ' in configuration ',
str(ret)])
else: else:
if default != "__None__": if default != "__None__":
print ''.join(['did not find ', option, if self.debug:
' in configuration, setting default ', str(default)]) print 'did not find %s in configuration, setting default %s' % (option, str(default))
self.set(section, option, str(default), save=True) self.set(section, option, str(default), save=True)
ret = default ret = default
else: else:

View File

@@ -318,7 +318,7 @@ def get_gettext():
def to_unicode(x): def to_unicode(x):
""" Attempts to convert a string to utf-8. """ """ Attempts to convert a string to utf-8. """
# If this is a unicode string, encode it and return # If this is a unicode string, encode it and return
if type(x) not in [unicode, str]: if not isinstance(x, basestring):
return x return x
if isinstance(x, unicode): if isinstance(x, unicode):
return x.encode('utf-8') return x.encode('utf-8')

View File

@@ -471,17 +471,16 @@ class WirelessSettingsDialog(AdvancedSettingsDialog):
if encryption_info[x].get_text() == "": if encryption_info[x].get_text() == "":
error(self, language['encrypt_info_missing']) error(self, language['encrypt_info_missing'])
return False return False
self.set_net_prop(x, noneToString(encryption_info[x]. self.set_net_prop(x, noneToString(encryption_info[x].get_text()))
get_text()))
elif not self.chkbox_encryption.get_active() and \ elif not self.chkbox_encryption.get_active() and \
wireless.GetWirelessProperty(networkid, "encryption"): wireless.GetWirelessProperty(networkid, "encryption"):
error(self, language['enable_encryption']) error(self, language['enable_encryption'])
return False return False
else: else:
print 'encryption is ' + str(wireless.GetWirelessProperty(networkid,
"encryption"))
print "no encryption specified..." print "no encryption specified..."
self.set_net_prop("enctype", "None") self.set_net_prop("enctype", "None")
for x in self.encryption_info:
self.set_net_prop(x, "")
AdvancedSettingsDialog.save_settings(self) AdvancedSettingsDialog.save_settings(self)
if self.chkbox_global_settings.get_active(): if self.chkbox_global_settings.get_active():