diff --git a/daemon.py b/daemon.py index 9632dc5..6a35b16 100644 --- a/daemon.py +++ b/daemon.py @@ -820,8 +820,8 @@ class ConnectionWizard(dbus.service.Object): self.wifi.before_script = self.GetWirelessProperty(id, 'beforescript') self.wifi.after_script = self.GetWirelessProperty(id, 'afterscript') self.wifi.disconnect_script = self.GetWirelessProperty(id, - 'disconnectscript') - print 'Connecting to wireless network', self.LastScan[id]['essid'] + 'disconnectscript') + print 'Connecting to wireless network ' + self.LastScan[id]['essid'] return self.wifi.Connect(self.LastScan[id], debug=self.debug_mode) @dbus.service.method('org.wicd.daemon.wireless') @@ -893,6 +893,7 @@ class ConnectionWizard(dbus.service.Object): @dbus.service.method('org.wicd.daemon.wired') def SetWiredProperty(self, property, value): + """ Sets the given property to the given value. """ if self.WiredNetwork: if (property.strip()).endswith("script"): print "Setting script properties through the daemon" \ @@ -930,6 +931,7 @@ class ConnectionWizard(dbus.service.Object): @dbus.service.method('org.wicd.daemon.wired') def SetAlwaysShowWiredInterface(self, value): + """ Sets always_show_wired_interface to the given value. """ config = ConfigParser.ConfigParser() config.read(self.app_conf) config.set("Settings", "always_show_wired_interface", @@ -939,10 +941,12 @@ class ConnectionWizard(dbus.service.Object): @dbus.service.method('org.wicd.daemon.wired') def GetAlwaysShowWiredInterface(self): + """ Returns always_show_wired_interface """ return bool(self.always_show_wired_interface) @dbus.service.method('org.wicd.daemon.wired') def CheckPluggedIn(self, fast=False): + """ Returns True if a ethernet cable is present, False otherwise. """ if self.wired.wired_interface and self.wired.wired_interface != "None": return self.wired.CheckPluggedIn(fast) else: @@ -1026,7 +1030,7 @@ class ConnectionWizard(dbus.service.Object): @dbus.service.method('org.wicd.daemon.config') def UnsetWiredDefault(self): - """Unsets the default option in the current default wired profile""" + """ Unsets the default option in the current default wired profile. """ config = ConfigParser.ConfigParser() config.read(self.wired_conf) profileList = config.sections() @@ -1038,7 +1042,7 @@ class ConnectionWizard(dbus.service.Object): @dbus.service.method('org.wicd.daemon.config') def GetDefaultWiredNetwork(self): - """ Returns the current default wired network """ + """ Returns the current default wired network. """ config = ConfigParser.ConfigParser() config.read(self.wired_conf) profileList = config.sections() @@ -1050,6 +1054,7 @@ class ConnectionWizard(dbus.service.Object): @dbus.service.method('org.wicd.daemon.config') def GetLastUsedWiredNetwork(self): + """ Returns the profile of the last used wired network. """ config = ConfigParser.ConfigParser() config.read(self.wired_conf) profileList = config.sections() @@ -1061,7 +1066,7 @@ class ConnectionWizard(dbus.service.Object): @dbus.service.method('org.wicd.daemon.config') def DeleteWiredNetworkProfile(self, profilename): - """ Deletes a wired network profile """ + """ Deletes a wired network profile. """ profilename = misc.to_unicode(profilename) print "Deleting wired profile for " + str(profilename) config = ConfigParser.ConfigParser() @@ -1075,8 +1080,7 @@ class ConnectionWizard(dbus.service.Object): @dbus.service.method('org.wicd.daemon.config') def SaveWiredNetworkProfile(self, profilename): - """ Writes a wired network profile to disk """ - #should include: profilename,ip,netmask,gateway,dns1,dns2 + """ Writes a wired network profile to disk. """ if profilename == "": return "500: Bad Profile name" profilename = misc.to_unicode(profilename) @@ -1110,7 +1114,7 @@ class ConnectionWizard(dbus.service.Object): @dbus.service.method('org.wicd.daemon.config') def GetWiredProfileList(self): - """ Returns a list of all wired profiles in wired-settings.conf """ + """ Returns a list of all wired profiles in wired-settings.conf. """ config = ConfigParser.ConfigParser() config.read(self.wired_conf) if config.sections(): @@ -1120,7 +1124,7 @@ class ConnectionWizard(dbus.service.Object): @dbus.service.method('org.wicd.daemon.config') def SaveWirelessNetworkProfile(self, id): - """ Writes a wireless profile to disk """ + """ Writes a wireless profile to disk. """ config = ConfigParser.ConfigParser() config.read(self.wireless_conf) cur_network = self.LastScan[id] @@ -1304,6 +1308,12 @@ class ConnectionWizard(dbus.service.Object): return ret def ReadConfig(self): + """ Reads the manager-settings.conf file. + + Reads the manager-settings.conf file and loads the stored + values into memory. + + """ if os.path.isfile(self.app_conf): iface = self.DetectWirelessInterface() if not iface: @@ -1546,12 +1556,14 @@ def main(argv): mainloop.run() def sigterm_caught(sig, frame): + """ Called when a SIGTERM is caught, kills monitor.py before exiting. """ global child_pid print 'SIGTERM caught, killing wicd-monitor...' os.kill(child_pid, signal.SIGTERM) print 'Shutting down...' sys.exit(0) - + + if __name__ == '__main__': if os.getuid() != 0: print ("Root priviledges are required for the daemon to run properly." + diff --git a/data/wicd.glade b/data/wicd.glade index 2513c2e..68e5228 100644 --- a/data/wicd.glade +++ b/data/wicd.glade @@ -1,13 +1,14 @@ - + - 605 + 450 400 True Wicd Manager GTK_WIN_POS_CENTER + 550 wicd.png GDK_GRAVITY_CENTER @@ -31,6 +32,7 @@ False + False @@ -140,7 +142,6 @@ 4 - False Connecting... True Connecting... @@ -287,7 +288,7 @@ - + 416 GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK 5 diff --git a/gui.py b/gui.py index 2610fa6..d7548e2 100644 --- a/gui.py +++ b/gui.py @@ -456,6 +456,7 @@ class WiredSettingsDialog(AdvancedSettingsDialog): self.des = self.connect("destroy", self.destroy_called) def set_net_prop(self, option, value): + """ Sets the given option to the given value for this network. """ wired.SetWiredProperty(option, value) def set_values(self): @@ -911,7 +912,7 @@ class WiredNetworkEntry(NetworkEntry): self.chkbox_default_profile.set_active(stringToBoolean(is_default)) def format_entry(self, label): - """Help method for fetching/formatting wired properties. """ + """ Help method for fetching/formatting wired properties. """ return noneToBlankString(wired.GetWiredProperty(label)) @@ -1183,6 +1184,7 @@ class appGui: self.status_area.hide_all() + self.window.set_icon_from_file(wpath.etc + "wicd.png") self.statusID = None self.first_dialog_load = True self.vpn_connection_pipe = None @@ -1484,9 +1486,6 @@ class appGui: def connect_hidden(self, widget): """ Prompts the user for a hidden network, then scans for it. """ - # Should display a dialog asking - # for the ssid of a hidden network - # and displaying connect/cancel buttons dialog = gtk.Dialog(title=language['hidden_network'], flags=gtk.DIALOG_MODAL, buttons=(gtk.STOCK_CONNECT, 1, gtk.STOCK_CANCEL, 2)) @@ -1938,6 +1937,16 @@ class appGui: self.update_statusbar() def disconnect(self, widget, event, nettype, networkid, networkentry): + """ Disconnects from the given network. + + Keyword arguments: + widget -- The disconnect button that was pressed. + event -- unused + nettype -- "wired" or "wireless", depending on the network entry type. + networkid -- unused + networkentry -- The NetworkEntry containing the disconnect button. + + """ widget.hide() networkentry.connect_button.show() if nettype == "wired": diff --git a/setup.py b/setup.py index ad1116e..17c65d5 100755 --- a/setup.py +++ b/setup.py @@ -25,17 +25,9 @@ data=[ ('/usr/share/applications', ['other/hammer-00186ddbac.desktop']), ('', ['launchdaemon.sh']), ('/usr/share/pixmaps', ['other/wicd.png']), -('images', ['images/good-signal.png', 'images/low-signal.png', - 'images/no-signal.png', 'images/good-signal-lock.png' ,'images/wired.png', - 'images/wicd-purple.png', 'images/signal-25.png', 'images/signal-50.png', - 'images/wicd-green.png', 'images/signal-100.png', 'images/wicd.png', - 'images/low-signal-lock.png', 'images/wicd-blue.png', 'images/bad-signal.png', - 'images/bad-signal-lock.png', 'images/wicd-orange.png', 'images/signal-75.png', - 'images/high-signal.png', 'images/wicd-red.png', 'images/high-signal-lock.png']), -('encryption/templates', ['encryption/templates/peap', 'encryption/templates/wep-hex', 'encryption/templates/wpa', - 'encryption/templates/wep-passphrase', 'encryption/templates/wep-shared', - 'encryption/templates/ttls', 'encryption/templates/leap', 'encryption/templates/peap-tkip', - 'encryption/templates/eap', 'encryption/templates/active']), +('images', [('images/' + b) for b in os.listdir('images') if not b.startswith('.')]), +('encryption/templates', [('encryption/templates/' + b) for b in os.listdir('encryption/templates') if not b.startswith('.')]), +('encryption/configurations', []), ('data', ['data/wicd.png', 'data/wicd.glade']), ('translations', ['translations/wicd.pot', 'translations/ids']), ('translations/de_DE/LC_MESSAGES', ['translations/de_DE/LC_MESSAGES/wicd.mo']), @@ -46,15 +38,7 @@ data=[ ('translations/gl_GL/LC_MESSAGES', ['translations/gl_GL/LC_MESSAGES/wicd.mo']), ('translations/no_NO/LC_MESSAGES', ['translations/no_NO/LC_MESSAGES/wicd.mo']), ('translations/bg_PHO/LC_MESSAGES', ['translations/bg_PHO/LC_MESSAGES/wicd.mo']), -('translations/po', ['translations/po/bg_PHO.po', 'translations/po/ja_JA.po', 'translations/po/de_DE.po', - 'translations/po/de_DE.po', 'translations/po/zh_CN.po', 'translations/po/fr_FR.po', - 'translations/po/ar_EG.po', 'translations/po/it_IT.po', 'translations/po/fi_FI.po', - 'translations/po/sl_SI.po', 'translations/po/es_ES.po', 'translations/po/da_DK.po', - 'translations/po/sv_SE.po', 'translations/po/ca_ES.po', 'translations/po/nl_NL.po', - 'translations/po/no_NO.po', 'translations/po/gl_GL.po', 'translations/po/pl_PL.po', - 'translations/po/ru_RU.po', 'translations/po/en_US.po', 'translations/po/pt_BR.po', - 'translations/po/cs_CZ.po', 'translations/po/tr_TR.po', 'translations/po/zh_HK.po', - 'translations/po/hu_HU.po', 'translations/po/ko_KR.po']), +('translations/po', [('translations/po/' + b) for b in os.listdir('translations/po') if not b.startswith('.')]), ('translations/sl_SI/LC_MESSAGES', ['translations/sl_SI/LC_MESSAGES/wicd.mo']), ('translations/da_DK/LC_MESSAGES', ['translations/da_DK/LC_MESSAGES/wicd.mo']), ('translations/ja_JA/LC_MESSAGES', ['translations/ja_JA/LC_MESSAGES/wicd.mo']), diff --git a/wicd.py b/wicd.py index 5d5b7c0..7bb4f08 100755 --- a/wicd.py +++ b/wicd.py @@ -110,6 +110,7 @@ language['killswitch_enabled'] = _('Wireless Kill Switch Enabled') language['connecting'] = _('Connecting') language['wired'] = _('Wired Network') + class TrayIcon: """ Base Tray Icon class. @@ -143,7 +144,7 @@ class TrayIcon: self.update_tray_icon() def wired_profile_chooser(self): - """Launch the wired profile chooser.""" + """ Launch the wired profile chooser. """ gui.WiredProfileChooser() daemon.SetNeedWiredProfileChooser(False) @@ -390,6 +391,8 @@ class TrayIcon: """ Tray Icon for gtk < 2.10. Uses the deprecated egg.trayicon module to implement the tray icon. + Since it relies on a deprecated module, this class is only used + for machines running versions of GTK < 2.10. """ def __init__(self, use_tray=True): @@ -451,7 +454,6 @@ class TrayIcon: gtk.StatusIcon.__init__(self) self.current_icon_path = '' - daemon.SetForcedDisconnect(False) self.set_visible(True) self.connect('activate', self.on_activate) self.connect('popup-menu', self.on_popup_menu) diff --git a/wnettools.py b/wnettools.py index 654f3ed..cad3372 100644 --- a/wnettools.py +++ b/wnettools.py @@ -155,6 +155,15 @@ def _fast_get_wifi_interfaces(): return None def get_iw_ioctl_result(iface, call): + """ Makes the given ioctl call and returns the results. + + Keyword arguments: + call -- The ioctl call to make + + Returns: + The results of the ioctl call. + + """ s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) buff = array.array('c', '\0' * 32) addr, length = buff.buffer_info() @@ -205,6 +214,17 @@ class Interface(object): self.iface = str(iface) def _find_client_path(self, client): + """ Determines the full path for the given program. + + Searches a hardcoded list of paths for a given program name. + + Keyword arguments: + client -- The name of the program to search for + + Returns: + The full path of the program or None + + """ paths = ['/sbin/', '/usr/sbin/', '/bin/', '/usr/bin/', '/usr/local/sbin/', '/usr/local/bin/'] for path in paths: @@ -215,7 +235,14 @@ class Interface(object): return None def _client_found(self, client): - # TODO: Don't use which anymore. Just search path manually. + """ Searches for the existence of the given program in PATH. + + Uses "which" to determine if a given program exists in PATH. + + Returns: + True if the program exists, False otherwise. + + """ output = misc.Run("which " + client) if output and not ("no " + client) in output: return True @@ -539,6 +566,7 @@ class Interface(object): return False def _fast_is_up(self): + """ Determines if the interfae is up using an ioctl call. """ data = (self.iface + '\0' * 16)[:18] try: result = fcntl.ioctl(self.sock.fileno(), SIOCGIFFLAGS, data) @@ -549,7 +577,6 @@ class Interface(object): flags, = struct.unpack('H', result[16:18]) return bool(flags & 1) - class WiredInterface(Interface): @@ -608,6 +635,14 @@ class WiredInterface(Interface): return False def _fast_eth_get_plugged_in(self): + """ Determines link connection status using an ioctl call. + + Uses the SIOCGETHTOOL ioctl call to determine link status. + + Returns: + True if a wire is plugged in, False otherwise. + + """ if not self.IsUp(): self.Up() time.sleep(2.5) @@ -649,7 +684,7 @@ class WiredInterface(Interface): return False def _fast_mii_get_plugged_in(self): - """ Get link status usingthe SIOCGMIIPHY ioctl. """ + """ Get link status using the SIOCGMIIPHY ioctl call. """ if not self.IsUp(): self.Up() time.sleep(2.5) @@ -1199,6 +1234,12 @@ class WirelessInterface(Interface): return dbm_strength def _get_dbm_strength_fast(self): + """ Uses the SIOCGIWSTATS ioctl call to get dbm signal strength. + + Returns: + The dBm signal strength or None if it can't be found. + + """ buff = misc.get_irwange_ioctl_result(self.iface, SIOCGIWSTATS) if not buff: return None