OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2011 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 """Provides an interface to start and stop Android emulator. | 6 """Provides an interface to start and stop Android emulator. |
7 | 7 |
8 Assumes system environment ANDROID_NDK_ROOT has been set. | 8 Assumes system environment ANDROID_NDK_ROOT has been set. |
9 | 9 |
10 Emulator: The class provides the methods to launch/shutdown the emulator with | 10 Emulator: The class provides the methods to launch/shutdown the emulator with |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 def _AggressiveImageCleanup(self): | 139 def _AggressiveImageCleanup(self): |
140 """Aggressive cleanup of emulator images. | 140 """Aggressive cleanup of emulator images. |
141 | 141 |
142 Experimentally it looks like our current emulator use on the bot | 142 Experimentally it looks like our current emulator use on the bot |
143 leaves image files around in /tmp/android-$USER. If a "random" | 143 leaves image files around in /tmp/android-$USER. If a "random" |
144 name gets reused, we choke with a 'File exists' error. | 144 name gets reused, we choke with a 'File exists' error. |
145 TODO(jrg): is there a less hacky way to accomplish the same goal? | 145 TODO(jrg): is there a less hacky way to accomplish the same goal? |
146 """ | 146 """ |
147 logging.info('Aggressive Image Cleanup') | 147 logging.info('Aggressive Image Cleanup') |
148 emulator_imagedir = '/tmp/android-%s' % os.environ['USER'] | 148 emulator_imagedir = '/tmp/android-%s' % os.environ['USER'] |
| 149 if not os.path.exists(emulator_imagedir): |
| 150 return |
149 for image in os.listdir(emulator_imagedir): | 151 for image in os.listdir(emulator_imagedir): |
150 full_name = os.path.join(emulator_imagedir, image) | 152 full_name = os.path.join(emulator_imagedir, image) |
151 if 'emulator' in full_name: | 153 if 'emulator' in full_name: |
152 logging.info('Deleting emulator image %s', full_name) | 154 logging.info('Deleting emulator image %s', full_name) |
153 os.unlink(full_name) | 155 os.unlink(full_name) |
154 | 156 |
155 def _ConfirmLaunch(self, wait_for_boot=False): | 157 def _ConfirmLaunch(self, wait_for_boot=False): |
156 """Confirm the emulator launched properly. | 158 """Confirm the emulator launched properly. |
157 | 159 |
158 Loop on a wait-for-device with a very small timeout. On each | 160 Loop on a wait-for-device with a very small timeout. On each |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 """Install a handler to kill the emulator when we exit unexpectedly.""" | 212 """Install a handler to kill the emulator when we exit unexpectedly.""" |
211 for sig in self._SIGNALS: | 213 for sig in self._SIGNALS: |
212 signal.signal(sig, self._ShutdownOnSignal) | 214 signal.signal(sig, self._ShutdownOnSignal) |
213 | 215 |
214 def main(argv): | 216 def main(argv): |
215 Emulator().launch() | 217 Emulator().launch() |
216 | 218 |
217 | 219 |
218 if __name__ == '__main__': | 220 if __name__ == '__main__': |
219 main(sys.argv) | 221 main(sys.argv) |
OLD | NEW |