From 04b67e9b2e7db389e7bbff09cbb33b030fed02ff Mon Sep 17 00:00:00 2001 From: imdano <> Date: Thu, 13 Mar 2008 14:10:49 +0000 Subject: [PATCH] Made calls to Autoconnect outside the daemon asynchronous. Removed some unnecessary print statements. Added checks to the daemon and configscript.py to make sure the user opening it is root. Fixed formatting problems in class definitions in wicd.py --- autoconnect.py | 11 +++++++++-- configscript.py | 5 ++++- daemon.py | 26 +++++++++++++------------- gui.py | 7 ++----- monitor.py | 15 ++++++++++++--- wicd.py | 6 +++--- wnettools.py | 2 +- 7 files changed, 44 insertions(+), 28 deletions(-) diff --git a/autoconnect.py b/autoconnect.py index ad2b5bc..17ff7b0 100644 --- a/autoconnect.py +++ b/autoconnect.py @@ -24,8 +24,15 @@ bus = dbus.SystemBus() proxy_obj = bus.get_object('org.wicd.daemon', '/org/wicd/daemon') daemon = dbus.Interface(proxy_obj, 'org.wicd.daemon') +def reply_handle(r): + pass +def error_handle(e): + pass + print daemon.Hello() time.sleep(3) daemon.SetSuspend(False) -if daemon.CheckIfConnecting() == False: - print daemon.AutoConnect(True) +daemon.SetForcedDisconnect(False) +if not daemon.CheckIfConnecting(): + print daemon.AutoConnect(True, reply_handler=reply_handle, + error_handler=error_handle) diff --git a/configscript.py b/configscript.py index d58e71e..5b6c48a 100755 --- a/configscript.py +++ b/configscript.py @@ -27,10 +27,10 @@ run as the current user. # import sys +import os import gtk import ConfigParser import dbus -import dbus.service import gtk.glade import wpath @@ -184,4 +184,7 @@ def main (argv): if __name__ == '__main__': + if os.getuid() != 0: + print "Root priviledges are required to configure scripts. Exiting." + sys.exit(0) main(sys.argv) diff --git a/daemon.py b/daemon.py index abb50f0..46829b5 100644 --- a/daemon.py +++ b/daemon.py @@ -371,13 +371,15 @@ class ConnectionWizard(dbus.service.Object): elif self.GetWiredAutoConnectMethod() == 1: network = self.GetDefaultWiredNetwork() if not network: - print "Couldn't find a default wired connection, wired autoconnect failed." + print "Couldn't find a default wired connection," + \ + " wired autoconnect failed." self._wireless_autoconnect() return else: # Assume its last-used. network = self.GetLastUsedWiredNetwork() if not network: - print "no previous wired profile available, wired autoconnect failed." + print "no previous wired profile available, wired " + \ + "autoconnect failed." self._wireless_autoconnect() return self.ReadWiredNetworkProfile(network) @@ -393,18 +395,19 @@ class ConnectionWizard(dbus.service.Object): def _wireless_autoconnect(self): """ Attempts to autoconnect to a wireless network. """ - print "No wired connection present, attempting to autoconnect \ - to wireless network" + print "No wired connection present, attempting to autoconnect" + \ + "to wireless network" if self.GetWirelessInterface() is None: - print 'autoconnect failed because wireless interface returned None' + print 'Autoconnect failed because wireless interface returned None' return for x, network in enumerate(self.LastScan): - if bool(self.LastScan[x]["has_profile"]): - print self.LastScan[x]["essid"] + ' has profile' - if bool(self.LastScan[x].get('automatic')): - print 'trying to automatically connect to...', \ - self.LastScan[x]["essid"] + if bool(network["has_profile"]): + if self.debug_mode: + print network["essid"] + ' has profile' + if bool(network.get('automatic')): + print 'trying to automatically connect to...' + \ + network["essid"] self.ConnectWireless(x) time.sleep(1) return @@ -597,7 +600,6 @@ class ConnectionWizard(dbus.service.Object): @dbus.service.method('org.wicd.daemon.wireless') def SetHiddenNetworkESSID(self, essid): """ Sets the ESSID of a hidden network for use with Scan(). """ - print 'setting hidden essid: ' + str(essid) self.hidden_essid = str(misc.Noneify(essid)) @dbus.service.method('org.wicd.daemon.wireless') @@ -632,7 +634,6 @@ class ConnectionWizard(dbus.service.Object): def CreateAdHocNetwork(self, essid, channel, ip, enctype, key, encused, ics): """ Creates an ad-hoc network using user inputted settings. """ - print 'attempting to create ad-hoc network...' self.wifi.CreateAdHocNetwork(essid, channel, ip, enctype, key, encused, ics) @@ -1253,7 +1254,6 @@ class ConnectionWizard(dbus.service.Object): self.SetSignalDisplayType(self.get_option("Settings", "signal_display_type", default=0)) - else: # Write some defaults maybe? print "Configuration file not found, creating, adding defaults..." diff --git a/gui.py b/gui.py index de48792..508d433 100644 --- a/gui.py +++ b/gui.py @@ -31,6 +31,8 @@ import gobject import dbus import dbus.service import pango +import gtk +import gtk.glade import misc import wpath @@ -42,11 +44,6 @@ try: pygtk.require("2.0") except: pass -try: - import gtk, gtk.glade -except: - print 'Missing GTK and gtk.glade. Aborting.' - sys.exit(1) if getattr(dbus, 'version', (0, 0, 0)) >= (0, 41, 0): import dbus.glib diff --git a/monitor.py b/monitor.py index 85c07fc..ef639ab 100755 --- a/monitor.py +++ b/monitor.py @@ -216,7 +216,8 @@ class ConnectionStatus(): # First try connecting through ethernet if wired.CheckPluggedIn(): print "Wired connection available, trying to connect..." - daemon.AutoConnect(False) + daemon.AutoConnect(False, reply_handler=reply_handle, + error_handler=err_handle) self.reconnecting = False return @@ -231,10 +232,18 @@ class ConnectionStatus(): elif not wireless.CheckIfWirelessConnecting(): print "Couldn't reconnect to last used network, \ scanning for an autoconnect network..." - daemon.AutoConnect(True) + daemon.AutoConnect(True, reply_handler=reply_handle, + error_handler=err_handle) else: - daemon.AutoConnect(True) + daemon.AutoConnect(True, reply_handler=reply_handle, + error_handler=err_handle) self.reconnecting = False + +def reply_handle(r): + pass + +def err_handle(e): + pass def main(): diff --git a/wicd.py b/wicd.py index 709fd16..77223ce 100755 --- a/wicd.py +++ b/wicd.py @@ -111,7 +111,7 @@ language['killswitch_enabled'] = _('Wireless Kill Switch Enabled') language['connecting'] = _('Connecting') language['wired'] = _('Wired Network') -class TrayIcon(): +class TrayIcon: """ Base Tray Icon class. Base Class for implementing a tray icon to display network status. @@ -125,7 +125,7 @@ class TrayIcon(): self.icon_info = self.TrayConnectionInfo(self.tr, use_tray) - class TrayConnectionInfo(): + class TrayConnectionInfo: """ Class for updating the tray icon status. """ def __init__(self, tr, use_tray=True): """ Initialize variables needed for the icon status methods. """ @@ -233,7 +233,7 @@ class TrayIcon(): self.tr.set_from_file(img_file) - class TrayIconGUI(): + class TrayIconGUI: """ Base Tray Icon UI class. Implements methods and variables used by both egg/StatusIcon diff --git a/wnettools.py b/wnettools.py index d9b1821..39870d3 100644 --- a/wnettools.py +++ b/wnettools.py @@ -204,7 +204,7 @@ class Interface(object): """ cmd = 'ifconfig ' + self.iface + ' up' - if self.verbose: print cmd + #if self.verbose: print cmd misc.Run(cmd) return True