From ec8eade509fb5d25140e143330b2e531818b4b60 Mon Sep 17 00:00:00 2001 From: Dan O'Reilly Date: Fri, 28 Aug 2009 19:47:55 -0400 Subject: [PATCH 1/9] 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. """ From 05a46ddfdcfd739eb1d1c9852e0b810a7fea190a Mon Sep 17 00:00:00 2001 From: Andrew Psaltis Date: Wed, 2 Sep 2009 10:20:13 -0400 Subject: [PATCH 2/9] Adjusted the keystrokes in wicd-curses to support 8-bit terminals (like xterms by default). Thanks to DarkStarSword for the patch. --- curses/curses_misc.py | 29 +++++++---------------------- curses/wicd-curses.py | 14 +++++++------- in/man=wicd-curses.8.in | 9 --------- 3 files changed, 14 insertions(+), 38 deletions(-) diff --git a/curses/curses_misc.py b/curses/curses_misc.py index 4affdd6..f34afcb 100644 --- a/curses/curses_misc.py +++ b/curses/curses_misc.py @@ -211,9 +211,9 @@ class TabColumns(urwid.WidgetWrap): return True def keypress(self,size,key): - if key == "meta [" or key == "meta ]": + if key == "page up" or key == "page down": self._w.get_body().set_focus(0) - newK = 'left' if key[-1] == '[' else 'right' + newK = 'left' if key == "page up" else 'right' self.keypress(size,newK) self._w.get_body().set_focus(1) else: @@ -564,26 +564,11 @@ class OptCols(urwid.WidgetWrap): # callbacks map the text contents to its assigned callback. self.callbacks = [] for cmd in tuples: - splitcmd = cmd[0].split() - key = '' - for part in splitcmd: - if part == 'ctrl': - key+='Ctrl+' - elif part == 'meta': - # If anyone has a problem with this, they can bother me - # about it. - key+='Alt+' - else: - if part == 'left': - key += '<-' - elif part == 'right': - key += '->' - elif part == 'esc': - key += 'ESC' - elif part == 'enter': - key += 'Enter' - else: - key += part + key = reduce(lambda s,(f,t):s.replace(f,t), [ \ + ('ctrl ', 'Ctrl+'), ('meta ', 'Alt+'), \ + ('left', '<-'), ('right', '->'), \ + ('page up', 'Page Up'), ('page down', 'Page Down'), \ + ('esc', 'ESC'), ('enter', 'Enter'), ('f10','F10')], cmd[0]) if debug: callback = self.debugClick diff --git a/curses/wicd-curses.py b/curses/wicd-curses.py index 6ba6846..ef50da8 100755 --- a/curses/wicd-curses.py +++ b/curses/wicd-curses.py @@ -3,8 +3,8 @@ """ wicd-curses. (curses/urwid-based) console interface to wicd -Provides the a console UI for wicd, so that people with broken X servers can -at least get a network connection. Or those who don't like using X. ;-) +Provides a console UI for wicd, so that people with broken X servers can +at least get a network connection. Or those who don't like using X and/or GTK. """ @@ -583,11 +583,11 @@ class appGUI(): def init_other_optcols(self): # The "tabbed" preferences dialog - self.prefCols = OptCols( [ ('meta enter','OK'), - ('meta [','Tab Left',), - ('meta ]','Tab Right'), + self.prefCols = OptCols( [ ('f10','OK'), + ('page up','Tab Left',), + ('page down', 'Tab Right'), ('esc','Cancel') ], self.handle_keys) - self.confCols = OptCols( [ ('meta enter','OK'), + self.confCols = OptCols( [ ('f10','OK'), ('esc','Cancel') ],self.handle_keys) # Does what it says it does @@ -902,7 +902,7 @@ class appGUI(): if k == 'esc' or k == 'q' or k == 'Q': self.restore_primary() break - if k == 'meta enter': + if k == 'f10': self.diag.save_settings() self.restore_primary() break diff --git a/in/man=wicd-curses.8.in b/in/man=wicd-curses.8.in index 7381627..a730c62 100644 --- a/in/man=wicd-curses.8.in +++ b/in/man=wicd-curses.8.in @@ -60,8 +60,6 @@ Delete the selected wired network profile (from the wired network combo box at t .TP .BR F2 Rename the selected wired network profile (from the wired network combo box at the top) -.\".PP -.\"The following are not implemented yet: .TP .BR S .\"Bring up the script selector for the selected network (requires superuser privileges) @@ -75,13 +73,6 @@ Raise the Ad-Hoc network creation dialog .I ~/.wicd/WHEREAREMYFILES Reminder that your network configuration files are not here ;-) .PP -These following are not used yet: -.TP -.I %LIB%colors.py -Tentative location of the system color schemes -.TP -.I ~/.wicd/colors.py -Custom color schemes. .SH "SEE ALSO" .BR wicd-client (1), .BR wicd (8) From f5866c0426e13b90246c6414c8a99a3b237b81af Mon Sep 17 00:00:00 2001 From: Dan O'Reilly Date: Thu, 10 Sep 2009 19:43:26 -0400 Subject: [PATCH 3/9] Fix for crash when trying to connect to an essid with all numeric characters. --- wicd/wicd-daemon.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wicd/wicd-daemon.py b/wicd/wicd-daemon.py index 3cd7bb4..0beb6ef 100644 --- a/wicd/wicd-daemon.py +++ b/wicd/wicd-daemon.py @@ -1144,7 +1144,7 @@ class WirelessDaemon(dbus.service.Object): 'predisconnectscript') self.wifi.post_disconnect_script = self.GetWirelessProperty(id, 'postdisconnectscript') - print 'Connecting to wireless network ' + self.LastScan[id]['essid'] + print 'Connecting to wireless network ' + str(self.LastScan[id]['essid']) self.daemon.wired_bus.wired.Disconnect() self.daemon.SetForcedDisconnect(False) conthread = self.wifi.Connect(self.LastScan[id], debug=self.debug_mode) From fe6d854cdfa290443e349b8afee72475aed4a26f Mon Sep 17 00:00:00 2001 From: Dan O'Reilly Date: Sat, 19 Sep 2009 14:58:00 -0400 Subject: [PATCH 4/9] chmod to 0755, not 755. Fixes LP #431304 --- wicd/wicd-daemon.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wicd/wicd-daemon.py b/wicd/wicd-daemon.py index 0beb6ef..7235ba8 100644 --- a/wicd/wicd-daemon.py +++ b/wicd/wicd-daemon.py @@ -1685,7 +1685,7 @@ def main(argv): logpath = os.path.join(wpath.log, 'wicd.log') if not os.path.exists(wpath.log): os.makedirs(wpath.log) - os.chmod(wpath.log, 755) + os.chmod(wpath.log, 0755) output = ManagedStdio(logpath) if os.path.exists(logpath): try: From 265dd40113e85be72262231d1728c0d0815c334d Mon Sep 17 00:00:00 2001 From: Dan O'Reilly Date: Sat, 19 Sep 2009 17:24:40 -0400 Subject: [PATCH 5/9] Still trying to get rid of this empty wired-settings.conf section bug. --- wicd/configmanager.py | 3 +++ wicd/wicd-daemon.py | 2 ++ 2 files changed, 5 insertions(+) diff --git a/wicd/configmanager.py b/wicd/configmanager.py index b93b1a6..6782821 100644 --- a/wicd/configmanager.py +++ b/wicd/configmanager.py @@ -124,6 +124,9 @@ class ConfigManager(RawConfigParser): def write(self): """ Writes the loaded config file to disk. """ + for section in self.sections(): + if not section: + self.remove_section(section) configfile = open(self.config_file, 'w') RawConfigParser.write(self, configfile) configfile.close() diff --git a/wicd/wicd-daemon.py b/wicd/wicd-daemon.py index 7235ba8..201b8f5 100644 --- a/wicd/wicd-daemon.py +++ b/wicd/wicd-daemon.py @@ -1446,6 +1446,8 @@ class WiredDaemon(dbus.service.Object): @dbus.service.method('org.wicd.daemon.wired') def CreateWiredNetworkProfile(self, profilename, default=False): """ Creates a wired network profile. """ + if not profilename: + return False profilename = misc.to_unicode(profilename) print "Creating wired profile for " + profilename if self.config.has_section(profilename): From 27c7c786ca204ff3cfa98ce7937790974e11e715 Mon Sep 17 00:00:00 2001 From: Andrew Psaltis Date: Sun, 27 Sep 2009 17:35:26 -0400 Subject: [PATCH 6/9] Reduce cursor flicker in wicd-curses. --- curses/wicd-curses.py | 36 ++++++++++++------------------------ 1 file changed, 12 insertions(+), 24 deletions(-) diff --git a/curses/wicd-curses.py b/curses/wicd-curses.py index ef50da8..cacd5be 100755 --- a/curses/wicd-curses.py +++ b/curses/wicd-curses.py @@ -400,7 +400,6 @@ class WiredComboBox(ComboBox): self.rebuild_combobox() self.set_focus(prev_focus) else: - print "updating..." wired.ReadWiredNetworkProfile(self.get_selected_profile()) if key == 'delete': if len(self.theList) == 1: @@ -768,6 +767,7 @@ class appGUI(): self.tcount+=1 toAppend=self.twirl[self.tcount % 4] self.status_label.set_text(text+' '+toAppend) + self.update_ui() return True # Make sure the screen is still working by providing a pretty counter. @@ -776,6 +776,7 @@ class appGUI(): #@wrap_exceptions def update_time(self): self.time_label.set_text(strftime('%H:%M:%S')) + self.update_ui() return True # Yeah, I'm copying code. Anything wrong with that? @@ -911,17 +912,16 @@ class appGUI(): continue def call_update_ui(self,source,cb_condition): - self.update_ui(from_key=True) + self.update_ui(True) return True # Redraw the screen @wrap_exceptions - def update_ui(self,from_key=True,from_alarm=False): - #self.update_status() - canvas = self.frame.render( (self.size),True ) - + def update_ui(self,from_key=False): if not ui._started: return False + canvas = self.frame.render( (self.size),True ) + # Update the screen ui.draw_screen((self.size),canvas) # Get the input data @@ -932,24 +932,12 @@ class appGUI(): # Resolve any "alarms" in the waiting if self.update_tag != None: gobject.source_remove(self.update_tag) - if max_wait == None: - max_wait = 25 - else: - max_wait *= 100 - - max_wait = int(max_wait) - self.update_tag = gobject.timeout_add(max_wait, \ - self.update_ui,False,True) - #print keys - #if keys == []: - # return True - self.handle_keys(keys) - - # If we came from the "alarm", die. - if from_alarm: - return False - - return True + if from_key: + max_wait = 20 + self.update_tag = gobject.timeout_add(max_wait, \ + self.update_ui,True) + self.handle_keys(keys) + return False def connect(self, nettype, networkid, networkentry=None): """ Initiates the connection process in the daemon. """ From 740204ee503ac394f07664e413b3d8db32172cc0 Mon Sep 17 00:00:00 2001 From: Andrew Psaltis Date: Tue, 29 Sep 2009 12:38:11 -0400 Subject: [PATCH 7/9] Remove uses of ternary operator from wicd-curses, restoring support for python 2.4. --- curses/curses_misc.py | 18 ++++++++++++------ curses/wicd-curses.py | 18 ++++++++++++++---- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/curses/curses_misc.py b/curses/curses_misc.py index f34afcb..e4e9e40 100644 --- a/curses/curses_misc.py +++ b/curses/curses_misc.py @@ -65,8 +65,11 @@ class DynWrap(urwid.AttrWrap): def __init__(self,w,sensitive=True,attrs=('editbx','editnfc'),focus_attr='editfc'): self._attrs=attrs self._sensitive = sensitive - - cur_attr = attrs[0] if sensitive else attrs[1] + + if sensitive: + cur_attr = attrs[0] + else: + cur_attr = attrs[1] self.__super.__init__(w,cur_attr,focus_attr) @@ -211,24 +214,27 @@ class TabColumns(urwid.WidgetWrap): return True def keypress(self,size,key): + # If the key is page up or page down, move focus to the tabs and call + # left or right on the tabs. if key == "page up" or key == "page down": self._w.get_body().set_focus(0) - newK = 'left' if key == "page up" else 'right' + if key == "page up": + newK = 'left' + else: + newK = 'right' self.keypress(size,newK) self._w.get_body().set_focus(1) else: key = self._w.keypress(size,key) wid = self.pile.get_focus().get_body() if wid == self.columns: - # lw = self.listbox.body - # lw.pop(1) self.active_tab.set_attr('body') self.columns.get_focus().set_attr('tab active') self.active_tab = self.columns.get_focus() self.gen_pile(self.tab_map[self.active_tab]) return key - # self.listbox.body = lw + def mouse_event(self,size,event,button,x,y,focus): wid = self.pile.get_focus().get_body() if wid == self.columns: diff --git a/curses/wicd-curses.py b/curses/wicd-curses.py index cacd5be..622560e 100755 --- a/curses/wicd-curses.py +++ b/curses/wicd-curses.py @@ -254,9 +254,14 @@ def help_dialog(body): def run_configscript(parent,netname,nettype): configfile = wpath.etc+netname+'-settings.conf' - header = 'profile' if nettype == 'wired' else 'BSSID' - profname = netname if nettype == 'wired' else wireless.GetWirelessProperty( - int(netname),'bssid') + if nettype != 'wired': + header = 'profile' + else: + header ='BSSID' + if nettype == 'wired': + profname = nettype + else: + profname = wireless.GetWirelessProperty( int(netname),'bssid') theText = [ language['cannot_edit_scripts_1'].replace('$A',configfile).replace('$B',header), "\n\n["+profname+"]\n\n", @@ -329,7 +334,12 @@ class NetLabel(urwid.WidgetWrap): str(wireless.GetWirelessProperty(id, strenstr))) self.essid = wireless.GetWirelessProperty(id, 'essid') self.bssid = wireless.GetWirelessProperty(id, 'bssid') - self.encrypt = wireless.GetWirelessProperty(id,'encryption_method') if wireless.GetWirelessProperty(id, 'encryption') else language['unsecured'] + + if wireless.GetWirelessProperty(id, 'encryption'): + self.encrypt = wireless.GetWirelessProperty(id,'encryption_method') + else: + self.encrypt = language['unsecured'] + self.mode = wireless.GetWirelessProperty(id, 'mode') # Master, Ad-Hoc self.channel = wireless.GetWirelessProperty(id, 'channel') theString = ' %-*s %25s %9s %17s %6s %4s' % (gap, From 0872e1b329da6267814374ed8bfb72bfab374b24 Mon Sep 17 00:00:00 2001 From: Dan O'Reilly Date: Sat, 24 Oct 2009 01:03:29 -0400 Subject: [PATCH 8/9] Handle essids that are made up of numbers. Thanks to anish for the patch. --- wicd/wnettools.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wicd/wnettools.py b/wicd/wnettools.py index 02ee0de..eaa9be5 100644 --- a/wicd/wnettools.py +++ b/wicd/wnettools.py @@ -844,7 +844,7 @@ class BaseWirelessInterface(BaseInterface): essid -- essid to set the interface to """ - cmd = ['iwconfig', self.iface, 'essid', essid] + cmd = ['iwconfig', self.iface, 'essid', str(essid)] if self.verbose: print str(cmd) misc.Run(cmd) @@ -1055,7 +1055,7 @@ class BaseWirelessInterface(BaseInterface): if not wpa_pass_path: return None key_pattern = re.compile('network={.*?\spsk=(.*?)\n}.*', re.I | re.M | re.S) - cmd = [wpa_pass_path, network['essid'], str(network['key'])] + cmd = [wpa_pass_path, str(network['essid']), str(network['key'])] if self.verbose: print cmd return misc.RunRegex(key_pattern, misc.Run(cmd)) From a45beaeeafd53603f5c05874528de49dffb5566e Mon Sep 17 00:00:00 2001 From: Dan O'Reilly Date: Fri, 30 Oct 2009 23:52:30 -0400 Subject: [PATCH 9/9] Determine valid wpa_supplicant drivers by parsing the list from wpa_supplicant, rather than comparing it's output to a static list of possible drivers. --- curses/prefs_curses.py | 4 +--- wicd/backends/be-external.py | 2 +- wicd/backends/be-ioctl.py | 3 ++- wicd/networking.py | 7 +++---- wicd/prefs.py | 4 +--- wicd/wicd-daemon.py | 6 +++--- wicd/wnettools.py | 11 +++++++++++ 7 files changed, 22 insertions(+), 15 deletions(-) diff --git a/curses/prefs_curses.py b/curses/prefs_curses.py index d843705..a88ceb8 100644 --- a/curses/prefs_curses.py +++ b/curses/prefs_curses.py @@ -294,9 +294,7 @@ class PrefsDialog(urwid.WidgetWrap): ### Advanced settings # wpa_supplicant janx - self.wpadrivers = ["wext", "hostap", "madwifi", "atmel", - "ndiswrapper", "ipw"] - self.wpadrivers = wireless.GetWpaSupplicantDrivers(self.wpadrivers) + self.wpadrivers = wireless.GetWpaSupplicantDrivers() self.wpadrivers.append("ralink_legacy") # Same as above with the dbus.String self.thedrivers = [unicode(w) for w in self.wpadrivers] diff --git a/wicd/backends/be-external.py b/wicd/backends/be-external.py index 13f9303..640a804 100644 --- a/wicd/backends/be-external.py +++ b/wicd/backends/be-external.py @@ -31,7 +31,7 @@ class WirelessInterface() -- Control a wireless network interface. from wicd.wnettools import GetDefaultGateway, GetWiredInterfaces, \ GetWirelessInterfaces, IsValidWpaSuppDriver, BaseWirelessInterface, \ -BaseWiredInterface, BaseInterface +BaseWiredInterface, BaseInterface, GetWpaSupplicantDrivers NAME = "external" UPDATE_INTERVAL = 5 diff --git a/wicd/backends/be-ioctl.py b/wicd/backends/be-ioctl.py index a51db1b..d4f00bc 100644 --- a/wicd/backends/be-ioctl.py +++ b/wicd/backends/be-ioctl.py @@ -34,7 +34,8 @@ from wicd import misc from wicd import wpath from wicd.wnettools import GetDefaultGateway, GetWiredInterfaces, \ GetWirelessInterfaces, IsValidWpaSuppDriver, BaseWirelessInterface, \ -BaseWiredInterface, BaseInterface, wep_pattern, signaldbm_pattern, neediface +BaseWiredInterface, BaseInterface, GetWpaSupplicantDrivers, wep_pattern, \ +signaldbm_pattern, neediface try: import iwscan diff --git a/wicd/networking.py b/wicd/networking.py index ea6620b..605ca83 100644 --- a/wicd/networking.py +++ b/wicd/networking.py @@ -703,10 +703,9 @@ class Wireless(Controller): """ Get the out of iwconfig. """ return self.wiface.GetIwconfig() - def GetWpaSupplicantDrivers(self, drivers): - """ Returns all valid wpa_supplicant drivers in a list. """ - return [driver for driver in drivers if - BACKEND.IsValidWpaSuppDriver(driver)] + def GetWpaSupplicantDrivers(self): + """ Returns all valid wpa_supplicant drivers on the system. """ + return BACKEND.GetWpaSupplicantDrivers() def StopWPA(self): return self.wiface.StopWPA() diff --git a/wicd/prefs.py b/wicd/prefs.py index 7d3426e..757465a 100644 --- a/wicd/prefs.py +++ b/wicd/prefs.py @@ -375,9 +375,7 @@ class PreferencesDialog(object): # Replacement for the combo box hack self.wpadrivercombo = build_combobox("pref_wpa_combobox") - self.wpadrivers = ["wext", "hostap", "madwifi", "atmel", - "ndiswrapper", "ipw"] - self.wpadrivers = wireless.GetWpaSupplicantDrivers(self.wpadrivers) + self.wpadrivers = wireless.GetWpaSupplicantDrivers() self.wpadrivers.append("ralink_legacy") for x in self.wpadrivers: diff --git a/wicd/wicd-daemon.py b/wicd/wicd-daemon.py index 201b8f5..cdb0e7f 100644 --- a/wicd/wicd-daemon.py +++ b/wicd/wicd-daemon.py @@ -1269,9 +1269,9 @@ class WirelessDaemon(dbus.service.Object): self.config.remove_section(essid_key) @dbus.service.method('org.wicd.daemon.wireless') - def GetWpaSupplicantDrivers(self, drivers): - """ Returns all valid wpa_supplicant drivers in a given list. """ - return self.wifi.GetWpaSupplicantDrivers(drivers) + def GetWpaSupplicantDrivers(self): + """ Returns all valid wpa_supplicant drivers. """ + return self.wifi.GetWpaSupplicantDrivers() @dbus.service.method('org.wicd.daemon.wireless') def ReloadConfig(self): diff --git a/wicd/wnettools.py b/wicd/wnettools.py index eaa9be5..bfb2b37 100644 --- a/wicd/wnettools.py +++ b/wicd/wnettools.py @@ -155,6 +155,17 @@ def NeedsExternalCalls(): """ Returns True if the backend needs to use an external program. """ raise NotImplementedError +def GetWpaSupplicantDrivers(): + """ Returns a list of all valid wpa_supplicant drivers. """ + output = misc.Run(["wpa_supplicant", "-h"]) + try: + output = output.split("drivers:")[1].split("options:")[0].strip() + except: + print "Warning: Couldn't get list of valid wpa_supplicant drivers" + return [""] + patt = re.compile("(\S+)\s+=.*") + return patt.findall(output) or [""] + def IsValidWpaSuppDriver(driver): """ Returns True if given string is a valid wpa_supplicant driver. """ output = misc.Run(["wpa_supplicant", "-D%s" % driver, "-iolan19",