From 97d553bce3f8e99a63a0ff7783b222fe793c3d22 Mon Sep 17 00:00:00 2001 From: Dan O'Reilly Date: Tue, 21 Apr 2009 20:30:40 -0400 Subject: [PATCH 1/7] Use atexit instead of catching SIGTERM in wicd-daemon. Use Popen to launch wicd-monitor instead of gobject.spawn_async. --- wicd/wicd-client.py | 2 +- wicd/wicd-daemon.py | 16 +++++++--------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/wicd/wicd-client.py b/wicd/wicd-client.py index 6c072a7..bcb4900 100755 --- a/wicd/wicd-client.py +++ b/wicd/wicd-client.py @@ -660,7 +660,7 @@ def setup_dbus(force=True): misc.PromptToStartDaemon() try: dbusmanager.connect_to_dbus() - except dbusmanager.DBusException: + except DBusException: error(None, "Could not connect to wicd's D-Bus interface. " + "Check the wicd log for error messages.") return False diff --git a/wicd/wicd-daemon.py b/wicd/wicd-daemon.py index 513716b..a2203e7 100755 --- a/wicd/wicd-daemon.py +++ b/wicd/wicd-daemon.py @@ -37,6 +37,8 @@ import sys import time import getopt import signal +import atexit +from subprocess import Popen # DBUS import gobject @@ -1601,8 +1603,6 @@ def daemonize(): os.dup2(0, 2) -child_pid = None - def main(argv): """ The main daemon program. @@ -1610,7 +1610,6 @@ def main(argv): argv -- The arguments passed to the script. """ - global child_pid do_daemonize = True redirect_stderr = True redirect_stdout = True @@ -1667,9 +1666,10 @@ def main(argv): wicd_bus = dbus.service.BusName('org.wicd.daemon', bus=bus) daemon = WicdDaemon(wicd_bus, auto_connect=auto_connect) if not no_poll: - (child_pid, x, y, z) = gobject.spawn_async( - [misc.find_path("python"), "-O", os.path.join(wpath.lib, "monitor.py")]) - signal.signal(signal.SIGTERM, sigterm_caught) + child_pid = Popen([misc.find_path("python"), "-O", + os.path.join(wpath.lib, "monitor.py")], + shell=False, close_fds=True).pid + atexit.register(on_exit, child_pid) # Enter the main loop mainloop = gobject.MainLoop() @@ -1678,11 +1678,9 @@ def main(argv): except KeyboardInterrupt: pass daemon.DaemonClosing() - sigterm_caught() -def sigterm_caught(sig=None, frame=None): +def on_exit(child_pid): """ Called when a SIGTERM is caught, kills monitor.py before exiting. """ - global child_pid if child_pid: print 'Daemon going down, killing wicd-monitor...' try: From 779fb40fff22327bdce749641b692181895dfc24 Mon Sep 17 00:00:00 2001 From: Dan O'Reilly Date: Tue, 21 Apr 2009 21:25:59 -0400 Subject: [PATCH 2/7] Refactor monitor.py polling code to remove reliance on globals. Make sure we update the polling rate in wicd-monitor when the backend changes. --- wicd/monitor.py | 59 ++++++++++++++++++++++++++------------------- wicd/wicd-daemon.py | 6 +++++ 2 files changed, 40 insertions(+), 25 deletions(-) diff --git a/wicd/monitor.py b/wicd/monitor.py index d47add5..82727cd 100755 --- a/wicd/monitor.py +++ b/wicd/monitor.py @@ -45,7 +45,7 @@ daemon = dbus_dict["daemon"] wired = dbus_dict["wired"] wireless = dbus_dict["wireless"] -monitor = to_time = update_callback = mainloop = None +mainloop = None def diewithdbus(func): def wrapper(self, *__args, **__kargs): @@ -86,11 +86,42 @@ class ConnectionStatus(object): self.iwconfig = "" self.trigger_reconnect = False self.__lost_dbus_count = 0 - + self._to_time = daemon.GetBackendUpdateInterval() + + self.add_poll_callback() bus = dbusmanager.get_bus() bus.add_signal_receiver(self._force_update_connection_status, "UpdateState", "org.wicd.daemon") + bus.add_signal_receiver(self._update_timeout_interval, + "SignalBackendChanged", "org.wicd.daemon") + def _update_timeout_interval(self, interval): + """ Update the callback interval when signaled by the daemon. """ + self._to_time = interval + gobject.source_remove(self.update_callback) + self.add_poll_callback() + + def _force_update_connection_status(self): + """ Run a connection status update on demand. + + Removes the scheduled update_connection_status() + call, explicitly calls the function, and reschedules + it. + + """ + gobject.source_remove(self.update_callback) + self.update_connection_status() + self.add_poll_callback() + + def add_poll_callback(self): + """ Registers a polling call at a predetermined interval. + + The polling interval is determined by the backend in use. + + """ + self.update_callback = misc.timeout_add(self._to_time, + self.update_connection_status) + def check_for_wired_connection(self, wired_ip): """ Checks for a wired connection. @@ -229,19 +260,6 @@ class ConnectionStatus(object): self.auto_reconnect(from_wireless) return self.update_state(state) - def _force_update_connection_status(self): - """ Run a connection status update on demand. - - Removes the scheduled update_connection_status() - call, explicitly calls the function, and reschedules - it. - - """ - global update_callback - gobject.source_remove(update_callback) - self.update_connection_status() - add_poll_callback() - def update_state(self, state, wired_ip=None, wifi_ip=None): """ Set the current connection state. """ # Set our connection state/info. @@ -333,12 +351,6 @@ def err_handle(error): """ Just a dummy function needed for asynchronous dbus calls. """ pass -def add_poll_callback(): - global monitor, to_time, update_callback - - update_callback = misc.timeout_add(to_time, - monitor.update_connection_status) - def main(): """ Starts the connection monitor. @@ -346,11 +358,8 @@ def main(): an amount of time determined by the active backend. """ - global monitor, to_time, mainloop - + global mainloop monitor = ConnectionStatus() - to_time = daemon.GetBackendUpdateInterval() - add_poll_callback() mainloop = gobject.MainLoop() mainloop.run() diff --git a/wicd/wicd-daemon.py b/wicd/wicd-daemon.py index a2203e7..073d1b1 100755 --- a/wicd/wicd-daemon.py +++ b/wicd/wicd-daemon.py @@ -208,6 +208,7 @@ class WicdDaemon(dbus.service.Object): self.suspended = True self.wifi.LoadBackend(backend) self.wired.LoadBackend(backend) + self.SignalBackendChanged(self.GetBackendUpdateInterval()) self.SetSuspend(False) @dbus.service.method('org.wicd.daemon') @@ -824,6 +825,11 @@ class WicdDaemon(dbus.service.Object): """ pass + + @dbus.service.signal(dbus_interface='org.wicd.daemon', signature='i') + def SignalBackendChanged(self, interval): + """ Emits a signal when the current backend changes. """ + pass def ReadConfig(self): """ Reads the manager-settings.conf file. From 3665bc3c61c2f2d33b2e77aa771038fe3daec694 Mon Sep 17 00:00:00 2001 From: Adam Blackburn Date: Wed, 22 Apr 2009 21:45:51 +0800 Subject: [PATCH 3/7] Updated vcsinfo.py generation logic --- setup.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/setup.py b/setup.py index 35df602..298e894 100755 --- a/setup.py +++ b/setup.py @@ -29,18 +29,21 @@ VERSION_NUM = '1.6.0a1' REVISION_NUM = 'unknown' CURSES_REVNO = 'uimod' +# change to the directory setup.py is contained in +os.chdir(os.path.abspath(__file)) + try: - try: - os.system('bzr version-info --python > vcsinfo.py') - except: - pass + if os.path.exists('.bzr') and os.system('bzr') == 0: + try: + os.system('bzr version-info --python > vcsinfo.py') + except: + pass import vcsinfo REVISION_NUM = vcsinfo.version_info['revno'] except Exception, e: print 'failed to find revision number:' print e - class configure(Command): description = "configure the paths that Wicd will be installed to" From 167b18cdeb25b7415df06e028feaae828fba8673 Mon Sep 17 00:00:00 2001 From: Adam Blackburn Date: Wed, 22 Apr 2009 22:02:31 +0800 Subject: [PATCH 4/7] Updated version number --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 298e894..ffa05c0 100755 --- a/setup.py +++ b/setup.py @@ -24,7 +24,7 @@ import subprocess # Be sure to keep this updated! # VERSIONNUMBER -VERSION_NUM = '1.6.0a1' +VERSION_NUM = '1.6.0a2' # REVISION_NUM is automatically updated REVISION_NUM = 'unknown' CURSES_REVNO = 'uimod' From 807054bb3af4427b1b61234cb1c79469934f3b14 Mon Sep 17 00:00:00 2001 From: Adam Blackburn Date: Wed, 22 Apr 2009 22:11:33 +0800 Subject: [PATCH 5/7] fixed a typo --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index ffa05c0..5e48064 100755 --- a/setup.py +++ b/setup.py @@ -30,7 +30,7 @@ REVISION_NUM = 'unknown' CURSES_REVNO = 'uimod' # change to the directory setup.py is contained in -os.chdir(os.path.abspath(__file)) +os.chdir(os.path.abspath(__file__)) try: if os.path.exists('.bzr') and os.system('bzr') == 0: From 5b8819bc6cf94eaa3601b6075d4bd1e0a415b458 Mon Sep 17 00:00:00 2001 From: Adam Blackburn Date: Wed, 22 Apr 2009 22:17:39 +0800 Subject: [PATCH 6/7] fixed another typo --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 5e48064..a66f187 100755 --- a/setup.py +++ b/setup.py @@ -30,7 +30,7 @@ REVISION_NUM = 'unknown' CURSES_REVNO = 'uimod' # change to the directory setup.py is contained in -os.chdir(os.path.abspath(__file__)) +os.chdir(os.path.abspath(os.path.split(__file__)[0])) try: if os.path.exists('.bzr') and os.system('bzr') == 0: From 4998d8c83efda6a86e7a657b886aa6681262bda0 Mon Sep 17 00:00:00 2001 From: Andrew Psaltis Date: Wed, 22 Apr 2009 12:13:06 -0400 Subject: [PATCH 7/7] Set the SVG wicd icon as the window icon in wicd-client. --- wicd/gui.py | 1 + 1 file changed, 1 insertion(+) diff --git a/wicd/gui.py b/wicd/gui.py index 2a2e174..e6bdecb 100644 --- a/wicd/gui.py +++ b/wicd/gui.py @@ -149,6 +149,7 @@ class appGui(object): gladefile = os.path.join(wpath.share, "wicd.glade") self.wTree = gtk.glade.XML(gladefile) self.window = self.wTree.get_widget("window1") + self.window.set_icon_from_file(wpath.icons +'scalable/apps/wicd-client.svg') size = daemon.ReadWindowSize("main") width = size[0] height = size[1]