blob: 7cc89758046cd6ae0323f60f9085df499d4a959e [file] [log] [blame]
#!/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(old_state, new_state, reason, path):
global waitcnt
if new_state == 60:
print "Disconnect completed for", path
else:
print "Disconnect failed for", 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=manager.provider,
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._dbus_error_name == "org.chromium.ModemManager.Error.OperationInitiated":
waitcnt += 1
else:
raise e
if waitflag and waitcnt != 0:
mainloop = gobject.MainLoop()
mainloop.run()