| #!/usr/bin/python |
| |
| # Copyright (c) 2011 The Chromium OS Authors. All rights reserved. |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| |
| import mm |
| import dbus |
| import dbus.mainloop.glib |
| import gobject |
| import sys |
| |
| waitcnt = 0 |
| def state_changed(_, new_state, _, modem_path): |
| """ |
| _ (old_state): Previous modem state (but unused). |
| new_state: New modem state. |
| _ (reason): Reason for transition (but unused). |
| modem_path: Path of the modem object for this status update. |
| """ |
| global waitcnt |
| if new_state == 60: |
| print "Disconnect completed for", modem_path |
| else: |
| print "Disconnect failed for", modem_path |
| waitcnt -= 1 |
| if waitcnt <= 0: |
| mainloop.quit() |
| |
| waitflag = False |
| if len(sys.argv) > 1 and sys.argv[1] == '-w': |
| waitflag = True |
| del sys.argv[1] |
| |
| dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) |
| |
| if waitflag: |
| bus = dbus.SystemBus() |
| bus.add_signal_receiver(state_changed, |
| bus_name=mm.ModemManager.INTERFACE, |
| signal_name="StateChanged", |
| path_keyword="path") |
| |
| devices = mm.EnumerateDevices() |
| |
| for manager, path in devices: |
| |
| print "Disconnecting", path |
| |
| modem = manager.Modem(path) |
| try: |
| modem.Disconnect() |
| except dbus.exceptions.DBusException, e: |
| if (e.get_dbus_name() == |
| "org.chromium.ModemManager.Error.OperationInitiated"): |
| waitcnt += 1 |
| else: |
| raise e |
| |
| if waitflag and waitcnt != 0: |
| mainloop = gobject.MainLoop() |
| mainloop.run() |