1
0
mirror of https://github.com/gryf/wicd.git synced 2026-03-13 13:15:47 +01:00

Merged mainline.

This commit is contained in:
Robby Workman
2009-02-11 21:38:38 -06:00
8 changed files with 68 additions and 50 deletions

View File

@@ -223,10 +223,7 @@ class appGui(object):
self._do_statusbar_update(*daemon.GetConnectionStatus()) self._do_statusbar_update(*daemon.GetConnectionStatus())
self.wait_for_events(0.1) self.wait_for_events(0.1)
if hasattr(gobject, "timeout_add_seconds"): self.update_cb = misc.timeout_add(2, self.update_statusbar)
self.update_cb = gobject.timeout_add_seconds(2, self.update_statusbar)
else:
self.update_cb = gobject.timeout_add(2000, self.update_statusbar)
self.refresh_clicked() self.refresh_clicked()
def handle_connection_results(self, results): def handle_connection_results(self, results):
@@ -393,26 +390,32 @@ class appGui(object):
return True return True
def set_not_connected_state(self, info): def set_not_connected_state(self, info):
self.connecting = False if self.connecting:
self._set_not_connecting_state() self._set_not_connecting_state()
self.set_status(language['not_connected']) self.set_status(language['not_connected'])
return True return True
def _set_not_connecting_state(self): def _set_not_connecting_state(self):
self.connecting = False if self.connecting:
gobject.source_remove(self.update_cb)
self.update_cb = misc.timeout_add(2, self.update_statusbar)
self.connecting = False
if self.pulse_active: if self.pulse_active:
self.pulse_active = False self.pulse_active = False
gobject.idle_add(self.network_list.set_sensitive, True) gobject.idle_add(self.network_list.set_sensitive, True)
gobject.idle_add(self.status_area.hide_all) gobject.idle_add(self.status_area.hide_all)
if self.statusID: if self.statusID:
gobject.idle_add(self.status_bar.remove, 1, self.statusID) gobject.idle_add(self.status_bar.remove, 1, self.statusID)
def set_connecting_state(self, info): def set_connecting_state(self, info):
self.connecting = True if not self.connecting:
gobject.source_remove(self.update_cb)
self.update_cb = misc.timeout_add(500, self.update_statusbar,
milli=True)
self.connecting = True
if not self.pulse_active: if not self.pulse_active:
self.pulse_active = True self.pulse_active = True
gobject.timeout_add(100, self.pulse_progress_bar) misc.timeout_add(100, self.pulse_progress_bar, milli=True)
gobject.idle_add(self.network_list.set_sensitive, False) gobject.idle_add(self.network_list.set_sensitive, False)
gobject.idle_add(self.status_area.show_all) gobject.idle_add(self.status_area.show_all)
if self.statusID: if self.statusID:
@@ -713,12 +716,10 @@ class appGui(object):
daemon.SetGUIOpen(True) daemon.SetGUIOpen(True)
self.wait_for_events(0.1) self.wait_for_events(0.1)
gobject.idle_add(self.refresh_clicked) gobject.idle_add(self.refresh_clicked)
self._do_statusbar_update(*daemon.GetConnectionStatus())
bus.add_signal_receiver(self._do_statusbar_update, 'StatusChanged', bus.add_signal_receiver(self._do_statusbar_update, 'StatusChanged',
'org.wicd.daemon') 'org.wicd.daemon')
if hasattr(gobject, "timeout_add_seconds"): self.update_cb = misc.timeout_add(2, self.update_statusbar)
self.update_cb = gobject.timeout_add_seconds(2, self.update_statusbar)
else:
self.update_cb = gobject.timeout_add(2000, self.update_statusbar)
if __name__ == '__main__': if __name__ == '__main__':

View File

@@ -22,6 +22,7 @@ import locale
import gettext import gettext
import sys import sys
import re import re
import gobject
from threading import Thread from threading import Thread
from subprocess import Popen, STDOUT, PIPE, call from subprocess import Popen, STDOUT, PIPE, call
from commands import getoutput from commands import getoutput
@@ -68,7 +69,7 @@ class WicdError(Exception):
__LANG = None __LANG = None
def Run(cmd, include_stderr=False, return_pipe=False): def Run(cmd, include_stderr=False, return_pipe=False, return_obj=False):
""" Run a command. """ Run a command.
Runs the given command, returning either the output Runs the given command, returning either the output
@@ -111,6 +112,8 @@ def Run(cmd, include_stderr=False, return_pipe=False):
return "" return ""
if return_obj:
return f
if return_pipe: if return_pipe:
return f.stdout return f.stdout
else: else:
@@ -421,7 +424,6 @@ def choose_sudo_prog(prog_num=0):
for path in paths: for path in paths:
if os.path.exists(path): if os.path.exists(path):
print "returning %s" % path
return path return path
return None return None
@@ -461,6 +463,7 @@ def get_language_list_gui():
language['use_static_dns'] = _('Use Static DNS') language['use_static_dns'] = _('Use Static DNS')
language['use_encryption'] = _('Use Encryption') language['use_encryption'] = _('Use Encryption')
language['advanced_settings'] = _('Advanced Settings') language['advanced_settings'] = _('Advanced Settings')
language['properties'] = _('Properties')
language['wired_network'] = _('Wired Network') language['wired_network'] = _('Wired Network')
language['wired_network_instructions'] = _('To connect to a wired network,' language['wired_network_instructions'] = _('To connect to a wired network,'
' you must create a network profile. To create a network profile, type a' ' you must create a network profile. To create a network profile, type a'
@@ -656,3 +659,12 @@ def threaded(f):
wrapper.__module__ = f.__module__ wrapper.__module__ = f.__module__
return wrapper return wrapper
def timeout_add(time, func, milli=False):
""" Convience function for running a function on a timer. """
if hasattr(gobject, "timeout_add_seconds") and not milli:
return gobject.timeout_add_seconds(time, func)
else:
if not milli: time = time * 1000
return gobject.timeout_add(time, func)

View File

@@ -54,6 +54,8 @@ def diewithdbus(func):
self.__lost_dbus_count = 0 self.__lost_dbus_count = 0
return ret return ret
except dbusmanager.DBusException: except dbusmanager.DBusException:
if not hasattr(self, "__lost_dbus_count"):
self.__lost_dbus_count = 0
if self.__lost_dbus_count > 3: if self.__lost_dbus_count > 3:
sys.exit(1) sys.exit(1)
self.__lost_dbus_count += 1 self.__lost_dbus_count += 1
@@ -330,12 +332,8 @@ def err_handle(error):
def add_poll_callback(): def add_poll_callback():
global monitor, to_time, update_callback global monitor, to_time, update_callback
if hasattr(gobject, "timeout_add_seconds"): update_callback = misc.timeout_add(to_time,
update_callback = gobject.timeout_add_seconds(to_time, monitor.update_connection_status)
monitor.update_connection_status)
else:
update_callback = gobject.timeout_add(to_time * 1000,
monitor.update_connection_status)
def main(): def main():
""" Starts the connection monitor. """ Starts the connection monitor.

View File

@@ -45,7 +45,7 @@ class AdvancedSettingsDialog(gtk.Dialog):
the WiredSettingsDialog and WirelessSettingsDialog. the WiredSettingsDialog and WirelessSettingsDialog.
""" """
gtk.Dialog.__init__(self, title=language['advanced_settings'], gtk.Dialog.__init__(self, title=language['properties'],
flags=gtk.DIALOG_MODAL, buttons=(gtk.STOCK_CANCEL, flags=gtk.DIALOG_MODAL, buttons=(gtk.STOCK_CANCEL,
gtk.RESPONSE_REJECT, gtk.RESPONSE_REJECT,
gtk.STOCK_OK, gtk.STOCK_OK,
@@ -149,7 +149,6 @@ class AdvancedSettingsDialog(gtk.Dialog):
self.chkbox_static_dns.set_sensitive(False) self.chkbox_static_dns.set_sensitive(False)
else: else:
self.chkbox_static_dns.set_sensitive(True) self.chkbox_static_dns.set_sensitive(True)
#self.chkbox_static_dns.set_active(False)
self.txt_ip.set_sensitive(self.chkbox_static_ip.get_active()) self.txt_ip.set_sensitive(self.chkbox_static_ip.get_active())
self.txt_netmask.set_sensitive(self.chkbox_static_ip.get_active()) self.txt_netmask.set_sensitive(self.chkbox_static_ip.get_active())
@@ -513,18 +512,13 @@ class NetworkEntry(gtk.HBox):
self.advanced_image.set_from_stock(gtk.STOCK_EDIT, 4) self.advanced_image.set_from_stock(gtk.STOCK_EDIT, 4)
self.advanced_image.set_padding(4, 0) self.advanced_image.set_padding(4, 0)
self.advanced_button.set_alignment(.5, .5) self.advanced_button.set_alignment(.5, .5)
self.advanced_button.set_label(language['advanced_settings']) self.advanced_button.set_label(language['properties'])
self.advanced_button.set_image(self.advanced_image) self.advanced_button.set_image(self.advanced_image)
#self.buttons_hbox.pack_start(self.script_button, False, False)
self.buttons_hbox.pack_start(self.connect_hbox, False, False) self.buttons_hbox.pack_start(self.connect_hbox, False, False)
self.buttons_hbox.pack_start(self.advanced_button, False, False) self.buttons_hbox.pack_start(self.advanced_button, False, False)
self.vbox_top = gtk.VBox(False, 0) self.vbox_top = gtk.VBox(False, 0)
#self.vbox_top.pack_end(self.buttons_hbox, False, False)
#self.vbox_top.pack_end(self.connect_hbox, False, False)
self.expander_vbox.pack_start(self.name_label) self.expander_vbox.pack_start(self.name_label)
self.expander_vbox.pack_start(self.vbox_top) self.expander_vbox.pack_start(self.vbox_top)
self.expander_vbox.pack_start(self.buttons_hbox) self.expander_vbox.pack_start(self.buttons_hbox)
@@ -550,7 +544,6 @@ class WiredNetworkEntry(NetworkEntry):
self.name_label.set_label(language['wired_network']) self.name_label.set_label(language['wired_network'])
#self.reset_static_checkboxes()
self.is_full_gui = True self.is_full_gui = True
self.button_add = gtk.Button(stock=gtk.STOCK_ADD) self.button_add = gtk.Button(stock=gtk.STOCK_ADD)
@@ -759,7 +752,6 @@ class WirelessNetworkEntry(NetworkEntry):
# Add the wireless network specific parts to the NetworkEntry # Add the wireless network specific parts to the NetworkEntry
# VBox objects. # VBox objects.
self.vbox_top.pack_start(self.chkbox_autoconnect, False, False) self.vbox_top.pack_start(self.chkbox_autoconnect, False, False)
# self.vbox_top.pack_start(self.hbox_status, True, True)
if to_bool(self.format_entry(networkID, "automatic")): if to_bool(self.format_entry(networkID, "automatic")):
self.chkbox_autoconnect.set_active(True) self.chkbox_autoconnect.set_active(True)
@@ -813,11 +805,11 @@ class WirelessNetworkEntry(NetworkEntry):
def set_signal_strength(self, strength, dbm_strength): def set_signal_strength(self, strength, dbm_strength):
""" Set the signal strength displayed in the WirelessNetworkEntry. """ """ Set the signal strength displayed in the WirelessNetworkEntry. """
if strength is not None: if strength:
strength = int(strength) strength = int(strength)
else: else:
strength = -1 strength = -1
if dbm_strength is not None: if dbm_strength:
dbm_strength = int(dbm_strength) dbm_strength = int(dbm_strength)
else: else:
dbm_strength = -100 dbm_strength = -100

View File

@@ -44,7 +44,9 @@ class WiredConnectThread() -- Connection thread for wired
import re import re
import time import time
import threading import threading
import os
import thread import thread
from signal import SIGTERM
# wicd imports # wicd imports
import misc import misc
@@ -202,7 +204,8 @@ class Controller(object):
iface = self.iface iface = self.iface
if self.disconnect_script != None: if self.disconnect_script != None:
print 'Running disconnect script' print 'Running disconnect script'
misc.ExecuteScript(expand_script_macros(self.disconnect_script, 'disconnection', *args)) misc.ExecuteScript(expand_script_macros(self.disconnect_script,
'disconnection', *args))
iface.ReleaseDHCP() iface.ReleaseDHCP()
iface.SetAddress('0.0.0.0') iface.SetAddress('0.0.0.0')
iface.FlushRoutes() iface.FlushRoutes()
@@ -213,6 +216,14 @@ class Controller(object):
""" Release the DHCP lease for this interface. """ """ Release the DHCP lease for this interface. """
return self.iface.ReleaseDHCP() return self.iface.ReleaseDHCP()
def KillDHCP(self):
""" Kill the managed DHCP client if its in a connecting state. """
if (self.connecting_thread.is_connecting and
self.iface.dhcp_object):
if self.iface.dhcp_object.poll() is None:
os.kill(self.iface.dhcp_object.pid, SIGTERM)
self.iface.dhcp_object = None
def IsUp(self): def IsUp(self):
""" Calls the IsUp method for the wired interface. """ Calls the IsUp method for the wired interface.
@@ -254,7 +265,6 @@ class ConnectThread(threading.Thread):
""" """
is_connecting = None is_connecting = None
connecting_thread = None
should_die = False should_die = False
lock = thread.allocate_lock() lock = thread.allocate_lock()
@@ -405,7 +415,8 @@ class ConnectThread(threading.Thread):
print "Running DHCP" print "Running DHCP"
dhcp_status = iface.StartDHCP() dhcp_status = iface.StartDHCP()
if dhcp_status in ['no_dhcp_offers', 'dhcp_failed']: if dhcp_status in ['no_dhcp_offers', 'dhcp_failed']:
self.abort_connection(dhcp_status) if self.connect_result != "aborted":
self.abort_connection(dhcp_status)
return return
@abortable @abortable

View File

@@ -69,7 +69,7 @@ misc.RenameProcess("wicd-client")
if __name__ == '__main__': if __name__ == '__main__':
wpath.chdir(__file__) wpath.chdir(__file__)
daemon = wireless = wired = None daemon = wireless = wired = lost_dbus_id = None
DBUS_AVAIL = False DBUS_AVAIL = False
language = misc.get_language_list_tray() language = misc.get_language_list_tray()
@@ -80,7 +80,7 @@ def catchdbus(func):
try: try:
return func(*args, **kwargs) return func(*args, **kwargs)
except DBusException, e: except DBusException, e:
print "warning: ignoring exception %s" % egg print "warning: ignoring exception %s" % e
return None return None
wrapper.__name__ = func.__name__ wrapper.__name__ = func.__name__
wrapper.__module__ = func.__module__ wrapper.__module__ = func.__module__
@@ -664,7 +664,7 @@ Arguments:
""" % wpath.version """ % wpath.version
def setup_dbus(force=True): def setup_dbus(force=True):
global daemon, wireless, wired, DBUS_AVAIL global daemon, wireless, wired, DBUS_AVAIL, lost_dbus_id
print "Connecting to daemon..." print "Connecting to daemon..."
try: try:
dbusmanager.connect_to_dbus() dbusmanager.connect_to_dbus()
@@ -681,13 +681,15 @@ def setup_dbus(force=True):
else: else:
return False return False
if lost_dbus_id:
gobject.source_remove(lost_dbus_id)
lost_dbus_id = None
dbus_ifaces = dbusmanager.get_dbus_ifaces() dbus_ifaces = dbusmanager.get_dbus_ifaces()
daemon = dbus_ifaces['daemon'] daemon = dbus_ifaces['daemon']
wireless = dbus_ifaces['wireless'] wireless = dbus_ifaces['wireless']
wired = dbus_ifaces['wired'] wired = dbus_ifaces['wired']
DBUS_AVAIL = True DBUS_AVAIL = True
print "Connected." print "Connected."
return True return True
def on_exit(): def on_exit():
@@ -698,11 +700,13 @@ def on_exit():
pass pass
def handle_no_dbus(): def handle_no_dbus():
global DBUS_AVAIL """ Called when dbus announces its shutting down. """
global DBUS_AVAIL, lost_dbus_id
DBUS_AVAIL = False DBUS_AVAIL = False
gui.handle_no_dbus(from_tray=True) gui.handle_no_dbus(from_tray=True)
print "Wicd daemon is shutting down!" print "Wicd daemon is shutting down!"
error(None, language['lost_dbus'], block=False) lost_dbus_id = misc.timeout_add(5, lambda:error(None, language['lost_dbus'],
block=False))
return False return False
def main(argv): def main(argv):

View File

@@ -380,6 +380,9 @@ class WicdDaemon(dbus.service.Object):
if self.wifi.connecting_thread: if self.wifi.connecting_thread:
self.wifi.connecting_thread.should_die = True self.wifi.connecting_thread.should_die = True
self.wifi.ReleaseDHCP() self.wifi.ReleaseDHCP()
# We have to actually kill dhcp if its still hanging
# around. It could still be trying to get a lease.
self.wifi.KillDHCP()
self.wifi.StopWPA() self.wifi.StopWPA()
self.wifi.connecting_thread.connect_result = 'aborted' self.wifi.connecting_thread.connect_result = 'aborted'
if self.wired.connecting_thread: if self.wired.connecting_thread:
@@ -1012,10 +1015,7 @@ class WirelessDaemon(dbus.service.Object):
value = self.LastScan[networkid].get(property) value = self.LastScan[networkid].get(property)
except IndexError: except IndexError:
return "" return ""
try: value = misc.to_unicode(value)
value = misc.to_unicode(value)
except:
pass
return value return value
@dbus.service.method('org.wicd.daemon.wireless') @dbus.service.method('org.wicd.daemon.wireless')
@@ -1027,14 +1027,13 @@ class WirelessDaemon(dbus.service.Object):
+ " permitted." + " permitted."
return False return False
self.LastScan[networkid][property] = misc.Noneify(value) self.LastScan[networkid][property] = misc.Noneify(value)
#end function SetProperty
@dbus.service.method('org.wicd.daemon.wireless') @dbus.service.method('org.wicd.daemon.wireless')
def DetectWirelessInterface(self): def DetectWirelessInterface(self):
""" Returns an automatically detected wireless interface. """ """ Returns an automatically detected wireless interface. """
iface = self.wifi.DetectWirelessInterface() iface = self.wifi.DetectWirelessInterface()
if iface: if iface:
print 'automatically detected wireless interface ' + iface print 'Automatically detected wireless interface ' + iface
else: else:
print "Couldn't detect a wireless interface." print "Couldn't detect a wireless interface."
return str(iface) return str(iface)

View File

@@ -453,7 +453,8 @@ class BaseInterface(object):
cmd = self._get_dhcp_command('connect') cmd = self._get_dhcp_command('connect')
#cmd = self.DHCP_CMD + " " + self.iface #cmd = self.DHCP_CMD + " " + self.iface
if self.verbose: print cmd if self.verbose: print cmd
pipe = misc.Run(cmd, include_stderr=True, return_pipe=True) self.dhcp_object = misc.Run(cmd, include_stderr=True, return_obj=True)
pipe = self.dhcp_object.stdout
DHCP_CLIENT = self.DHCP_CLIENT DHCP_CLIENT = self.DHCP_CLIENT
if DHCP_CLIENT == misc.DHCLIENT: if DHCP_CLIENT == misc.DHCLIENT: