diff --git a/curses/wicd-curses.py b/curses/wicd-curses.py index 6af93dc..c754a58 100644 --- a/curses/wicd-curses.py +++ b/curses/wicd-curses.py @@ -33,9 +33,8 @@ at least get a network connection. Or those who don't like using X. :-) Comments, criticisms, patches, bug reports all welcome! """ -##### NOTICE: THIS DOES NOT WORK WITH THE EXPERIMENTAL BRANCH, DESPITE THE FACT -##### THAT THIS FILE COMES WITH A FULL COPY OF THE EXPERIMENTAL BRANCH! -##### I WILL PROBABLY BE REMEDYING THIS SOMETIME IN JANUARY. +##### NOTICE: THIS ONLY WORKS WITH THE SOURCE IN WICD 1.6 AS FOUND IN THE BZR +##### REPOSITORIES! # UI stuff #import urwid.raw_display @@ -50,6 +49,7 @@ import gobject # Other important wicd-related stuff import wicd.misc as misc +from wicd import dbusmanager # Internal Python stuff import sys @@ -197,7 +197,7 @@ class wrap_exceptions: gobject.source_remove(redraw_tag) loop.quit() ui.stop() - print "Terminated by user." + print "\nTerminated by user." raise except : # If the UI isn't inactive (redraw_tag wouldn't normally be @@ -210,7 +210,7 @@ class wrap_exceptions: # Zap the screen ui.stop() # Print out standard notification: - print "EXCEPTION!" + print "\nEXCEPTION!" print "Please report this to the maintainer and/or file a bug report with the backtrace below:" print redraw_tag # Flush the buffer so that the notification is always above the @@ -291,9 +291,6 @@ def gen_list_header(): # DBUS interfaces do. ^_^ # Whatever calls this must be exception-wrapped if it is run if the UI is up def gen_network_list(): - #theList = [urwid.Text(gen_list_header())] - #theList = [] - # Pick which strength measure to use based on what the daemon says if daemon.GetSignalDisplayType() == 0: strenstr = 'quality' @@ -304,15 +301,12 @@ def gen_network_list(): id = 0 wiredL = [] - for profile in config.GetWiredProfileList(): - #if id == 0: - #theList.append(urwid.Text("Wired Network(s):")) - #wired.append(urwid.Text(('body',"Wired Network(s):") ) ) + for profile in wired.GetWiredProfileList(): theString = '%4s %25s' % (id, profile) #### THIS IS wired.blah() in experimental #print config.GetLastUsedWiredNetwork() # Tag if no wireless IP present, and wired one is - is_active = wireless.GetWirelessIP() == None and wired.GetWiredIP() != None + is_active = wireless.GetWirelessIP('') == None and wired.GetWiredIP('') != None if is_active: theString = '>'+theString[1:] wiredL.append(urwid.AttrWrap(SelText(theString),'connected', @@ -323,9 +317,6 @@ def gen_network_list(): wlessL = [] for network_id in range(0, wireless.GetNumberOfNetworks()): - #if network_id == 0: - #wireless.append(urwid.Text(('body', "Wireless Network(s):")) ) - # ?: in python encryption = wireless.GetWirelessProperty(network_id, 'encryption_method') if wireless.GetWirelessProperty(network_id, 'encryption') else 'Unsecured' theString = ' %*s %25s %9s %17s %6s: %s' % ( gap, @@ -338,13 +329,12 @@ def gen_network_list(): wireless.GetWirelessProperty(network_id, 'mode'), # Master, Ad-Hoc wireless.GetWirelessProperty(network_id, 'channel') ) - is_active = wireless.GetPrintableSignalStrength("") != 0 and wireless.GetCurrentNetworkID(wireless.GetIwconfig())==network_id + is_active = wireless.GetCurrentSignalStrength("") != 0 and wireless.GetCurrentNetworkID(wireless.GetIwconfig())==network_id if is_active: theString = '>'+theString[1:] wlessL.append(urwid.AttrWrap(SelText(theString),'connected','connected focus')) else: wlessL.append(urwid.AttrWrap(SelText(theString),'body','focus')) - #theList.append(SelText(theString)) return (wiredL,wlessL) @@ -384,19 +374,16 @@ class appGUI(): ('fixed',1,self.wiredLB), ('fixed',1,self.wlessH), self.wlessLB] ) - #self.netList = urwid.ListBox(wlessL) - #walker = urwid.SimpleListWalker(gen_network_list()) self.footer1 = urwid.AttrWrap(urwid.Text("Something important will eventually go here."),'body') self.footer2 = urwid.AttrWrap(urwid.Text("If you are seeing this, then something has gone wrong!"),'important') self.footerList = urwid.ListBox([self.footer1,self.footer2]) # Pop takes a number! #walker.pop(1) - #self.listbox = urwid.AttrWrap(urwid.ListBox(netList),'body','focus') self.frame = urwid.Frame(self.thePile, header=header, footer=urwid.BoxAdapter(self.footerList,2)) - #self.frame = urwid.Frame(self.screen_locker, header=header,footer=footer) self.frame.set_focus('body') + # Booleans gallore! self.prev_state = False self.connecting = False @@ -441,17 +428,16 @@ class appGUI(): wireless_connecting = wireless.CheckIfWirelessConnecting() self.connecting = wired_connecting or wireless_connecting - # IN EXPERIMENTAL - #fast = not daemon.NeedsExternalCalls() + fast = not daemon.NeedsExternalCalls() if self.connecting: #self.lock_screen() #if self.statusID: # gobject.idle_add(self.status_bar.remove, 1, self.statusID) if wireless_connecting: - #if not fast: - iwconfig = wireless.GetIwconfig() - #else: - # iwconfig = '' + if not fast: + iwconfig = wireless.GetIwconfig() + else: + iwconfig = '' # set_status is rigged to return false when it is not # connecting to anything, so this should work. gobject.idle_add(self.set_status, wireless.GetCurrentNetwork(iwconfig) + @@ -465,10 +451,14 @@ class appGUI(): True) return True else: - if check_for_wired(wired.GetWiredIP(),self.set_status): + if check_for_wired(wired.GetWiredIP(''),self.set_status): return True - elif check_for_wireless(wireless.GetIwconfig(), - wireless.GetWirelessIP(), self.set_status): + if not fast: + iwconfig = wireless.GetIwconfig() + else: + iwconfig = '' + if check_for_wireless(iwconfig, wireless.GetWirelessIP(""), + self.set_status): return True else: self.set_status(language['not_connected']) @@ -479,7 +469,7 @@ class appGUI(): # mainloop def set_status(self,text,from_idle=False): # If we are being called as the result of trying to connect to - # something return False immediately. + # something, return False immediately. if from_idle and not self.connecting: return False self.footer2 = urwid.AttrWrap(urwid.Text(text),'important') @@ -489,7 +479,7 @@ class appGUI(): # Make sure the screen is still working by providing a pretty counter. # Not necessary in the end, but I will be using footer1 for stuff in - # the long run. + # the long run, so I might as well put something there. incr = 0 def idle_incr(self): theText = "" @@ -517,13 +507,6 @@ class appGUI(): self.lock_screen() # Redraw the screen - # There exists a problem with this where any exceptions that occur (especially of - # the DBus variety) will get spread out on the top of the screen, or not displayed - # at all. Urwid and the glib main loop don't mix all too well. I may need to - # consult the Urwid maintainer about this. - # - # The implementation of this solution is active in this program, and it appears to - # be functioning well. @wrap_exceptions() def update_ui(self): #self.update_status() @@ -551,7 +534,6 @@ class appGUI(): daemon.CancelConnect() # Prevents automatic reconnecting if that option is enabled daemon.SetForcedDisconnect(True) - pass for k in keys: if k == "window resize": self.size = ui.get_cols_rows() @@ -612,7 +594,11 @@ def main(): ('header','light blue','black'), ('important','light red','black'), ('connected','dark green','black'), - ('connected focus','black','dark green')]) + ('connected focus','black','dark green'), + # I'll be needing these soon, so I'll leave them here for now. + ('editcp', 'light gray', 'black', 'standout'), + ('editbx', 'light gray', 'dark blue'), + ('editfc', 'white','dark blue', 'bold') ]) # This is a wrapper around a function that calls another a function that is a # wrapper around a infinite loop. Fun. ui.run_wrapper(run) @@ -625,9 +611,9 @@ def run(): # Connect signals and whatnot to UI screen control functions bus.add_signal_receiver(app.dbus_scan_finished, 'SendEndScanSignal', - 'org.wicd.daemon') + 'org.wicd.daemon.wireless') bus.add_signal_receiver(app.dbus_scan_started, 'SendStartScanSignal', - 'org.wicd.daemon') + 'org.wicd.daemon.wireless') # I've left this commented out many times. bus.add_signal_receiver(app.update_netlist, 'StatusChanged', 'org.wicd.daemon') @@ -641,22 +627,26 @@ def run(): #gobject.idle_add(app.stop_loop) loop.run() - -# Mostly borrowed from gui.py, but also with the "need daemon first" check -def setup_dbus(): - global proxy_obj, daemon, wireless, wired, config, dbus_ifaces +# Mostly borrowed from gui.py +def setup_dbus(force=True): + global bus, daemon, wireless, wired, DBUS_AVAIL try: - proxy_obj = bus.get_object('org.wicd.daemon', '/org/wicd/daemon') - except dbus.DBusException: - print 'Error: Could not connect to the daemon. Please make sure it is running.' - sys.exit(3) - daemon = dbus.Interface(proxy_obj, 'org.wicd.daemon') - wireless = dbus.Interface(proxy_obj, 'org.wicd.daemon.wireless') - wired = dbus.Interface(proxy_obj, 'org.wicd.daemon.wired') - config = dbus.Interface(proxy_obj, 'org.wicd.daemon.config') - - dbus_ifaces = {"daemon" : daemon, "wireless" : wireless, "wired" : wired, - "config" : config} + dbusmanager.connect_to_dbus() + except DBusException: + # I may need to be a little more verbose here. + # Suggestions as to what should go here + print "Can't connect to the daemon. Are you sure it is running?" + print "Please check the wicd log for error messages." + raise + # return False # <- Will need soon. + bus = dbusmanager.get_bus() + dbus_ifaces = dbusmanager.get_dbus_ifaces() + daemon = dbus_ifaces['daemon'] + wireless = dbus_ifaces['wireless'] + wired = dbus_ifaces['wired'] + DBUS_AVAIL = True + + return True bus = dbus.SystemBus() setup_dbus() @@ -665,4 +655,7 @@ setup_dbus() ##### MAIN ENTRY POINT ######################################## if __name__ == '__main__': - main() + main() + # Make sure that the terminal does not try to overwrite the last line of + # the program, so that everything looks pretty. + print "" diff --git a/data/wicd.glade b/data/wicd.glade index a5eea9f..234fd4a 100644 --- a/data/wicd.glade +++ b/data/wicd.glade @@ -1,6 +1,6 @@ - + 450 @@ -62,7 +62,7 @@ True - wicd + network-wireless @@ -391,728 +391,950 @@ - Preferences - 125 - 560 + 5 + GTK_WIN_POS_CENTER_ON_PARENT GDK_WINDOW_TYPE_HINT_DIALOG + False - + True + 2 - + True True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - GTK_POLICY_NEVER - GTK_POLICY_AUTOMATIC - + True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - GTK_RESIZE_QUEUE + 12 + 12 + 12 + 12 - + True True + GTK_POLICY_AUTOMATIC + GTK_POLICY_AUTOMATIC - + True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - 5 + GTK_RESIZE_QUEUE + GTK_SHADOW_NONE - + True + 16 + 2 + 4 + 4 - - 260 + True - Wireless Interface: - - - - - 200 - True - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + 24 + + + True + True + If enabled, the wired network interface will always be displayed in the main window. This can be useful if your wired network card does not detect when the interface is connected to a cable. + Always show wired interface + 0 + True + + - False - False - 1 - - - - - False - False - - - - - True - - - 260 - True - Wired Interface: - - - - - 200 - True - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - - - False - False - 1 - - - - - False - False - 1 - - - - - True - True - Use global DNS servers - True - 0 - True - - - False - 2 - - - - - True - - - 170 - True - Search Domain - - - False - False + 2 + 3 + 4 + - 200 True True - False - False - 1 - - - - - False - False - 3 - - - - - True - - - 170 - True - DNS 1 - - - False - False + 1 + 2 + 6 + 7 + - 200 True True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - False - False - 1 - - - - - False - False - 4 - - - - - True - - - 170 - True - DNS 2 - - - False - False + 1 + 2 + 7 + 8 + - 200 True True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - False - False - 1 + 1 + 2 + 8 + 9 + - - - False - False - 5 - - - - - True - - 170 + True - DNS 3 + 0 + <b>Global DNS Servers</b> + True - False - False + 2 + 4 + 5 + + + + + + True + 12 + + + True + True + Use global DNS servers + 0 + True + + + + + 2 + 5 + 6 + + + + + + True + 24 + + + True + 0 + Search domain: + + + + + 6 + 7 + + + + + + True + 24 + + + True + 0 + DNS server 1: + + + + + 7 + 8 + + + + + + True + 24 + + + True + 0 + DNS server 2: + + + + + 8 + 9 + - 200 True True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - False - False - 1 + 1 + 2 + 9 + 10 + + + + + + True + 24 + + + True + 0 + DNS server 3: + + + + + 9 + 10 + + + + + + True + 0 + <b>Network Interfaces</b> + True + + + 2 + + + + + + True + True + + + 1 + 2 + 1 + 2 + + + + + + True + True + + + 1 + 2 + 2 + 3 + + + + + + True + 12 + + + True + 0 + Wireless interface: + + + + + 1 + 2 + + + + + + True + 12 + + + True + 0 + Wired interface: + + + + + 2 + 3 + + + + + + True + 0 + <b>Wired automatic connection</b> + True + + + 2 + 10 + 11 + + + + + + True + 12 + + + True + True + Use default wired network profile + 0 + True + True + pref_use_last_radio + + + + + 2 + 11 + 12 + + + + + + True + 12 + + + True + True + Prompt for wired network profile + 0 + True + True + pref_use_last_radio + + + + + 2 + 12 + 13 + + + + + + True + 12 + + + True + True + Use last wired network profile + 0 + True + True + + + + + 2 + 13 + 14 + + + + + + True + 0 + <b>Wireless automatic connection</b> + True + + + 2 + 14 + 15 + + + + + + True + 12 + + + True + True + Automatically connect to on network connection loss + 0 + True + + + + + 2 + 15 + 16 + - - False - 6 - - - - - True - True - Always show wired interface - True - 0 - True - - - False - False - 7 - - - - - True - True - Automatically reconnect on connection loss - True - 0 - True - - - False - False - 8 - - - - - True - True - Use dBm to measure signal strength - True - 0 - True - - - False - False - 9 - - - - - 2 - 8 - True - - - False - 10 - - - - - True - Wired Autoconnect Setting: - True - - - False - False - 11 - - - - - True - True - Use default profile on wired autoconnect - True - 0 - True - True - - - False - 12 - - - - - True - True - Prompt for profile on wired autoconnect - True - 0 - True - True - pref_use_def_radio - - - False - 13 - - - - - True - True - Use last profile on wired autoconnect - True - 0 - True - True - pref_use_def_radio - - - False - 14 - - - - True - General Settings - - - tab - False - - - - - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - - - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - 5 - - - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - DHCP Client: - - - - - True - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - Automatic (recommended) - 0 - True - True - - - 1 - - - - - True - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - dhclient - 0 - True - True - dhcp_auto_radio - - - 2 - - - - - True - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - dhcpcd - 0 - True - True - dhcp_auto_radio - - - 3 - - - - - True - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - pump - 0 - True - True - dhcp_auto_radio - - - 4 - - - - - False - False - - - - - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - - - False - 4 - 1 - - - - - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - 5 - - - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - Wired Link Detection: - - - - - True - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - Automatic (recommended) - 0 - True - True - - - 1 - - - - - True - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - ethtool - 0 - True - True - link_auto_radio - - - 2 - - - - - True - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - mii-tool - 0 - True - True - link_auto_radio - - - 3 - - - - - False - False - 2 - - - - - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - - - False - 4 - 3 - - - - - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - - - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - Route Table Flushing: - - - - - True - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - Automatic (recommended) - 0 - True - True - - - 1 - - - - - True - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - ip - 0 - True - True - flush_auto_radio - - - 2 - - - - - True - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - route - 0 - True - True - flush_auto_radio - - - 3 - - - - - False - False - 4 - - - - - 1 - - - - - True - External Programs - - - tab - 1 - False - - - - - True - - - True - - - 75 - True - Sets the wpa_supplicant driver. In almost every case the correct choice is wext. Only consider switching if you're having trouble with encrypted networks. - WPA Supplicant Driver: - - - - - True - Sets the wpa_supplicant driver. In almost every case the correct choice is wext. Only consider switching if you're having trouble with encrypted networks. - - - 1 - - - - - False - False - 1 - - - - - True - - - True - Backend: - - - - - True - - - 1 - - - - - False - False - 3 - 1 - - - - - True - True - Enable Debug Mode - True - 0 - True - - - False - False - 3 - 2 - - - - - 2 - - - - - True - Advanced Settings - - - tab - 2 - False - - + + + True + General Settings + + + tab + False + + + + + True + 12 + 12 + 12 + 12 + + + True + True + GTK_POLICY_AUTOMATIC + GTK_POLICY_AUTOMATIC + + + True + GTK_RESIZE_QUEUE + GTK_SHADOW_NONE + + + True + 6 + + + True + 0 + <b>DHCP Client</b> + True + + + + + + + + True + 12 + + + True + + + True + True + Automatic (recommended) + 0 + True + True + dhclient_radio + + + False + + + + + True + True + dhclient + 0 + True + True + + + False + 1 + + + + + True + True + dhcpcd + 0 + True + True + dhclient_radio + + + False + 2 + + + + + True + True + pump + 0 + True + True + dhclient_radio + + + False + 3 + + + + + + + 1 + 2 + + + + + + True + 12 + + + True + + + True + True + Automatic (recommended) + 0 + True + True + + + False + + + + + True + True + ethtool + 0 + True + True + link_auto_radio + + + False + 1 + + + + + True + True + mii-tool + 0 + True + True + link_auto_radio + + + False + 2 + + + + + + + 3 + 4 + + + + + + True + 12 + + + True + + + True + True + Automatic (recommended) + 0 + True + True + + + False + + + + + True + True + ip + 0 + True + True + flush_auto_radio + + + False + 1 + + + + + True + True + route + 0 + True + True + flush_auto_radio + + + False + 2 + + + + + + + 5 + 6 + + + + + + True + 0 + <b>Wired Link Detection</b> + True + + + 2 + 3 + + + + + + True + 0 + <b>Route Table Flushing</b> + True + + + 4 + 5 + + + + + + + + + + + + 1 + + + + + True + External Programs + + + tab + 1 + False + + + + + True + 12 + 12 + 12 + 12 + + + True + 9 + 2 + + + True + + + 2 + 3 + + + + + + True + 0 + You should almost always use wext as the WPA supplicant driver. + True + + + 1 + 2 + 2 + 3 + + + + + + True + + + True + + + False + + + + + 1 + 2 + 1 + 2 + + + + + + True + 0 + <b>Backend</b> + True + + + 2 + 3 + 4 + + + + + + True + + + 1 + 2 + 4 + 5 + + + + + + True + 12 + + + True + 0 + Backend: + + + + + 4 + 5 + + + + + + True + 0 + <b>Debugging</b> + True + + + 2 + 5 + 6 + + + + + + True + 0 + <b>WPA Supplicant</b> + True + + + 2 + + + + + + True + 0 + <b>Wireless Interface</b> + True + + + 2 + 7 + 8 + + + + + + True + 12 + + + True + True + Enable debug mode + 0 + True + + + + + 2 + 6 + 7 + + + + + + True + 12 + + + True + True + Use dBm to measure signal strength + 0 + True + + + + + 2 + 8 + 9 + + + + + + True + 12 + + + True + 0 + Driver: + + + + + 1 + 2 + + + + + + + + 2 + + + + + True + Advanced Settings + + + tab + 2 + False + + - 2 + 1 - + True GTK_BUTTONBOX_END - + True True - True - gtk-cancel + True + gtk-cancel True 0 - + True True - True - gtk-ok + True + gtk-ok True 1 diff --git a/encryption/templates/active b/encryption/templates/active index 3be3271..aee3d84 100644 --- a/encryption/templates/active +++ b/encryption/templates/active @@ -1,4 +1,5 @@ wpa +wpa-psk wep-hex wep-passphrase wep-shared diff --git a/encryption/templates/wpa b/encryption/templates/wpa index c618bcb..20b36a7 100644 --- a/encryption/templates/wpa +++ b/encryption/templates/wpa @@ -1,4 +1,4 @@ -name = WPA 1/2 +name = WPA 1/2 (Passphrase) author = Adam Blackburn version = 1 require key *Key diff --git a/encryption/templates/wpa-psk b/encryption/templates/wpa-psk new file mode 100644 index 0000000..3685610 --- /dev/null +++ b/encryption/templates/wpa-psk @@ -0,0 +1,15 @@ +name = WPA 1/2 (Preshared Key) +author = Adam Blackburn +version = 1 +require apsk *Preshared_Key +----- +ctrl_interface=/var/run/wpa_supplicant +network={ + ssid="$_ESSID" + scan_ssid=$_SCAN + proto=WPA RSN + key_mgmt=WPA-PSK + pairwise=CCMP TKIP + group=CCMP TKIP + psk="$_APSK" +} diff --git a/setup.py b/setup.py index 521e7dd..16644e5 100755 --- a/setup.py +++ b/setup.py @@ -219,7 +219,24 @@ class configure(Command): item_out.close() item_in.close() shutil.copymode(original_name, final_name) + +class test(Command): + description = "run Wicd's unit tests" + + user_options = [] + + def initialize_options(self): + pass + def finalize_options(self): + pass + + def run(self): + print "importing tests" + import tests + print 'running tests' + tests.run_tests() + class get_translations(Command): description = "download the translations from the online translator" @@ -330,7 +347,7 @@ try: data.append(( wpath.suspend, ['other/50-wicd-suspend.sh' ])) if not wpath.no_install_pmutils: data.append(( wpath.pmutils, ['other/55wicd' ])) - print 'Creating pid path', os.path.basename(wpath.pidfile) + print 'Using pid path', os.path.basename(wpath.pidfile) print 'Language support for', for language in os.listdir('translations/'): if not language.startswith('.'): @@ -354,7 +371,7 @@ iwscan_ext = Extension(name = 'iwscan', libraries = ['iw'], sources = ['depends/python-iwscan/pyiwscan.c']) -setup(cmdclass={'configure' : configure, 'get_translations' : get_translations, 'uninstall' : uninstall}, +setup(cmdclass={'configure' : configure, 'get_translations' : get_translations, 'uninstall' : uninstall, 'test' : test}, name="Wicd", version=VERSION_NUM, description="A wireless and wired network manager", diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..369c462 --- /dev/null +++ b/tests/__init__.py @@ -0,0 +1,9 @@ + +def run_tests(): + import unittest + test_suite = unittest.TestSuite() + + import testwnettools + test_suite.addTest(testwnettools.suite()) + + unittest.TextTestRunner(verbosity=5).run(test_suite) diff --git a/tests/testwnettools.py b/tests/testwnettools.py new file mode 100644 index 0000000..2ace308 --- /dev/null +++ b/tests/testwnettools.py @@ -0,0 +1,66 @@ +import unittest +from wicd import wnettools + +class TestWnettools(unittest.TestCase): + def setUp(self): + self.interface = wnettools.BaseInterface('eth0') + + def test_find_wireless_interface(self): + interfaces = wnettools.GetWirelessInterfaces() + # wlan0 may change depending on your system + self.assertTrue('wlan0' in interfaces) + + def test_find_wired_interface(self): + interfaces = wnettools.GetWiredInterfaces() + # eth0 may change depending on your system + self.assertTrue('eth0' in interfaces) + + def test_wext_is_valid_wpasupplicant_driver(self): + self.assertTrue(wnettools.IsValidWpaSuppDriver('wext')) + + def test_needs_external_calls_not_implemented(self): + self.assertRaises(NotImplementedError, wnettools.NeedsExternalCalls) + + def test_get_ip_not_implemented(self): + self.assertRaises(NotImplementedError, self.interface.GetIP) + + def test_is_up_not_implemented(self): + self.assertRaises(NotImplementedError, self.interface.IsUp) + + def test_enable_debug_mode(self): + self.interface.SetDebugMode(True) + self.assertTrue(self.interface.verbose) + + def test_disable_debug_mode(self): + self.interface.SetDebugMode(False) + self.assertFalse(self.interface.verbose) + + def test_interface_name_sanitation(self): + interface = wnettools.BaseInterface('blahblah; uptime > /tmp/blah | cat') + self.assertEquals(interface.iface, 'blahblahuptimetmpblahcat') + + def test_freq_translation_low(self): + freq = '2.412 GHz' + interface = wnettools.BaseWirelessInterface('wlan0') + self.assertEquals(interface._FreqToChannel(freq), 1) + + def test_freq_translation_high(self): + freq = '2.484 GHz' + interface = wnettools.BaseWirelessInterface('wlan0') + self.assertEquals(interface._FreqToChannel(freq), 14) + + def test_generate_psk(self): + interface = wnettools.BaseWirelessInterface('wlan0') + psk = interface.GeneratePSK({'essid' : 'Network 1', 'key' : 'arandompassphrase'}) + self.assertEquals(psk, 'd70463014514f4b4ebb8e3aebbdec13f4437ac3a9af084b3433f3710e658a7be') + +def suite(): + suite = unittest.TestSuite() + tests = [] + [ tests.append(test) for test in dir(TestWnettools) if test.startswith('test') ] + for test in tests: + suite.addTest(TestWnettools(test)) + return suite + +if __name__ == '__main__': + unittest.main() diff --git a/wicd/misc.py b/wicd/misc.py index d7e65e7..f3e2abe 100644 --- a/wicd/misc.py +++ b/wicd/misc.py @@ -302,13 +302,22 @@ 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) == unicode: + if type(x) not in [unicode, str]: + return x + if isinstance(x, unicode): return x.encode('utf-8') encoding = locale.getpreferredencoding() try: - ret = x.decode(encoding, 'replace').encode('utf-8') - except: - ret = x.decode('utf-8', 'replace').encode('utf-8') + ret = x.decode(encoding).encode('utf-8') + except UnicodeError: + try: + ret = x.decode('utf-8').encode('utf-8') + except UnicodeError: + try: + ret = x.decode('latin-1').encode('utf-8') + except UnicodeError: + ret = x.decode('utf-8', 'replace').encode('utf-8') + return ret def RenameProcess(new_name): @@ -509,8 +518,8 @@ def get_language_list_gui(): language['bad_pass'] = _('Connection Failed: Could not authenticate (bad password?)') language['done'] = _('Done connecting...') language['scanning'] = _('Scanning') - language['cannot_start_daemon'] = _("Unable to connect to wicd daemon DBus interface." + \ - "This typically means there was a problem starting the daemon." + \ + language['cannot_start_daemon'] = _("Unable to connect to wicd daemon DBus interface. " + \ + "This typically means there was a problem starting the daemon. " + \ "Check the wicd log for more info") language['lost_dbus'] = _("The wicd daemon has shut down, the UI will not function properly until it is restarted.") diff --git a/wicd/prefs.py b/wicd/prefs.py index 95a517f..c8ca2c0 100644 --- a/wicd/prefs.py +++ b/wicd/prefs.py @@ -71,6 +71,7 @@ class PreferencesDialog(object): dhcp_list = [self.dhcpautoradio, self.dhclientradio, self.dhcpcdradio, self.pumpradio] dhcp_method = daemon.GetDHCPClient() + print 'DHCP method is %s' % daemon.GetDHCPClient() dhcp_list[dhcp_method].set_active(True) wired_link_list = [self.linkautoradio, self.ethtoolradio, @@ -94,21 +95,10 @@ class PreferencesDialog(object): self.entryWirelessInterface.set_text(daemon.GetWirelessInterface()) self.entryWiredInterface.set_text(daemon.GetWiredInterface()) - found = False def_driver = daemon.GetWPADriver() - for i, x in enumerate(self.wpadrivers): - if x == def_driver: #and not found: - found = True - user_driver_index = i - self.wpadrivercombo.remove_text(i) - self.wpadrivercombo.append_text(x) - - # Set the active choice here. Doing it before all the items are - # added the combobox causes the choice to be reset. - if found: - self.wpadrivercombo.set_active(user_driver_index) - else: - # Use wext as default, since normally it is the correct driver. + try: + self.wpadrivercombo.set_active(self.wpadrivers.index(def_driver)) + except ValueError: self.wpadrivercombo.set_active(0) self.useGlobalDNSCheckbox.connect("toggled", checkboxTextboxToggle, @@ -128,22 +118,12 @@ class PreferencesDialog(object): self.dns2Entry.set_sensitive(False) self.dns3Entry.set_sensitive(False) - # Load backend combobox - self.backends = daemon.GetBackendList() - # "" is included as a hack for DBus limitations, so we remove it. - self.backends.remove("") - found = False cur_backend = daemon.GetSavedBackend() - for i, x in enumerate(self.backends): - if x == cur_backend: - found = True - backend_index = i - self.backendcombo.remove_text(i) - self.backendcombo.append_text(x) - - if found: - self.backendcombo.set_active(backend_index) - else: + self.backendcombo.set_active(0) + + try: + self.backendcombo.set_active(self.backends.index(cur_backend)) + except ValueError: self.backendcombo.set_active(0) self.wTree.get_widget("notebook2").set_current_page(0) @@ -234,32 +214,34 @@ class PreferencesDialog(object): def setup_label(name, lbl=""): """ Sets up a label for the given widget name. """ widget = self.wTree.get_widget(name) - if lbl: - widget.set_label(language[lbl]) + # if lbl: + # widget.set_label(language[lbl]) + if widget is None: + raise ValueError('widget %s does not exist' % name) return widget # External Programs tab - self.wTree.get_widget("gen_settings_label").set_label(language["gen_settings"]) - self.wTree.get_widget("ext_prog_label").set_label(language["ext_programs"]) - self.wTree.get_widget("dhcp_client_label").set_label(language["dhcp_client"]) - self.wTree.get_widget("wired_detect_label").set_label(language["wired_detect"]) - self.wTree.get_widget("route_flush_label").set_label(language["route_flush"]) - self.wTree.get_widget("pref_backend_label").set_label(language["backend"] + ":") + # self.wTree.get_widget("gen_settings_label").set_label(language["gen_settings"]) + # self.wTree.get_widget("ext_prog_label").set_label(language["ext_programs"]) + # self.wTree.get_widget("dhcp_client_label").set_label(language["dhcp_client"]) + # self.wTree.get_widget("wired_detect_label").set_label(language["wired_detect"]) + # self.wTree.get_widget("route_flush_label").set_label(language["route_flush"]) + # self.wTree.get_widget("pref_backend_label").set_label(language["backend"] + ":") - entryWiredAutoMethod = self.wTree.get_widget("pref_wired_auto_label") - entryWiredAutoMethod.set_label('Wired Autoconnect Setting:') - entryWiredAutoMethod.set_alignment(0, 0) - atrlist = pango.AttrList() - atrlist.insert(pango.AttrWeight(pango.WEIGHT_BOLD, 0, 50)) - entryWiredAutoMethod.set_attributes(atrlist) + # entryWiredAutoMethod = self.wTree.get_widget("pref_wired_auto_label") + # entryWiredAutoMethod.set_label('Wired Autoconnect Setting:') + # entryWiredAutoMethod.set_alignment(0, 0) + # atrlist = pango.AttrList() + # atrlist.insert(pango.AttrWeight(pango.WEIGHT_BOLD, 0, 50)) + # entryWiredAutoMethod.set_attributes(atrlist) - self.set_label("pref_dns1_label", "%s %s" % (language['dns'], language['1'])) - self.set_label("pref_dns2_label", "%s %s" % (language['dns'], language['2'])) - self.set_label("pref_dns3_label", "%s %s" % (language['dns'], language['3'])) - self.set_label("pref_search_dom_label", "%s:" % language['search_domain']) - self.set_label("pref_wifi_label", "%s:" % language['wireless_interface']) - self.set_label("pref_wired_label", "%s:" % language['wired_interface']) - self.set_label("pref_driver_label", "%s:" % language['wpa_supplicant_driver']) + # self.set_label("pref_dns1_label", "%s %s" % (language['dns'], language['1'])) + # self.set_label("pref_dns2_label", "%s %s" % (language['dns'], language['2'])) + # self.set_label("pref_dns3_label", "%s %s" % (language['dns'], language['3'])) + # self.set_label("pref_search_dom_label", "%s:" % language['search_domain']) + # self.set_label("pref_wifi_label", "%s:" % language['wireless_interface']) + # self.set_label("pref_wired_label", "%s:" % language['wired_interface']) + # self.set_label("pref_driver_label", "%s:" % language['wpa_supplicant_driver']) self.dialog = self.wTree.get_widget("pref_dialog") self.dialog.set_title(language['preferences']) @@ -315,6 +297,9 @@ class PreferencesDialog(object): "ndiswrapper", "ipw"] self.wpadrivers = wireless.GetWpaSupplicantDrivers(self.wpadrivers) self.wpadrivers.append("ralink_legacy") + + for x in self.wpadrivers: + self.wpadrivercombo.append_text(x) self.entryWirelessInterface = self.wTree.get_widget("pref_wifi_entry") self.entryWiredInterface = self.wTree.get_widget("pref_wired_entry") @@ -327,4 +312,13 @@ class PreferencesDialog(object): self.dns2Entry = self.wTree.get_widget("pref_dns2_entry") self.dns3Entry = self.wTree.get_widget("pref_dns3_entry") - self.backendcombo = build_combobox("pref_backend_combobox") \ No newline at end of file + self.backendcombo = build_combobox("pref_backend_combobox") + # Load backend combobox + self.backends = daemon.GetBackendList() + # "" is included as a hack for DBus limitations, so we remove it. + self.backends.remove("") + + cur_backend = daemon.GetSavedBackend() + for x in self.backends: + self.backendcombo.append_text(x) + diff --git a/wicd/wicd-client.py b/wicd/wicd-client.py index 40114de..743b9e8 100755 --- a/wicd/wicd-client.py +++ b/wicd/wicd-client.py @@ -364,7 +364,8 @@ class TrayIcon(object): if DBUS_AVAIL: self.toggle_wicd_gui() else: - gui.error(None, language["daemon_unavailable"]) + # gui.error(None, language["daemon_unavailable"]) + pass def on_quit(self, widget=None): """ Closes the tray icon. """ diff --git a/wicd/wnettools.py b/wicd/wnettools.py index 0a0b9c2..5c70c75 100644 --- a/wicd/wnettools.py +++ b/wicd/wnettools.py @@ -41,7 +41,7 @@ import misc RALINK_DRIVER = 'ralink legacy' -blacklist_strict = punctuation.replace("-", "") + " " +blacklist_strict = '!"#$%&\'()*+,./:;<=>?@[\\]^`{|}~ ' blacklist_norm = ";`$!*|><&\\" blank_trans = maketrans("", "")