OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # | 2 # |
3 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 3 # Copyright (c) 2012 The Chromium 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 """Saves logcats from all connected devices. | 7 """Saves logcats from all connected devices. |
8 | 8 |
9 Usage: adb_logcat_monitor.py <base_dir> [<adb_binary_path>] | 9 Usage: adb_logcat_monitor.py <base_dir> [<adb_binary_path>] |
10 | 10 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 Returns: | 76 Returns: |
77 list of devices or an empty list on timeout | 77 list of devices or an empty list on timeout |
78 """ | 78 """ |
79 signal.alarm(2) | 79 signal.alarm(2) |
80 try: | 80 try: |
81 out, err = subprocess.Popen([adb_cmd, 'devices'], | 81 out, err = subprocess.Popen([adb_cmd, 'devices'], |
82 stdout=subprocess.PIPE, | 82 stdout=subprocess.PIPE, |
83 stderr=subprocess.PIPE).communicate() | 83 stderr=subprocess.PIPE).communicate() |
84 if err: | 84 if err: |
85 logging.warning('adb device error %s', err.strip()) | 85 logging.warning('adb device error %s', err.strip()) |
86 return re.findall('^(\S+)\tdevice$', out, re.MULTILINE) | 86 return re.findall('^(\\S+)\tdevice$', out, re.MULTILINE) |
87 except TimeoutException: | 87 except TimeoutException: |
88 logging.warning('"adb devices" command timed out') | 88 logging.warning('"adb devices" command timed out') |
89 return [] | 89 return [] |
90 except (IOError, OSError): | 90 except (IOError, OSError): |
91 logging.exception('Exception from "adb devices"') | 91 logging.exception('Exception from "adb devices"') |
92 return [] | 92 return [] |
93 finally: | 93 finally: |
94 signal.alarm(0) | 94 signal.alarm(0) |
95 | 95 |
96 | 96 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 subprocess.call([adb_cmd, '-s', device_id, 'logcat', '-c']) | 129 subprocess.call([adb_cmd, '-s', device_id, 'logcat', '-c']) |
130 devices[device_id] = (None, 0) | 130 devices[device_id] = (None, 0) |
131 | 131 |
132 for device in devices: | 132 for device in devices: |
133 # This will spawn logcat watchers for any device ever detected | 133 # This will spawn logcat watchers for any device ever detected |
134 StartLogcatIfNecessary(device, adb_cmd, base_dir) | 134 StartLogcatIfNecessary(device, adb_cmd, base_dir) |
135 | 135 |
136 time.sleep(5) | 136 time.sleep(5) |
137 except SigtermError: | 137 except SigtermError: |
138 logging.info('Received SIGTERM, shutting down') | 138 logging.info('Received SIGTERM, shutting down') |
139 except: | 139 except: # pylint: disable=bare-except |
140 logging.exception('Unexpected exception in main.') | 140 logging.exception('Unexpected exception in main.') |
141 finally: | 141 finally: |
142 for process, _ in devices.itervalues(): | 142 for process, _ in devices.itervalues(): |
143 if process: | 143 if process: |
144 try: | 144 try: |
145 process.terminate() | 145 process.terminate() |
146 except OSError: | 146 except OSError: |
147 pass | 147 pass |
148 os.remove(pid_file_path) | 148 os.remove(pid_file_path) |
149 | 149 |
150 | 150 |
151 if __name__ == '__main__': | 151 if __name__ == '__main__': |
152 if 2 <= len(sys.argv) <= 3: | 152 if 2 <= len(sys.argv) <= 3: |
153 print 'adb_logcat_monitor: Initializing' | 153 print 'adb_logcat_monitor: Initializing' |
154 sys.exit(main(*sys.argv[1:3])) | 154 sys.exit(main(*sys.argv[1:3])) |
155 | 155 |
156 print 'Usage: %s <base_dir> [<adb_binary_path>]' % sys.argv[0] | 156 print 'Usage: %s <base_dir> [<adb_binary_path>]' % sys.argv[0] |
OLD | NEW |