From da5fc2dfdffbb8fe035d17634ad1ece17e2f3c80 Mon Sep 17 00:00:00 2001 From: Robby Workman Date: Sun, 28 Dec 2008 00:19:25 -0600 Subject: [PATCH] Merged autoconnect.py and suspend.py changes from trunk (fixes for the pm-utils sleep hook usage). --- wicd/autoconnect.py | 43 +++++++++++++++++++++++++++++-------------- wicd/suspend.py | 18 ++++++++++++------ 2 files changed, 41 insertions(+), 20 deletions(-) diff --git a/wicd/autoconnect.py b/wicd/autoconnect.py index 472a2d1..787aae5 100755 --- a/wicd/autoconnect.py +++ b/wicd/autoconnect.py @@ -1,8 +1,8 @@ #!/usr/bin/python # -# Copyright (C) 2007 Adam Blackburn -# Copyright (C) 2007 Dan O'Reilly +# Copyright (C) 2007 - 2008 Adam Blackburn +# Copyright (C) 2007 - 2008 Dan O'Reilly # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License Version 2 as @@ -21,22 +21,37 @@ import dbus import time import gobject import sys -from dbus.mainloop.glib import DBusGMainLoop -DBusGMainLoop(set_as_default=True) -bus = dbus.SystemBus() -proxy_obj = bus.get_object('org.wicd.daemon', '/org/wicd/daemon') -daemon = dbus.Interface(proxy_obj, 'org.wicd.daemon') -loop = gobject.MainLoop() +if getattr(dbus, 'version', (0, 0, 0)) < (0, 80, 0): + import dbus.glib +else: + from dbus.mainloop.glib import DBusGMainLoop + DBusGMainLoop(set_as_default=True) +try: + bus = dbus.SystemBus() + proxy_obj = bus.get_object('org.wicd.daemon', '/org/wicd/daemon') + daemon = dbus.Interface(proxy_obj, 'org.wicd.daemon') +except Exception, e: + print>>sys.stderr, "Exception caught: %s" % str(e) + print>>sys.stderr, 'Could not connect to daemon.' + sys.exit(1) def handler(*args): loop.quit() -print daemon.Hello() -time.sleep(3) -daemon.SetSuspend(False) -if not daemon.CheckIfConnecting(): - daemon.SetForcedDisconnect(False) - daemon.AutoConnect(True, reply_handler=handler, error_handler=handler) +def error_handler(*args): + print>>sys.stderr, 'Async error autoconnecting.' + sys.exit(3) +if __name__ == '__main__': + try: + time.sleep(3) + daemon.SetSuspend(False) + if not daemon.CheckIfConnecting(): + daemon.SetForcedDisconnect(False) + daemon.AutoConnect(True, reply_handler=handler, error_handler=handler) + except Exception, e: + print>>sys.stderr, "Exception caught: %s" % str(e) + print>>sys.stderr, 'Error autoconnecting.' + sys.exit(2) diff --git a/wicd/suspend.py b/wicd/suspend.py index c43e2a3..7a860fb 100755 --- a/wicd/suspend.py +++ b/wicd/suspend.py @@ -2,14 +2,14 @@ """ Suspends the wicd daemon. -Sets a flag in the daemon that will stop it from monitoring network status. +Sets a flag in the daemon that will stop it from monitoring networkg status. Used for when a laptop enters hibernation/suspension. """ # -# Copyright (C) 2007 Adam Blackburn -# Copyright (C) 2007 Dan O'Reilly +# Copyright (C) 2007 - 2008 Adam Blackburn +# Copyright (C) 2007 - 2008 Dan O'Reilly # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License Version 2 as @@ -26,13 +26,17 @@ Used for when a laptop enters hibernation/suspension. import dbus import dbus.service +import sys try: bus = dbus.SystemBus() proxy_obj = bus.get_object('org.wicd.daemon', '/org/wicd/daemon') daemon = dbus.Interface(proxy_obj, 'org.wicd.daemon') except Exception, e: - print "Exception caught: %s" % str(e) + print>>sys.stderr, "Exception caught: %s" % str(e) + print>>sys.stderr, 'Could not connect to daemon.' + sys.exit(1) + if __name__ == '__main__': @@ -41,5 +45,7 @@ if __name__ == '__main__': daemon.SetForcedDisconnect(False) daemon.SetSuspend(True) except Exception, e: - print "Exception caught: %s" % str(e) - + print>>sys.stderr, "Exception caught: %s" % str(e) + print>>sys.stderr, 'Error setting suspend.' + sys.exit(2) +