From ec8eade509fb5d25140e143330b2e531818b4b60 Mon Sep 17 00:00:00 2001 From: Dan O'Reilly Date: Fri, 28 Aug 2009 19:47:55 -0400 Subject: [PATCH] Wait for the network interface to finish coming up before moving on during the connection process. Use a dict instead of if/elifs in StartDHCP() method. --- wicd/networking.py | 10 +++++++++- wicd/wnettools.py | 23 ++++++++++++----------- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/wicd/networking.py b/wicd/networking.py index 1269e5c..ea6620b 100644 --- a/wicd/networking.py +++ b/wicd/networking.py @@ -526,6 +526,14 @@ class ConnectThread(threading.Thread): print 'Putting interface up...' self.SetStatus('interface_up') iface.Up() + for x in range(0, 5): + time.sleep(2) + if iface.IsUp(): + return + self.abort_if_needed() + + # If we get here, the interface never came up + print "WARNING: Timed out waiting for interface to come up" class Wireless(Controller): @@ -769,7 +777,7 @@ class Wireless(Controller): iwconfig = self.GetIwconfig() else: iwconfig = None - bssid = self.wiface.GetBSSID(iwconfig), + bssid = self.wiface.GetBSSID(iwconfig) essid = self.wiface.GetCurrentNetwork(iwconfig) Controller.Disconnect(self, bssid, essid) diff --git a/wicd/wnettools.py b/wicd/wnettools.py index b088049..02ee0de 100644 --- a/wicd/wnettools.py +++ b/wicd/wnettools.py @@ -550,19 +550,20 @@ class BaseInterface(object): if self.verbose: print cmd self.dhcp_object = misc.Run(cmd, include_stderr=True, return_obj=True) pipe = self.dhcp_object.stdout + client_dict = { misc.DHCLIENT : self._parse_dhclient, + misc.DHCPCD : self._parse_dhcpcd, + misc.PUMP : self._parse_pump, + misc.UDHCPC : self._parse_udhcpc, + } - DHCP_CLIENT = self._get_dhcp_command() - if DHCP_CLIENT == misc.DHCLIENT: - return self._parse_dhclient(pipe) - elif DHCP_CLIENT == misc.PUMP: - return self._parse_pump(pipe) - elif DHCP_CLIENT == misc.DHCPCD: - return self._parse_dhcpcd(pipe) - elif DHCP_CLIENT == misc.UDHCPC: - return self._parse_udhcpc(pipe) + DHCP_CLIENT = self._get_dhcp_command() + if DHCP_CLIENT in client_dict: + ret = client_dict[DHCP_CLIENT](pipe) else: - print 'ERROR no dhclient found!' - + print "ERROR: no dhcp client found" + ret = None + return ret + @neediface(False) def ReleaseDHCP(self): """ Release the DHCP lease for this interface. """