OLD | NEW |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """PyAuto: Python Interface to Chromium's Automation Proxy. | 6 """PyAuto: Python Interface to Chromium's Automation Proxy. |
7 | 7 |
8 PyAuto uses swig to expose Automation Proxy interfaces to Python. | 8 PyAuto uses swig to expose Automation Proxy interfaces to Python. |
9 For complete documentation on the functionality available, | 9 For complete documentation on the functionality available, |
10 run pydoc on this file. | 10 run pydoc on this file. |
(...skipping 5046 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5057 | 5057 |
5058 Returns: | 5058 Returns: |
5059 The SSID of the connected network or None if we're not connected. | 5059 The SSID of the connected network or None if we're not connected. |
5060 """ | 5060 """ |
5061 service_list = self.GetNetworkInfo() | 5061 service_list = self.GetNetworkInfo() |
5062 connected_service_path = service_list.get('connected_wifi') | 5062 connected_service_path = service_list.get('connected_wifi') |
5063 if 'wifi_networks' in service_list and \ | 5063 if 'wifi_networks' in service_list and \ |
5064 connected_service_path in service_list['wifi_networks']: | 5064 connected_service_path in service_list['wifi_networks']: |
5065 return service_list['wifi_networks'][connected_service_path]['name'] | 5065 return service_list['wifi_networks'][connected_service_path]['name'] |
5066 | 5066 |
5067 def GetServicePath(self, ssid): | 5067 def GetServicePath(self, ssid, encryption=None, timeout=30): |
5068 """Returns the service path associated with an SSID. | 5068 """Returns the service path associated with an SSID. |
5069 | 5069 |
5070 Args: | 5070 Args: |
5071 ssid: String defining the SSID we are searching for. | 5071 ssid: String defining the SSID we are searching for. |
5072 encryption: Encryption type of the network; either None to return the | |
5073 first instance of network that matches the ssid, '' for | |
5074 an empty network, 'PSK', 'WEP' or '8021X'. | |
5075 timeout: Duration to wait for ssid to appear. | |
5072 | 5076 |
5073 Returns: | 5077 Returns: |
5074 The service path or None if SSID does not exist. | 5078 The service path or None if SSID does not exist after timeout period. |
5075 """ | 5079 """ |
5076 service_list = self.GetNetworkInfo() | 5080 end_time = time.time() + timeout |
5077 service_list = service_list.get('wifi_networks', []) | 5081 while time.time() < end_time: |
krisr
2012/08/06 23:39:13
How fast does this spin? i.e. are we spiking the
stanleyw
2012/08/07 01:22:13
Done.
| |
5078 for service_path, service_obj in service_list.iteritems(): | 5082 service_list = self.GetNetworkInfo().get('wifi_networks', []) |
5079 if service_obj['name'] == ssid: | 5083 for service_path, service_obj in service_list.iteritems(): |
5080 return service_path | 5084 service_encr = 'PSK' if service_obj['encryption'] in ['WPA', 'RSN'] \ |
5085 else service_obj['encryption'] | |
5086 | |
5087 if service_obj['name'] == ssid and \ | |
5088 (encryption == None or service_encr == encryption): | |
5089 return service_path | |
5090 self.NetworkScan() | |
5081 return None | 5091 return None |
5082 | 5092 |
5083 def NetworkScan(self): | 5093 def NetworkScan(self): |
5084 """Causes ChromeOS to scan for available wifi networks. | 5094 """Causes ChromeOS to scan for available wifi networks. |
5085 | 5095 |
5086 Blocks until scanning is complete. | 5096 Blocks until scanning is complete. |
5087 | 5097 |
5088 Returns: | 5098 Returns: |
5089 The new list of networks obtained from GetNetworkInfo(). | 5099 The new list of networks obtained from GetNetworkInfo(). |
5090 | 5100 |
(...skipping 1454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6545 successful = result.wasSuccessful() | 6555 successful = result.wasSuccessful() |
6546 if not successful: | 6556 if not successful: |
6547 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename) | 6557 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename) |
6548 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \ | 6558 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \ |
6549 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL) | 6559 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL) |
6550 sys.exit(not successful) | 6560 sys.exit(not successful) |
6551 | 6561 |
6552 | 6562 |
6553 if __name__ == '__main__': | 6563 if __name__ == '__main__': |
6554 Main() | 6564 Main() |
OLD | NEW |