1
0
mirror of https://github.com/gryf/wicd.git synced 2025-12-19 12:28:08 +01:00

Fixed some setup.py problems

Added a bunch of docstrings
Fixed a crash bug when the daemon is called with the -s option caused by wicd.py calling SetForceDisconnect(False) when it launches.
This commit is contained in:
imdano
2008-04-02 10:52:41 +00:00
parent 6d5a78b124
commit e1d7429e6c
6 changed files with 92 additions and 43 deletions

View File

@@ -820,8 +820,8 @@ class ConnectionWizard(dbus.service.Object):
self.wifi.before_script = self.GetWirelessProperty(id, 'beforescript') self.wifi.before_script = self.GetWirelessProperty(id, 'beforescript')
self.wifi.after_script = self.GetWirelessProperty(id, 'afterscript') self.wifi.after_script = self.GetWirelessProperty(id, 'afterscript')
self.wifi.disconnect_script = self.GetWirelessProperty(id, self.wifi.disconnect_script = self.GetWirelessProperty(id,
'disconnectscript') 'disconnectscript')
print 'Connecting to wireless network', self.LastScan[id]['essid'] print 'Connecting to wireless network ' + self.LastScan[id]['essid']
return self.wifi.Connect(self.LastScan[id], debug=self.debug_mode) return self.wifi.Connect(self.LastScan[id], debug=self.debug_mode)
@dbus.service.method('org.wicd.daemon.wireless') @dbus.service.method('org.wicd.daemon.wireless')
@@ -893,6 +893,7 @@ class ConnectionWizard(dbus.service.Object):
@dbus.service.method('org.wicd.daemon.wired') @dbus.service.method('org.wicd.daemon.wired')
def SetWiredProperty(self, property, value): def SetWiredProperty(self, property, value):
""" Sets the given property to the given value. """
if self.WiredNetwork: if self.WiredNetwork:
if (property.strip()).endswith("script"): if (property.strip()).endswith("script"):
print "Setting script properties through the daemon" \ print "Setting script properties through the daemon" \
@@ -930,6 +931,7 @@ class ConnectionWizard(dbus.service.Object):
@dbus.service.method('org.wicd.daemon.wired') @dbus.service.method('org.wicd.daemon.wired')
def SetAlwaysShowWiredInterface(self, value): def SetAlwaysShowWiredInterface(self, value):
""" Sets always_show_wired_interface to the given value. """
config = ConfigParser.ConfigParser() config = ConfigParser.ConfigParser()
config.read(self.app_conf) config.read(self.app_conf)
config.set("Settings", "always_show_wired_interface", config.set("Settings", "always_show_wired_interface",
@@ -939,10 +941,12 @@ class ConnectionWizard(dbus.service.Object):
@dbus.service.method('org.wicd.daemon.wired') @dbus.service.method('org.wicd.daemon.wired')
def GetAlwaysShowWiredInterface(self): def GetAlwaysShowWiredInterface(self):
""" Returns always_show_wired_interface """
return bool(self.always_show_wired_interface) return bool(self.always_show_wired_interface)
@dbus.service.method('org.wicd.daemon.wired') @dbus.service.method('org.wicd.daemon.wired')
def CheckPluggedIn(self, fast=False): 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": if self.wired.wired_interface and self.wired.wired_interface != "None":
return self.wired.CheckPluggedIn(fast) return self.wired.CheckPluggedIn(fast)
else: else:
@@ -1026,7 +1030,7 @@ class ConnectionWizard(dbus.service.Object):
@dbus.service.method('org.wicd.daemon.config') @dbus.service.method('org.wicd.daemon.config')
def UnsetWiredDefault(self): 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 = ConfigParser.ConfigParser()
config.read(self.wired_conf) config.read(self.wired_conf)
profileList = config.sections() profileList = config.sections()
@@ -1038,7 +1042,7 @@ class ConnectionWizard(dbus.service.Object):
@dbus.service.method('org.wicd.daemon.config') @dbus.service.method('org.wicd.daemon.config')
def GetDefaultWiredNetwork(self): def GetDefaultWiredNetwork(self):
""" Returns the current default wired network """ """ Returns the current default wired network. """
config = ConfigParser.ConfigParser() config = ConfigParser.ConfigParser()
config.read(self.wired_conf) config.read(self.wired_conf)
profileList = config.sections() profileList = config.sections()
@@ -1050,6 +1054,7 @@ class ConnectionWizard(dbus.service.Object):
@dbus.service.method('org.wicd.daemon.config') @dbus.service.method('org.wicd.daemon.config')
def GetLastUsedWiredNetwork(self): def GetLastUsedWiredNetwork(self):
""" Returns the profile of the last used wired network. """
config = ConfigParser.ConfigParser() config = ConfigParser.ConfigParser()
config.read(self.wired_conf) config.read(self.wired_conf)
profileList = config.sections() profileList = config.sections()
@@ -1061,7 +1066,7 @@ class ConnectionWizard(dbus.service.Object):
@dbus.service.method('org.wicd.daemon.config') @dbus.service.method('org.wicd.daemon.config')
def DeleteWiredNetworkProfile(self, profilename): def DeleteWiredNetworkProfile(self, profilename):
""" Deletes a wired network profile """ """ Deletes a wired network profile. """
profilename = misc.to_unicode(profilename) profilename = misc.to_unicode(profilename)
print "Deleting wired profile for " + str(profilename) print "Deleting wired profile for " + str(profilename)
config = ConfigParser.ConfigParser() config = ConfigParser.ConfigParser()
@@ -1075,8 +1080,7 @@ class ConnectionWizard(dbus.service.Object):
@dbus.service.method('org.wicd.daemon.config') @dbus.service.method('org.wicd.daemon.config')
def SaveWiredNetworkProfile(self, profilename): def SaveWiredNetworkProfile(self, profilename):
""" Writes a wired network profile to disk """ """ Writes a wired network profile to disk. """
#should include: profilename,ip,netmask,gateway,dns1,dns2
if profilename == "": if profilename == "":
return "500: Bad Profile name" return "500: Bad Profile name"
profilename = misc.to_unicode(profilename) profilename = misc.to_unicode(profilename)
@@ -1110,7 +1114,7 @@ class ConnectionWizard(dbus.service.Object):
@dbus.service.method('org.wicd.daemon.config') @dbus.service.method('org.wicd.daemon.config')
def GetWiredProfileList(self): 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 = ConfigParser.ConfigParser()
config.read(self.wired_conf) config.read(self.wired_conf)
if config.sections(): if config.sections():
@@ -1120,7 +1124,7 @@ class ConnectionWizard(dbus.service.Object):
@dbus.service.method('org.wicd.daemon.config') @dbus.service.method('org.wicd.daemon.config')
def SaveWirelessNetworkProfile(self, id): def SaveWirelessNetworkProfile(self, id):
""" Writes a wireless profile to disk """ """ Writes a wireless profile to disk. """
config = ConfigParser.ConfigParser() config = ConfigParser.ConfigParser()
config.read(self.wireless_conf) config.read(self.wireless_conf)
cur_network = self.LastScan[id] cur_network = self.LastScan[id]
@@ -1304,6 +1308,12 @@ class ConnectionWizard(dbus.service.Object):
return ret return ret
def ReadConfig(self): 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): if os.path.isfile(self.app_conf):
iface = self.DetectWirelessInterface() iface = self.DetectWirelessInterface()
if not iface: if not iface:
@@ -1546,12 +1556,14 @@ def main(argv):
mainloop.run() mainloop.run()
def sigterm_caught(sig, frame): def sigterm_caught(sig, frame):
""" Called when a SIGTERM is caught, kills monitor.py before exiting. """
global child_pid global child_pid
print 'SIGTERM caught, killing wicd-monitor...' print 'SIGTERM caught, killing wicd-monitor...'
os.kill(child_pid, signal.SIGTERM) os.kill(child_pid, signal.SIGTERM)
print 'Shutting down...' print 'Shutting down...'
sys.exit(0) sys.exit(0)
if __name__ == '__main__': if __name__ == '__main__':
if os.getuid() != 0: if os.getuid() != 0:
print ("Root priviledges are required for the daemon to run properly." + print ("Root priviledges are required for the daemon to run properly." +

View File

@@ -1,13 +1,14 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd"> <!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
<!--Generated with glade3 3.2.2 on Sun Jul 1 23:19:18 2007 by adam@adam--> <!--Generated with glade3 3.4.0 on Wed Apr 2 14:45:13 2008 -->
<glade-interface> <glade-interface>
<widget class="GtkWindow" id="window1"> <widget class="GtkWindow" id="window1">
<property name="width_request">605</property> <property name="width_request">450</property>
<property name="height_request">400</property> <property name="height_request">400</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="title" translatable="yes">Wicd Manager</property> <property name="title" translatable="yes">Wicd Manager</property>
<property name="window_position">GTK_WIN_POS_CENTER</property> <property name="window_position">GTK_WIN_POS_CENTER</property>
<property name="default_width">550</property>
<property name="icon">wicd.png</property> <property name="icon">wicd.png</property>
<property name="gravity">GDK_GRAVITY_CENTER</property> <property name="gravity">GDK_GRAVITY_CENTER</property>
<signal name="destroy" handler="exit"/> <signal name="destroy" handler="exit"/>
@@ -31,6 +32,7 @@
</widget> </widget>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
<property name="homogeneous">False</property>
</packing> </packing>
</child> </child>
<child> <child>
@@ -140,7 +142,6 @@
<property name="border_width">4</property> <property name="border_width">4</property>
<child> <child>
<widget class="GtkProgressBar" id="progressbar"> <widget class="GtkProgressBar" id="progressbar">
<property name="visible">False</property>
<property name="tooltip" translatable="yes">Connecting...</property> <property name="tooltip" translatable="yes">Connecting...</property>
<property name="activity_mode">True</property> <property name="activity_mode">True</property>
<property name="text" translatable="yes">Connecting...</property> <property name="text" translatable="yes">Connecting...</property>
@@ -287,7 +288,7 @@
</widget> </widget>
</child> </child>
</widget> </widget>
<widget class="GtkDialog" id="configure_script_dialog"> <widget class="GtkDialog" id="configure_script_dialog">
<property name="width_request">416</property> <property name="width_request">416</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property> <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="border_width">5</property> <property name="border_width">5</property>

17
gui.py
View File

@@ -456,6 +456,7 @@ class WiredSettingsDialog(AdvancedSettingsDialog):
self.des = self.connect("destroy", self.destroy_called) self.des = self.connect("destroy", self.destroy_called)
def set_net_prop(self, option, value): def set_net_prop(self, option, value):
""" Sets the given option to the given value for this network. """
wired.SetWiredProperty(option, value) wired.SetWiredProperty(option, value)
def set_values(self): def set_values(self):
@@ -911,7 +912,7 @@ class WiredNetworkEntry(NetworkEntry):
self.chkbox_default_profile.set_active(stringToBoolean(is_default)) self.chkbox_default_profile.set_active(stringToBoolean(is_default))
def format_entry(self, label): def format_entry(self, label):
"""Help method for fetching/formatting wired properties. """ """ Help method for fetching/formatting wired properties. """
return noneToBlankString(wired.GetWiredProperty(label)) return noneToBlankString(wired.GetWiredProperty(label))
@@ -1183,6 +1184,7 @@ class appGui:
self.status_area.hide_all() self.status_area.hide_all()
self.window.set_icon_from_file(wpath.etc + "wicd.png")
self.statusID = None self.statusID = None
self.first_dialog_load = True self.first_dialog_load = True
self.vpn_connection_pipe = None self.vpn_connection_pipe = None
@@ -1484,9 +1486,6 @@ class appGui:
def connect_hidden(self, widget): def connect_hidden(self, widget):
""" Prompts the user for a hidden network, then scans for it. """ """ 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'], dialog = gtk.Dialog(title=language['hidden_network'],
flags=gtk.DIALOG_MODAL, flags=gtk.DIALOG_MODAL,
buttons=(gtk.STOCK_CONNECT, 1, gtk.STOCK_CANCEL, 2)) buttons=(gtk.STOCK_CONNECT, 1, gtk.STOCK_CANCEL, 2))
@@ -1938,6 +1937,16 @@ class appGui:
self.update_statusbar() self.update_statusbar()
def disconnect(self, widget, event, nettype, networkid, networkentry): 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() widget.hide()
networkentry.connect_button.show() networkentry.connect_button.show()
if nettype == "wired": if nettype == "wired":

View File

@@ -25,17 +25,9 @@ data=[
('/usr/share/applications', ['other/hammer-00186ddbac.desktop']), ('/usr/share/applications', ['other/hammer-00186ddbac.desktop']),
('', ['launchdaemon.sh']), ('', ['launchdaemon.sh']),
('/usr/share/pixmaps', ['other/wicd.png']), ('/usr/share/pixmaps', ['other/wicd.png']),
('images', ['images/good-signal.png', 'images/low-signal.png', ('images', [('images/' + b) for b in os.listdir('images') if not b.startswith('.')]),
'images/no-signal.png', 'images/good-signal-lock.png' ,'images/wired.png', ('encryption/templates', [('encryption/templates/' + b) for b in os.listdir('encryption/templates') if not b.startswith('.')]),
'images/wicd-purple.png', 'images/signal-25.png', 'images/signal-50.png', ('encryption/configurations', []),
'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']),
('data', ['data/wicd.png', 'data/wicd.glade']), ('data', ['data/wicd.png', 'data/wicd.glade']),
('translations', ['translations/wicd.pot', 'translations/ids']), ('translations', ['translations/wicd.pot', 'translations/ids']),
('translations/de_DE/LC_MESSAGES', ['translations/de_DE/LC_MESSAGES/wicd.mo']), ('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/gl_GL/LC_MESSAGES', ['translations/gl_GL/LC_MESSAGES/wicd.mo']),
('translations/no_NO/LC_MESSAGES', ['translations/no_NO/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/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', [('translations/po/' + b) for b in os.listdir('translations/po') if not b.startswith('.')]),
'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/sl_SI/LC_MESSAGES', ['translations/sl_SI/LC_MESSAGES/wicd.mo']), ('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/da_DK/LC_MESSAGES', ['translations/da_DK/LC_MESSAGES/wicd.mo']),
('translations/ja_JA/LC_MESSAGES', ['translations/ja_JA/LC_MESSAGES/wicd.mo']), ('translations/ja_JA/LC_MESSAGES', ['translations/ja_JA/LC_MESSAGES/wicd.mo']),

View File

@@ -110,6 +110,7 @@ language['killswitch_enabled'] = _('Wireless Kill Switch Enabled')
language['connecting'] = _('Connecting') language['connecting'] = _('Connecting')
language['wired'] = _('Wired Network') language['wired'] = _('Wired Network')
class TrayIcon: class TrayIcon:
""" Base Tray Icon class. """ Base Tray Icon class.
@@ -143,7 +144,7 @@ class TrayIcon:
self.update_tray_icon() self.update_tray_icon()
def wired_profile_chooser(self): def wired_profile_chooser(self):
"""Launch the wired profile chooser.""" """ Launch the wired profile chooser. """
gui.WiredProfileChooser() gui.WiredProfileChooser()
daemon.SetNeedWiredProfileChooser(False) daemon.SetNeedWiredProfileChooser(False)
@@ -390,6 +391,8 @@ class TrayIcon:
""" Tray Icon for gtk < 2.10. """ Tray Icon for gtk < 2.10.
Uses the deprecated egg.trayicon module to implement the tray icon. 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): def __init__(self, use_tray=True):
@@ -451,7 +454,6 @@ class TrayIcon:
gtk.StatusIcon.__init__(self) gtk.StatusIcon.__init__(self)
self.current_icon_path = '' self.current_icon_path = ''
daemon.SetForcedDisconnect(False)
self.set_visible(True) self.set_visible(True)
self.connect('activate', self.on_activate) self.connect('activate', self.on_activate)
self.connect('popup-menu', self.on_popup_menu) self.connect('popup-menu', self.on_popup_menu)

View File

@@ -155,6 +155,15 @@ def _fast_get_wifi_interfaces():
return None return None
def get_iw_ioctl_result(iface, call): 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) s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
buff = array.array('c', '\0' * 32) buff = array.array('c', '\0' * 32)
addr, length = buff.buffer_info() addr, length = buff.buffer_info()
@@ -205,6 +214,17 @@ class Interface(object):
self.iface = str(iface) self.iface = str(iface)
def _find_client_path(self, client): 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/', paths = ['/sbin/', '/usr/sbin/', '/bin/', '/usr/bin/',
'/usr/local/sbin/', '/usr/local/bin/'] '/usr/local/sbin/', '/usr/local/bin/']
for path in paths: for path in paths:
@@ -215,7 +235,14 @@ class Interface(object):
return None return None
def _client_found(self, client): 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) output = misc.Run("which " + client)
if output and not ("no " + client) in output: if output and not ("no " + client) in output:
return True return True
@@ -539,6 +566,7 @@ class Interface(object):
return False return False
def _fast_is_up(self): def _fast_is_up(self):
""" Determines if the interfae is up using an ioctl call. """
data = (self.iface + '\0' * 16)[:18] data = (self.iface + '\0' * 16)[:18]
try: try:
result = fcntl.ioctl(self.sock.fileno(), SIOCGIFFLAGS, data) result = fcntl.ioctl(self.sock.fileno(), SIOCGIFFLAGS, data)
@@ -551,7 +579,6 @@ class Interface(object):
return bool(flags & 1) return bool(flags & 1)
class WiredInterface(Interface): class WiredInterface(Interface):
""" Control a wired network interface. """ """ Control a wired network interface. """
def __init__(self, iface, verbose=False): def __init__(self, iface, verbose=False):
@@ -608,6 +635,14 @@ class WiredInterface(Interface):
return False return False
def _fast_eth_get_plugged_in(self): 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(): if not self.IsUp():
self.Up() self.Up()
time.sleep(2.5) time.sleep(2.5)
@@ -649,7 +684,7 @@ class WiredInterface(Interface):
return False return False
def _fast_mii_get_plugged_in(self): 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(): if not self.IsUp():
self.Up() self.Up()
time.sleep(2.5) time.sleep(2.5)
@@ -1199,6 +1234,12 @@ class WirelessInterface(Interface):
return dbm_strength return dbm_strength
def _get_dbm_strength_fast(self): 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) buff = misc.get_irwange_ioctl_result(self.iface, SIOCGIWSTATS)
if not buff: if not buff:
return None return None