mirror of
https://github.com/gryf/wicd.git
synced 2026-02-02 14:15:47 +01:00
Merged with r242 of mainline experimental (1.6) branch.
This commit is contained in:
@@ -26,14 +26,15 @@ reusable for other purposes as well.
|
||||
|
||||
from ConfigParser import RawConfigParser
|
||||
|
||||
from wicd.misc import stringToNone, Noneify
|
||||
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):
|
||||
def __init__(self, path, debug=False):
|
||||
RawConfigParser.__init__(self)
|
||||
self.config_file = path
|
||||
self.debug = debug
|
||||
self.read(path)
|
||||
|
||||
def __repr__(self):
|
||||
@@ -57,8 +58,9 @@ class ConfigManager(RawConfigParser):
|
||||
"""
|
||||
if not self.has_section(section):
|
||||
self.add_section(section)
|
||||
|
||||
RawConfigParser.set(self, section, str(option), str(value))
|
||||
if isinstance(value, basestring):
|
||||
value = to_unicode(value)
|
||||
RawConfigParser.set(self, section, str(option), value)
|
||||
if save:
|
||||
self.write()
|
||||
|
||||
@@ -80,11 +82,13 @@ class ConfigManager(RawConfigParser):
|
||||
if self.has_option(section, option):
|
||||
ret = RawConfigParser.get(self, section, option)
|
||||
if default:
|
||||
print ''.join(['found ', option, ' in configuration ', ret])
|
||||
if self.debug:
|
||||
print ''.join(['found ', option, ' in configuration ',
|
||||
str(ret)])
|
||||
else:
|
||||
if default != "__None__":
|
||||
print ''.join(['did not find ', option,
|
||||
' in configuration, setting default ', str(default)])
|
||||
if self.debug:
|
||||
print 'did not find %s in configuration, setting default %s' % (option, str(default))
|
||||
self.set(section, option, str(default), save=True)
|
||||
ret = default
|
||||
else:
|
||||
|
||||
@@ -318,7 +318,7 @@ def get_gettext():
|
||||
def to_unicode(x):
|
||||
""" Attempts to convert a string to utf-8. """
|
||||
# If this is a unicode string, encode it and return
|
||||
if type(x) not in [unicode, str]:
|
||||
if not isinstance(x, basestring):
|
||||
return x
|
||||
if isinstance(x, unicode):
|
||||
return x.encode('utf-8')
|
||||
|
||||
@@ -471,17 +471,16 @@ class WirelessSettingsDialog(AdvancedSettingsDialog):
|
||||
if encryption_info[x].get_text() == "":
|
||||
error(self, language['encrypt_info_missing'])
|
||||
return False
|
||||
self.set_net_prop(x, noneToString(encryption_info[x].
|
||||
get_text()))
|
||||
self.set_net_prop(x, noneToString(encryption_info[x].get_text()))
|
||||
elif not self.chkbox_encryption.get_active() and \
|
||||
wireless.GetWirelessProperty(networkid, "encryption"):
|
||||
error(self, language['enable_encryption'])
|
||||
return False
|
||||
else:
|
||||
print 'encryption is ' + str(wireless.GetWirelessProperty(networkid,
|
||||
"encryption"))
|
||||
print "no encryption specified..."
|
||||
self.set_net_prop("enctype", "None")
|
||||
for x in self.encryption_info:
|
||||
self.set_net_prop(x, "")
|
||||
AdvancedSettingsDialog.save_settings(self)
|
||||
|
||||
if self.chkbox_global_settings.get_active():
|
||||
|
||||
Reference in New Issue
Block a user