OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 | 2 |
3 # Copyright (c) 2011 The Chromium OS Authors. All rights reserved. | 3 # Copyright (c) 2011 The Chromium OS Authors. All rights reserved. |
4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 import dbus | 7 import dbus |
8 import os | 8 import os |
9 | 9 |
10 MMPROVIDERS = [ 'org.chromium', 'org.freedesktop' ] | 10 MMPROVIDERS = [ 'org.chromium', 'org.freedesktop' ] |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 | 91 |
92 Args: | 92 Args: |
93 manager - the specific manager to use, if None check all known managers | 93 manager - the specific manager to use, if None check all known managers |
94 | 94 |
95 Returns: | 95 Returns: |
96 a list of (ModemManager object, modem dbus path) | 96 a list of (ModemManager object, modem dbus path) |
97 """ | 97 """ |
98 if manager: | 98 if manager: |
99 managers = [manager] | 99 managers = [manager] |
100 else: | 100 else: |
101 managers = [ModemManager(x) for x in MMPROVIDERS] | 101 managers = [] |
| 102 for provider in MMPROVIDERS: |
| 103 try: |
| 104 managers.append(ModemManager(provider)) |
| 105 except dbus.exceptions.DBusException, e: |
| 106 if e._dbus_error_name != 'org.freedesktop.DBus.Error.ServiceUnknown': |
| 107 raise |
102 | 108 |
103 result = [] | 109 result = [] |
104 for m in managers: | 110 for m in managers: |
105 for path in m.manager.EnumerateDevices(): | 111 for path in m.manager.EnumerateDevices(): |
106 result.append((m, path)) | 112 result.append((m, path)) |
107 | 113 |
108 return result | 114 return result |
109 | 115 |
110 | 116 |
111 def PickOneModem(modem_pattern, manager=None): | 117 def PickOneModem(modem_pattern, manager=None): |
(...skipping 16 matching lines...) Expand all Loading... |
128 """ | 134 """ |
129 devices = EnumerateDevices(manager) | 135 devices = EnumerateDevices(manager) |
130 | 136 |
131 matches = [(m, path) for m, path in devices if modem_pattern in path] | 137 matches = [(m, path) for m, path in devices if modem_pattern in path] |
132 if not matches: | 138 if not matches: |
133 raise ValueError("No modems had substring: " + modem_pattern) | 139 raise ValueError("No modems had substring: " + modem_pattern) |
134 if len(matches) > 1: | 140 if len(matches) > 1: |
135 raise ValueError("Expected only one modem, got: " + | 141 raise ValueError("Expected only one modem, got: " + |
136 ", ".join([path for _, path in matches])) | 142 ", ".join([path for _, path in matches])) |
137 return matches[0] | 143 return matches[0] |
OLD | NEW |