1
0
mirror of https://github.com/gryf/wicd.git synced 2025-12-20 04:48:00 +01:00

Experimental/Testing:

- Improved behavior in the networking backend.  The wired/wireless wnettools instances now refer to each other, and get passed on to connection threads as well, which simplifies passing settings for external program usage.  Also removed some unecessary creating of duplicate wnettools instances which ended up causing some issues.
- Fixed bug where dhclient was being used as the dhcp client even if it was selected in the options menu.
- Fixed a typo in the connection commands used for ralink cards.
- Fixed the wrong cli option for releasing a dhcpcd lease.
- Monitor.py no longer calls for an auto-rescan if the daemon is currently connecting to a network.
- Cleaned up some comments and simplified the logic in a few methods/functions.
This commit is contained in:
imdano
2008-06-19 22:09:39 +00:00
parent 86bcc8f795
commit 05a59fb5db
6 changed files with 53 additions and 32 deletions

View File

@@ -155,9 +155,10 @@ class ConnectionWizard(dbus.service.Object):
# Make a variable that will hold the wired network profile # Make a variable that will hold the wired network profile
self.WiredNetwork = {} self.WiredNetwork = {}
# Load our wired/wireless interfaces # Kind of hackish way to load the secondary wnettools interface
self.wifi.LoadInterfaces() # for both wired and wireless connection managers.
self.wired.LoadInterfaces() self.wifi.liface = self.wired.liface
self.wired.wiface = self.wifi.wiface
# Scan since we just got started # Scan since we just got started
if auto_connect: if auto_connect:
@@ -590,6 +591,7 @@ class ConnectionWizard(dbus.service.Object):
@dbus.service.method('org.wicd.daemon') @dbus.service.method('org.wicd.daemon')
def SetDHCPClient(self, client): def SetDHCPClient(self, client):
print "Setting dhcp client to %i" % (int(client))
self.dhcp_client = int(client) self.dhcp_client = int(client)
self.wifi.dhcp_client = int(client) self.wifi.dhcp_client = int(client)
self.wired.dhcp_client = int(client) self.wired.dhcp_client = int(client)

2
gui.py
View File

@@ -382,7 +382,7 @@ class appGui:
dhclientradio = self.wTree.get_widget("dhclient_radio") dhclientradio = self.wTree.get_widget("dhclient_radio")
pumpradio = self.wTree.get_widget("pump_radio") pumpradio = self.wTree.get_widget("pump_radio")
dhcpcdradio = self.wTree.get_widget("dhcpcd_radio") dhcpcdradio = self.wTree.get_widget("dhcpcd_radio")
dhcp_list = [dhcpautoradio, dhclientradio, pumpradio, dhcpcdradio] dhcp_list = [dhcpautoradio, dhclientradio, dhcpcdradio, pumpradio]
dhcp_method = daemon.GetDHCPClient() dhcp_method = daemon.GetDHCPClient()
dhcp_list[dhcp_method].set_active(True) dhcp_list[dhcp_method].set_active(True)

11
misc.py
View File

@@ -283,14 +283,11 @@ 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. """
try: # This may never fail, but let's be safe try: # This may never fail, but let's be safe
default_encoding = locale.getpreferredencoding() encoding = locale.getpreferredencoding()
except: except:
default_encoding = None # Just guess utf-8 if it fails.
encoding = 'utf-8'
if default_encoding: ret = x.decode(encoding, 'replace').encode('utf-8')
ret = x.decode(default_encoding, 'replace').encode('utf-8')
else: # Just guess UTF-8
ret = x.decode('utf-8', 'replace').encode('utf-8')
return ret return ret
def RenameProcess(new_name): def RenameProcess(new_name):

View File

@@ -260,7 +260,7 @@ class ConnectionStatus():
def rescan_networks(self): def rescan_networks(self):
""" Calls a wireless scan. """ """ Calls a wireless scan. """
try: try:
if daemon.GetSuspend(): if daemon.GetSuspend() or daemon.CheckIfConnecting():
return True return True
wireless.Scan() wireless.Scan()
daemon.SendScanSignal() daemon.SendScanSignal()

View File

@@ -103,8 +103,10 @@ class Controller(object):
self._dhcp_client = value self._dhcp_client = value
if self.wiface: if self.wiface:
self.wiface.DHCP_CLIENT = value self.wiface.DHCP_CLIENT = value
self.wiface.CheckDHCP()
if self.liface: if self.liface:
self.liface.DHCP_CLIENT = value self.liface.DHCP_CLIENT = value
self.liface.CheckDHCP()
def get_dhcp_client(self): def get_dhcp_client(self):
return self._dhcp_client return self._dhcp_client
@@ -140,7 +142,7 @@ class ConnectThread(threading.Thread):
lock = thread.allocate_lock() lock = thread.allocate_lock()
def __init__(self, network, wireless, wired, before_script, after_script, def __init__(self, network, wireless, wired, before_script, after_script,
disconnect_script, gdns1, gdns2, gdns3, debug): disconnect_script, gdns1, gdns2, gdns3, wiface, liface, debug):
""" Initialise the required object variables and the thread. """ Initialise the required object variables and the thread.
Keyword arguments: Keyword arguments:
@@ -173,6 +175,9 @@ class ConnectThread(threading.Thread):
self.global_dns_2 = gdns2 self.global_dns_2 = gdns2
self.global_dns_3 = gdns3 self.global_dns_3 = gdns3
self.wiface = wiface
self.liface = liface
self.connecting_message = None self.connecting_message = None
self.debug = debug self.debug = debug
@@ -391,7 +396,8 @@ class Wireless(Controller):
self.wireless_interface, self.wired_interface, self.wireless_interface, self.wired_interface,
self.wpa_driver, self.before_script, self.after_script, self.wpa_driver, self.before_script, self.after_script,
self.disconnect_script, self.global_dns_1, self.disconnect_script, self.global_dns_1,
self.global_dns_2, self.global_dns_3, debug) self.global_dns_2, self.global_dns_3, self.wiface, self.liface,
debug)
self.connecting_thread.setDaemon(True) self.connecting_thread.setDaemon(True)
self.connecting_thread.start() self.connecting_thread.start()
return True return True
@@ -570,7 +576,7 @@ class WirelessConnectThread(ConnectThread):
def __init__(self, network, wireless, wired, wpa_driver, def __init__(self, network, wireless, wired, wpa_driver,
before_script, after_script, disconnect_script, gdns1, before_script, after_script, disconnect_script, gdns1,
gdns2, gdns3, debug=False): gdns2, gdns3, wiface, liface, debug=False):
""" Initialise the thread with network information. """ Initialise the thread with network information.
Keyword arguments: Keyword arguments:
@@ -588,7 +594,7 @@ class WirelessConnectThread(ConnectThread):
""" """
ConnectThread.__init__(self, network, wireless, wired, ConnectThread.__init__(self, network, wireless, wired,
before_script, after_script, disconnect_script, gdns1, before_script, after_script, disconnect_script, gdns1,
gdns2, gdns3, debug) gdns2, gdns3, wiface, liface, debug)
self.wpa_driver = wpa_driver self.wpa_driver = wpa_driver
@@ -606,9 +612,8 @@ class WirelessConnectThread(ConnectThread):
5. Get/set IP address and DNS servers. 5. Get/set IP address and DNS servers.
""" """
wiface = wnettools.WirelessInterface(self.wireless_interface, wiface = self.wiface
self.debug, self.wpa_driver) liface = self.liface
liface = wnettools.WiredInterface(self.wired_interface, self.debug)
self.is_connecting = True self.is_connecting = True
# Run pre-connection script. # Run pre-connection script.
@@ -747,7 +752,7 @@ class Wired(Controller):
self.wireless_interface, self.wired_interface, self.wireless_interface, self.wired_interface,
self.before_script, self.after_script, self.before_script, self.after_script,
self.disconnect_script, self.global_dns_1, self.disconnect_script, self.global_dns_1,
self.global_dns_2, self.global_dns_3, debug) self.global_dns_2, self.global_dns_3, wiface, liface, debug)
self.connecting_thread.setDaemon(True) self.connecting_thread.setDaemon(True)
self.connecting_thread.start() self.connecting_thread.start()
return True return True
@@ -809,7 +814,7 @@ class WiredConnectThread(ConnectThread):
""" """
def __init__(self, network, wireless, wired, def __init__(self, network, wireless, wired,
before_script, after_script, disconnect_script, gdns1, before_script, after_script, disconnect_script, gdns1,
gdns2, gdns3, debug=False): gdns2, gdns3, wiface, liface, debug=False):
""" Initialise the thread with network information. """ Initialise the thread with network information.
Keyword arguments: Keyword arguments:
@@ -826,7 +831,7 @@ class WiredConnectThread(ConnectThread):
""" """
ConnectThread.__init__(self, network, wireless, wired, ConnectThread.__init__(self, network, wireless, wired,
before_script, after_script, disconnect_script, gdns1, before_script, after_script, disconnect_script, gdns1,
gdns2, gdns3, debug) gdns2, gdns3, wiface, liface, debug)
def run(self): def run(self):
""" The main function of the connection thread. """ The main function of the connection thread.
@@ -842,8 +847,8 @@ class WiredConnectThread(ConnectThread):
5. Run post-connection script. 5. Run post-connection script.
""" """
wiface = wnettools.WirelessInterface(self.wireless_interface, self.debug) wiface = self.wiface
liface = wnettools.WiredInterface(self.wired_interface, self.debug) liface = self.liface
self.is_connecting = True self.is_connecting = True

View File

@@ -239,15 +239,31 @@ class Interface(object):
def CheckDHCP(self): def CheckDHCP(self):
""" Check for a valid DHCP client. """ Check for a valid DHCP client.
Checks for the existence of a support DHCP client. If one is Checks for the existence of a supported DHCP client. If one is
found, the appropriate values for DHCP_CMD, DHCP_RELEASE, and found, the appropriate values for DHCP_CMD, DHCP_RELEASE, and
DHCP_CLIENT are set. If a supported client is not found, a DHCP_CLIENT are set. If a supported client is not found, a
warning is printed. warning is printed.
""" """
if self.DHCP_CLIENT: def get_client_name(cl):
dhcp_client = self.DHCP_CLIENT """ Converts the integer value for a dhcp client to a string. """
if cl in [misc.DHCLIENT, "dhclient"]:
client = "dhclient"
elif cl in [misc.DHCPCD, "dhcpcd"]:
client = "dhcpcd"
else: else:
client = "pump"
return client
print 'checking dhcp...'
if self.DHCP_CLIENT:
dhcp_client = get_client_name(self.DHCP_CLIENT)
dhcp_path = self._find_client_path(dhcp_client)
if not dhcp_path:
print "WARNING: Could not find selected dhcp client. Wicd " + \
" will try to find another supported client."
if not self.DHCP_CLIENT or not dhcp_path:
dhcp_client = None dhcp_client = None
dhcp_path = None dhcp_path = None
dhcpclients = ["dhclient", "dhcpcd", "pump"] dhcpclients = ["dhclient", "dhcpcd", "pump"]
@@ -271,7 +287,7 @@ class Interface(object):
elif dhcp_client in [misc.DHCPCD, "dhcpcd"]: elif dhcp_client in [misc.DHCPCD, "dhcpcd"]:
dhcp_client = misc.DHCPCD dhcp_client = misc.DHCPCD
dhcp_cmd = dhcp_path dhcp_cmd = dhcp_path
dhcp_release = dhcp_cmd + " -r" dhcp_release = dhcp_cmd + " -k"
else: else:
dhcp_client = None dhcp_client = None
dhcp_cmd = None dhcp_cmd = None
@@ -1126,7 +1142,7 @@ class WirelessInterface(Interface):
cmd_list = [] cmd_list = []
cmd_list.append('NetworkType=' + info[6]) cmd_list.append('NetworkType=' + info[6])
cmd_list.append('AuthMode=' + auth_mode) cmd_list.append('AuthMode=' + auth_mode)
cmd_list.append('EncryptType=' + info[4]) cmd_list.append('EncrypType=' + info[4])
cmd_list.append('SSID=' + info[2]) cmd_list.append('SSID=' + info[2])
cmd_list.append(key_name + '=' + network.get('key')) cmd_list.append(key_name + '=' + network.get('key'))
if info[5] == 'SHARED' and info[4] == 'WEP': if info[5] == 'SHARED' and info[4] == 'WEP':
@@ -1207,6 +1223,7 @@ class WirelessInterface(Interface):
if self.verbose: if self.verbose:
print "SIOCGIWRANGE failed: " + str(e) print "SIOCGIWRANGE failed: " + str(e)
return None return None
# This defines the iwfreq struct, used to get singal strength.
fmt = "iiihb6ii4B4Bi32i2i2i2i2i3h8h2b2bhi8i2b3h2i2ihB17x" + 32 * "ihbb" fmt = "iiihb6ii4B4Bi32i2i2i2i2i3h8h2b2bhi8i2b3h2i2ihB17x" + 32 * "ihbb"
size = struct.calcsize(fmt) size = struct.calcsize(fmt)
data = buff.tostring() data = buff.tostring()