OLD | NEW |
1 import os | 1 import os |
2 import urllib | 2 import urllib |
3 import zipfile | 3 import zipfile |
4 import sys | 4 import sys |
5 import subprocess | 5 import subprocess |
| 6 import shutil |
| 7 |
| 8 def get_dst_path(): |
| 9 cwd = os.getcwd() |
| 10 return os.path.join(cwd, 'src', 'third_party', 'libadblockplus_android', 'thir
d_party', 'android_sdk') |
| 11 |
| 12 def duplicate_sdk(): |
| 13 cwd = os.getcwd() |
| 14 sdk_src = os.path.join(cwd, 'src', 'third_party', 'android_tools', 'sdk') |
| 15 sdk_dst = get_dst_path() |
| 16 |
| 17 if os.path.exists(sdk_dst): |
| 18 print('Deleting %s' % sdk_dst) |
| 19 shutil.rmtree(sdk_dst) |
| 20 else: |
| 21 dst_parent = os.path.abspath(os.path.join(sdk_dst, os.pardir)) |
| 22 print('Creating %s' % dst_parent) |
| 23 os.makedirs(dst_parent) |
| 24 |
| 25 print('Copying Android SDK from %s to %s' % (sdk_src, sdk_dst)) |
| 26 shutil.copytree(sdk_src, sdk_dst) |
6 | 27 |
7 def install(title, package, version, verbose=False): | 28 def install(title, package, version, verbose=False): |
8 print('Installing %s ...' % title) | 29 print('Installing %s ...' % title) |
9 | 30 |
10 cwd = os.getcwd() | 31 cwd = os.getcwd() |
11 sdk_root = os.path.join(cwd, 'src', 'third_party', 'android_tools', 'sdk') | 32 sdk_root = get_dst_path() |
12 sdkmanager = os.path.join(sdk_root, 'tools', 'bin', 'sdkmanager') | 33 sdkmanager = os.path.join(sdk_root, 'tools', 'bin', 'sdkmanager') |
13 | 34 |
14 args = [ | 35 args = [ |
15 sdkmanager, | 36 sdkmanager, |
16 "--sdk_root=%s" % (sdk_root), | 37 "--sdk_root=%s" % (sdk_root), |
17 "%s;%s" % (package, version) | 38 "%s;%s" % (package, version) |
18 ] | 39 ] |
19 | 40 |
20 if verbose: | 41 if verbose: |
21 args += [ "--verbose" ] | 42 args += [ "--verbose" ] |
22 | 43 |
23 process = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=sys.stdout, std
err=sys.stderr) | 44 process = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=sys.stdout, std
err=sys.stderr) |
24 process.stdin.write('y') # Agree to License | 45 process.stdin.write('y') # Agree to License |
25 process.communicate() | 46 process.communicate() |
26 process.stdin.close() | 47 process.stdin.close() |
27 | 48 |
28 if process.returncode != 0: | 49 if process.returncode != 0: |
29 print("%s finished with error code %s" % (args, process.returncode)) | 50 print("%s finished with error code %s" % (args, process.returncode)) |
30 | 51 |
31 return process.returncode | 52 return process.returncode |
32 | 53 |
33 def main(argv): | 54 def main(argv): |
| 55 duplicate_sdk() |
| 56 |
34 # TODO: update when different version of built-tools and platform are required | 57 # TODO: update when different version of built-tools and platform are required |
35 bt25 = install("Build tools", "build-tools", "25.0.0", True) | 58 bt25 = install("Build tools", "build-tools", "25.0.0", True) |
36 if bt25 != 0: | 59 if bt25 != 0: |
37 return bt25 | 60 return bt25 |
38 | 61 |
39 a16 = install("Platform 16", "platforms", "android-16", True) | 62 a16 = install("Platform 16", "platforms", "android-16", True) |
40 if a16 != 0: | 63 if a16 != 0: |
41 return a16 | 64 return a16 |
42 | 65 |
43 a21 = install("Platform 21", "platforms", "android-21", True) | 66 a21 = install("Platform 21", "platforms", "android-21", True) |
44 if a21 != 0: | 67 if a21 != 0: |
45 return a21 | 68 return a21 |
46 | 69 |
47 return 0 | 70 return 0 |
48 | 71 |
49 if '__main__' == __name__: | 72 if '__main__' == __name__: |
50 try: | 73 try: |
51 sys.exit(main(sys.argv[1:])) | 74 sys.exit(main(sys.argv[1:])) |
52 except KeyboardInterrupt: | 75 except KeyboardInterrupt: |
53 sys.stderr.write('interrupted\n') | 76 sys.stderr.write('interrupted\n') |
54 sys.exit(1) | 77 sys.exit(1) |
OLD | NEW |