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

Initial work on automatic switchover to wired networks (no UI work yet)

actually use "write=True" instead of just "True" everywhere we do config writes explicitly.
Fix the scripts dialog not working for wired connections.
Force the monitor to update state after triggering a disconnect or connect.
Remove an unneeded Scan call from autoconnect.py
This commit is contained in:
Dan O'Reilly
2009-01-24 23:31:24 -05:00
parent 290006629b
commit ec37206905
8 changed files with 70 additions and 41 deletions

View File

@@ -49,7 +49,6 @@ def error_handler(*args):
if __name__ == '__main__':
try:
time.sleep(2)
wireless.Scan(True)
daemon.SetSuspend(False)
if not daemon.CheckIfConnecting():
daemon.AutoConnect(True, reply_handler=handler, error_handler=handler)

View File

@@ -376,9 +376,8 @@ class WirelessInterface(Interface, wnettools.BaseWirelessInterface):
False otherwise.
"""
def error():
print "Unable to find ctrl_interface for wpa_supplicant. " + \
"Could not validate authentication."
error= "Unable to find ctrl_interface for wpa_supplicant. " + \
"Could not validate authentication."
# Right now there's no way to do this for ralink drivers
if self.wpa_driver == RALINK_DRIVER:
@@ -389,7 +388,7 @@ class WirelessInterface(Interface, wnettools.BaseWirelessInterface):
socket = [os.path.join(ctrl_iface, s) \
for s in os.listdir(ctrl_iface) if s == self.iface][0]
except OSError:
error()
print error
return True
wpa = wpactrl.WPACtrl(socket)

View File

@@ -48,7 +48,7 @@ class ConfigManager(RawConfigParser):
""" Returns the path to the loaded config file. """
return self.config_file
def set_option(self, section, option, value, save=False):
def set_option(self, section, option, value, write=False):
""" Wrapper around ConfigParser.set
Adds the option to write the config file change right away.
@@ -65,7 +65,7 @@ class ConfigManager(RawConfigParser):
value = "%(ws)s%(value)s%(ws)s" % {"value" : value,
"ws" : self.mrk_ws}
RawConfigParser.set(self, section, str(option), value)
if save:
if write:
self.write()
def set(self, *args, **kargs):
@@ -98,7 +98,7 @@ class ConfigManager(RawConfigParser):
else:
if default != "__None__":
print 'did not find %s in configuration, setting default %s' % (option, str(default))
self.set(section, option, str(default), save=True)
self.set(section, option, str(default), write=True)
ret = default
else:
ret = None

View File

@@ -706,15 +706,14 @@ class appGui(object):
[width, height] = self.window.get_size()
try:
daemon.WriteWindowSize(width, height, "main")
except:
daemon.SetGUIOpen(False)
except dbusmanager.DBusException:
pass
if self.standalone:
sys.exit(0)
self.is_visible = False
daemon.SetGUIOpen(False)
self.wait_for_events()
return True
def show_win(self):

View File

@@ -63,20 +63,29 @@ class ConnectionStatus(object):
self.last_reconnect_time = time.time()
self.signal_changed = False
self.iwconfig = ""
self.trigger_reconnect = False
bus = dbusmanager.get_bus()
bus.add_signal_receiver(self._force_update_connection_status,
"UpdateState", "org.wicd.daemon")
def check_for_wired_connection(self, wired_ip):
""" Checks for an active wired connection.
""" Checks for a wired connection.
Checks for and updates the tray icon for an active wired connection
Returns True if wired connection is active, false if inactive.
Checks for two states:
1) A wired connection is not in use, but a cable is plugged
in, and the user has chosen to switch to a wired connection
whenever its available, even if already connected to a
wireless network
2) A wired connection is currently active.
"""
if not wired_ip and daemon.GetPreferWiredNetwork():
if not daemon.GetForcedDisconnect() and wired.CheckPluggedIn():
self.trigger_reconnect = True
if wired_ip and wired.CheckPluggedIn():
elif wired_ip and wired.CheckPluggedIn():
# Only change the interface if it's not already set for wired
if not self.still_wired:
daemon.SetCurrentInterface(daemon.GetWiredInterface())
@@ -89,14 +98,17 @@ class ConnectionStatus(object):
def check_for_wireless_connection(self, wireless_ip):
""" Checks for an active wireless connection.
Checks for and updates the tray icon for an active
wireless connection. Returns True if wireless connection
is active, and False otherwise.
Checks for an active wireless connection. Also notes
if the signal strength is 0, and if it remains there
for too long, triggers a wireless disconnect.
Returns True if wireless connection is active, and
False otherwise.
"""
# Make sure we have an IP before we do anything else.
if wireless_ip is None:
if not wireless_ip:
return False
if daemon.NeedsExternalCalls():
@@ -158,6 +170,15 @@ class ConnectionStatus(object):
# Check for wired.
wired_ip = wired.GetWiredIP("")
wired_found = self.check_for_wired_connection(wired_ip)
# Trigger an AutoConnect if we're plugged in, not connected
# to a wired network, and the "autoswitch to wired" option
# is on.
if self.trigger_reconnect:
self.trigger_reconnect = False
wireless.DisconnectWireless()
daemon.AutoConnect(False, reply_handler=lambda:None,
error_handler=lambda:None)
return True
if wired_found:
self.update_state(misc.WIRED, wired_ip=wired_ip)
return True

View File

@@ -234,7 +234,7 @@ class WiredSettingsDialog(AdvancedSettingsDialog):
def edit_scripts(self, widget=None, event=None):
""" Launch the script editting dialog. """
profile = self.combo_profile_names.get_active_text()
profile = self.prof_name
cmdend = [os.path.join(wpath.lib, "configscript.py"), profile, "wired"]
if os.getuid() != 0:
cmdbase = misc.get_sudo_cmd(language['scripts_need_pass'])
@@ -695,6 +695,7 @@ class WiredNetworkEntry(NetworkEntry):
return
profile_name = self.combo_profile_names.get_active_text()
self.advanced_dialog.prof_name = profile_name
wired.ReadWiredNetworkProfile(profile_name)
self.advanced_dialog.txt_ip.set_text(self.format_entry("ip"))

View File

@@ -741,7 +741,8 @@ class WirelessConnectThread(ConnectThread):
self.is_connecting = True
# Run pre-connection script.
self.run_script_if_needed(self.before_script, 'pre-connection', self.network['bssid'], self.network['essid'])
self.run_script_if_needed(self.before_script, 'pre-connection',
self.network['bssid'], self.network['essid'])
# Take down interface and clean up previous connections.
@@ -783,7 +784,8 @@ class WirelessConnectThread(ConnectThread):
self.set_dns_addresses()
# Run post-connection script.
self.run_script_if_needed(self.after_script, 'post-connection', self.network['bssid'], self.network['essid'])
self.run_script_if_needed(self.after_script, 'post-connection',
self.network['bssid'], self.network['essid'])
self.SetStatus('done')
print 'Connecting thread exiting.'
@@ -947,7 +949,8 @@ class WiredConnectThread(ConnectThread):
self.is_connecting = True
# Run pre-connection script.
self.run_script_if_needed(self.before_script, 'pre-connection', 'wired', 'wired')
self.run_script_if_needed(self.before_script, 'pre-connection', 'wired',
'wired')
# Take down interface and clean up previous connections.
self.put_iface_down(liface)
@@ -965,7 +968,8 @@ class WiredConnectThread(ConnectThread):
self.set_dns_addresses()
# Run post-connection script.
self.run_script_if_needed(self.after_script, 'post-connection', 'wired', 'wired')
self.run_script_if_needed(self.after_script, 'post-connection', 'wired',
'wired')
self.SetStatus('done')
print 'Connecting thread exiting.'

View File

@@ -141,28 +141,28 @@ class WicdDaemon(dbus.service.Object):
""" Sets the wired interface for the daemon to use. """
print "setting wired interface %s" % (str(interface))
self.wired.wired_interface = noneToBlankString(interface)
self.config.set("Settings", "wired_interface", interface, True)
self.config.set("Settings", "wired_interface", interface, write=True)
@dbus.service.method('org.wicd.daemon')
def SetWirelessInterface(self, interface):
""" Sets the wireless interface the daemon will use. """
print "setting wireless interface %s" % (str(interface))
self.wifi.wireless_interface = noneToBlankString(interface)
self.config.set("Settings", "wireless_interface", interface, True)
self.config.set("Settings", "wireless_interface", interface, write=True)
@dbus.service.method('org.wicd.daemon')
def SetWPADriver(self, driver):
""" Sets the wpa driver the wpa_supplicant will use. """
print "setting wpa driver", str(driver)
self.wifi.wpa_driver = driver
self.config.set("Settings", "wpa_driver", driver, True)
self.config.set("Settings", "wpa_driver", driver, write=True)
@dbus.service.method('org.wicd.daemon')
def SetUseGlobalDNS(self, use):
""" Sets a boolean which determines if global DNS is enabled. """
print 'setting use global dns to', use
use = misc.to_bool(use)
self.config.set("Settings", "use_global_dns", use, True)
self.config.set("Settings", "use_global_dns", use, write=True)
self.use_global_dns = use
self.wifi.use_global_dns = use
self.wired.use_global_dns = use
@@ -197,12 +197,11 @@ class WicdDaemon(dbus.service.Object):
print 'search domain is %s' % search_dom
self.config.write()
@dbus.service.method('org.wicd.daemon')
def SetBackend(self, backend):
""" Sets a new backend. """
print "setting backend to %s" % backend
self.config.set("Settings", "backend", backend, True)
self.config.set("Settings", "backend", backend, write=True)
if backend != self.GetCurrentBackend():
self.suspended = True
self.wifi.LoadBackend(backend)
@@ -272,7 +271,7 @@ class WicdDaemon(dbus.service.Object):
@dbus.service.method('org.wicd.daemon')
def SetDebugMode(self, debug):
""" Sets if debugging mode is on or off. """
self.config.set("Settings", "debug_mode", debug, True)
self.config.set("Settings", "debug_mode", debug, write=True)
self.debug_mode = misc.to_bool(debug)
self.wifi.debug = self.debug_mode
self.wired.debug = self.debug_mode
@@ -352,7 +351,8 @@ class WicdDaemon(dbus.service.Object):
"""
print 'setting automatically reconnect when connection drops %s' % value
self.config.set("Settings", "auto_reconnect", misc.to_bool(value), True)
self.config.set("Settings", "auto_reconnect", misc.to_bool(value),
write=True)
self.auto_reconnect = misc.to_bool(value)
@dbus.service.method('org.wicd.daemon')
@@ -453,7 +453,7 @@ class WicdDaemon(dbus.service.Object):
@dbus.service.method('org.wicd.daemon')
def SetSignalDisplayType(self, value):
""" Sets the signal display type and writes it the wicd config file. """
self.config.set("Settings", "signal_display_type", value, True)
self.config.set("Settings", "signal_display_type", value, write=True)
self.signal_display_type = int(value)
@dbus.service.method('org.wicd.daemon')
@@ -483,7 +483,7 @@ class WicdDaemon(dbus.service.Object):
def SetAlwaysShowWiredInterface(self, value):
""" Sets always_show_wired_interface to the given value. """
self.config.set("Settings", "always_show_wired_interface",
misc.to_bool(value), True)
misc.to_bool(value), write=True)
self.always_show_wired_interface = misc.to_bool(value)
@dbus.service.method('org.wicd.daemon')
@@ -497,7 +497,8 @@ class WicdDaemon(dbus.service.Object):
# 1 = default profile
# 2 = show list
# 3 = last used profile
self.config.set("Settings","wired_connect_mode", int(method), True)
self.config.set("Settings","wired_connect_mode", int(method),
write=True)
self.wired_connect_mode = int(method)
self.wired_bus.connect_mode = int(method)
@@ -505,9 +506,8 @@ class WicdDaemon(dbus.service.Object):
def GetWiredAutoConnectMethod(self):
""" Returns the wired autoconnect method. """
return int(self.wired_connect_mode)
@dbus.service.method('org.wicd.dameon')
@dbus.service.method('org.wicd.daemon')
def GetPreferWiredNetwork(self):
""" Returns True if wired network preference is set.
@@ -520,6 +520,7 @@ class WicdDaemon(dbus.service.Object):
@dbus.service.method('org.wicd.daemon')
def SetPreferWiredNetwork(self, value):
""" Sets the prefer_wired state. """
self.config.set("Settings", "prefer_wired", bool(value), write=True)
self.prefer_wired = bool(value)
@dbus.service.method('org.wicd.daemon')
@@ -589,7 +590,7 @@ class WicdDaemon(dbus.service.Object):
self.dhcp_client = int(client)
self.wifi.dhcp_client = int(client)
self.wired.dhcp_client = int(client)
self.config.set("Settings", "dhcp_client", client, True)
self.config.set("Settings", "dhcp_client", client, write=True)
@dbus.service.method('org.wicd.daemon')
def GetLinkDetectionTool(self):
@@ -609,7 +610,7 @@ class WicdDaemon(dbus.service.Object):
"""
self.link_detect_tool = int(link_tool)
self.wired.link_tool = int(link_tool)
self.config.set("Settings", "link_detect_tool", link_tool, True)
self.config.set("Settings", "link_detect_tool", link_tool, write=True)
@dbus.service.method('org.wicd.daemon')
def GetFlushTool(self):
@@ -628,7 +629,7 @@ class WicdDaemon(dbus.service.Object):
self.flush_tool = int(flush_tool)
self.wired.flush_tool = int(flush_tool)
self.wifi.flush_tool = int(flush_tool)
self.config.set("Settings", "flush_tool", flush_tool, True)
self.config.set("Settings", "flush_tool", flush_tool, write=True)
@dbus.service.method('org.wicd.daemon')
def WriteWindowSize(self, width, height, win_name):
@@ -1018,6 +1019,7 @@ class WirelessDaemon(dbus.service.Object):
""" Disconnects the wireless network. """
self.SetForcedDisconnect(True)
self.wifi.Disconnect()
self.daemon.UpdateState()
@dbus.service.method('org.wicd.daemon.wireless')
def GetForcedDisconnect(self):
@@ -1100,6 +1102,7 @@ class WirelessDaemon(dbus.service.Object):
'disconnectscript')
print 'Connecting to wireless network ' + self.LastScan[id]['essid']
conthread = self.wifi.Connect(self.LastScan[id], debug=self.debug_mode)
self.daemon.UpdateState()
@dbus.service.method('org.wicd.daemon.wireless')
def CheckIfWirelessConnecting(self):
@@ -1354,6 +1357,7 @@ class WiredDaemon(dbus.service.Object):
""" Disconnects the wired network. """
self.SetForcedDisconnect(True)
self.wired.Disconnect()
self.daemon.UpdateState()
@dbus.service.method('org.wicd.daemon.wired')
def CheckPluggedIn(self):
@@ -1402,6 +1406,7 @@ class WiredDaemon(dbus.service.Object):
self.wired.after_script = self.GetWiredProperty("afterscript")
self.wired.disconnect_script = self.GetWiredProperty("disconnectscript")
self.wired.Connect(self.WiredNetwork, debug=self.debug_mode)
self.daemon.UpdateState()
@dbus.service.method('org.wicd.daemon.wired')
def CreateWiredNetworkProfile(self, profilename, default=False):
@@ -1474,6 +1479,7 @@ class WiredDaemon(dbus.service.Object):
self.config.set(prof, script, None)
if profilename == "":
self.config.write()
return "500: Bad Profile name"
profilename = misc.to_unicode(profilename)
self.config.remove_section(profilename)