OLD | NEW |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2013 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 """Installs deps for using SDK emulator for testing. | 6 """Installs deps for using SDK emulator for testing. |
7 | 7 |
8 The script will download the SDK and system images, if they are not present, and | 8 The script will download the SDK and system images, if they are not present, and |
9 install and enable KVM, if virtualization has been enabled in the BIOS. | 9 install and enable KVM, if virtualization has been enabled in the BIOS. |
10 """ | 10 """ |
(...skipping 17 matching lines...) Expand all Loading... | |
28 X86_IMG_URL = 'http://download-software.intel.com/sites/landingpage/android/sysi mg_x86-17_r01.zip' | 28 X86_IMG_URL = 'http://download-software.intel.com/sites/landingpage/android/sysi mg_x86-17_r01.zip' |
29 | 29 |
30 # Android API level | 30 # Android API level |
31 API_TARGET = 'android-%s' % constants.ANDROID_SDK_VERSION | 31 API_TARGET = 'android-%s' % constants.ANDROID_SDK_VERSION |
32 | 32 |
33 | 33 |
34 def CheckSDK(): | 34 def CheckSDK(): |
35 """Check if SDK is already installed. | 35 """Check if SDK is already installed. |
36 | 36 |
37 Returns: | 37 Returns: |
38 True if android_tools directory exists in current directory. | 38 True if the android_tools/sdk directory exists in current directory. |
Peter Beverloo
2013/09/11 13:58:08
nit: EMULATOR_SDK_ROOT is an absolute path, so the
| |
39 """ | 39 """ |
40 return os.path.exists(os.path.join(constants.EMULATOR_SDK_ROOT, | 40 return os.path.exists(constants.EMULATOR_SDK_ROOT) |
41 'android_tools')) | |
42 | 41 |
43 | 42 |
44 def CheckX86Image(): | 43 def CheckX86Image(): |
45 """Check if Android system images have been installed. | 44 """Check if Android system images have been installed. |
46 | 45 |
47 Returns: | 46 Returns: |
48 True if android_tools/sdk/system-images directory exists. | 47 True if android_tools/sdk/system-images directory exists. |
49 """ | 48 """ |
50 return os.path.exists(os.path.join(constants.EMULATOR_SDK_ROOT, | 49 return os.path.exists(os.path.join(constants.EMULATOR_SDK_ROOT, |
51 'android_tools', 'sdk', 'system-images', | 50 'system-images', API_TARGET, 'x86')) |
52 API_TARGET, 'x86')) | |
53 | 51 |
54 | 52 |
55 def CheckKVM(): | 53 def CheckKVM(): |
56 """Check if KVM is enabled. | 54 """Check if KVM is enabled. |
57 | 55 |
58 Returns: | 56 Returns: |
59 True if kvm-ok returns 0 (already enabled) | 57 True if kvm-ok returns 0 (already enabled) |
60 """ | 58 """ |
61 try: | 59 try: |
62 return not cmd_helper.RunCmd(['kvm-ok']) | 60 return not cmd_helper.RunCmd(['kvm-ok']) |
(...skipping 10 matching lines...) Expand all Loading... | |
73 cmd_helper.RunCmd(['curl', '-o', '/tmp/sdk.zip', sdk_url]) | 71 cmd_helper.RunCmd(['curl', '-o', '/tmp/sdk.zip', sdk_url]) |
74 print 'curled unzipping...' | 72 print 'curled unzipping...' |
75 rc = cmd_helper.RunCmd(['unzip', '-o', '/tmp/sdk.zip', '-d', '/tmp/']) | 73 rc = cmd_helper.RunCmd(['unzip', '-o', '/tmp/sdk.zip', '-d', '/tmp/']) |
76 if rc: | 74 if rc: |
77 logging.critical('ERROR: could not download/unzip Android SDK.') | 75 logging.critical('ERROR: could not download/unzip Android SDK.') |
78 raise | 76 raise |
79 # Get the name of the sub-directory that everything will be extracted to. | 77 # Get the name of the sub-directory that everything will be extracted to. |
80 dirname, _ = os.path.splitext(SDK_ZIP) | 78 dirname, _ = os.path.splitext(SDK_ZIP) |
81 zip_dir = '/tmp/%s' % dirname | 79 zip_dir = '/tmp/%s' % dirname |
82 # Move the extracted directory to EMULATOR_SDK_ROOT | 80 # Move the extracted directory to EMULATOR_SDK_ROOT |
83 dst = os.path.join(constants.EMULATOR_SDK_ROOT, 'android_tools') | 81 dst = os.path.join(constants.EMULATOR_SDK_ROOT, 'android_tools') |
Peter Beverloo
2013/09/11 13:58:08
Shouldn't this just be EMULATOR_SDK_ROOT, since th
| |
84 shutil.move(zip_dir, dst) | 82 shutil.move(zip_dir, dst) |
85 finally: | 83 finally: |
86 os.unlink('/tmp/sdk.zip') | 84 os.unlink('/tmp/sdk.zip') |
87 | 85 |
88 | 86 |
89 def InstallKVM(): | 87 def InstallKVM(): |
90 """Installs KVM packages.""" | 88 """Installs KVM packages.""" |
91 rc = cmd_helper.RunCmd(['sudo', 'apt-get', 'install', 'kvm']) | 89 rc = cmd_helper.RunCmd(['sudo', 'apt-get', 'install', 'kvm']) |
92 if rc: | 90 if rc: |
93 logging.critical('ERROR: Did not install KVM. Make sure hardware ' | 91 logging.critical('ERROR: Did not install KVM. Make sure hardware ' |
(...skipping 14 matching lines...) Expand all Loading... | |
108 | 106 |
109 def GetX86Image(): | 107 def GetX86Image(): |
110 """Download x86 system image from Intel's website.""" | 108 """Download x86 system image from Intel's website.""" |
111 logging.info('Download x86 system image directory into sdk directory.') | 109 logging.info('Download x86 system image directory into sdk directory.') |
112 try: | 110 try: |
113 cmd_helper.RunCmd(['curl', '-o', '/tmp/x86_img.zip', X86_IMG_URL]) | 111 cmd_helper.RunCmd(['curl', '-o', '/tmp/x86_img.zip', X86_IMG_URL]) |
114 rc = cmd_helper.RunCmd(['unzip', '-o', '/tmp/x86_img.zip', '-d', '/tmp/']) | 112 rc = cmd_helper.RunCmd(['unzip', '-o', '/tmp/x86_img.zip', '-d', '/tmp/']) |
115 if rc: | 113 if rc: |
116 logging.critical('ERROR: Could not download/unzip image zip.') | 114 logging.critical('ERROR: Could not download/unzip image zip.') |
117 raise | 115 raise |
118 sys_imgs = os.path.join(constants.EMULATOR_SDK_ROOT, 'android_tools', 'sdk', | 116 sys_imgs = os.path.join(constants.EMULATOR_SDK_ROOT, 'system-images', |
119 'system-images', API_TARGET, 'x86') | 117 API_TARGET, 'x86') |
120 shutil.move('/tmp/x86', sys_imgs) | 118 shutil.move('/tmp/x86', sys_imgs) |
121 finally: | 119 finally: |
122 os.unlink('/tmp/x86_img.zip') | 120 os.unlink('/tmp/x86_img.zip') |
123 | 121 |
124 | 122 |
125 def main(argv): | 123 def main(argv): |
126 logging.basicConfig(level=logging.INFO, | 124 logging.basicConfig(level=logging.INFO, |
127 format='# %(asctime)-15s: %(message)s') | 125 format='# %(asctime)-15s: %(message)s') |
128 run_tests_helper.SetLogLevel(verbose_count=1) | 126 run_tests_helper.SetLogLevel(verbose_count=1) |
129 | 127 |
(...skipping 12 matching lines...) Expand all Loading... | |
142 | 140 |
143 # Make sure KVM packages are installed and enabled. | 141 # Make sure KVM packages are installed and enabled. |
144 if CheckKVM(): | 142 if CheckKVM(): |
145 logging.info('KVM already installed and enabled.') | 143 logging.info('KVM already installed and enabled.') |
146 else: | 144 else: |
147 InstallKVM() | 145 InstallKVM() |
148 | 146 |
149 | 147 |
150 if __name__ == '__main__': | 148 if __name__ == '__main__': |
151 sys.exit(main(sys.argv)) | 149 sys.exit(main(sys.argv)) |
OLD | NEW |