Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: third_party/libadblockplus_android/prepare_build_tools.py

Issue 29670562: Issue 6272 - Can't sync because of changes in android_tools (Closed)
Patch Set: Formatted with respect to eyeo python code style. Tested with flake8 Created Jan. 16, 2018, 8:59 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/libadblockplus_android/BUILD.gn ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 import os 1 import os
2 import urllib
3 import zipfile
4 import sys 2 import sys
5 import subprocess 3 import subprocess
4 import shutil
5
6
7 def get_dst_path():
8 cwd = os.getcwd()
9 return os.path.join(cwd, 'src', 'third_party',
10 'libadblockplus_android', 'third_party', 'android_sdk')
11
12
13 def duplicate_sdk():
14 cwd = os.getcwd()
15 sdk_src = os.path.join(cwd, 'src', 'third_party', 'android_tools', 'sdk')
16 sdk_dst = get_dst_path()
17
18 if os.path.exists(sdk_dst):
19 print('Deleting {}'.format(sdk_dst))
20 shutil.rmtree(sdk_dst)
21 else:
22 dst_parent = os.path.abspath(os.path.join(sdk_dst, os.pardir))
23 print('Creating {}'.format(dst_parent))
24 os.makedirs(dst_parent)
25
26 print('Copying Android SDK from {} to {}'.format(sdk_src, sdk_dst))
27 shutil.copytree(sdk_src, sdk_dst)
28
6 29
7 def install(title, package, version, verbose=False): 30 def install(title, package, version, verbose=False):
8 print('Installing %s ...' % title) 31 print('Installing {} ...'.format(title))
9 32
10 cwd = os.getcwd() 33 sdk_root = get_dst_path()
11 sdk_root = os.path.join(cwd, 'src', 'third_party', 'android_tools', 'sdk') 34 sdkmanager = os.path.join(sdk_root, 'tools', 'bin', 'sdkmanager')
12 sdkmanager = os.path.join(sdk_root, 'tools', 'bin', 'sdkmanager')
13 35
14 args = [ 36 args = [
15 sdkmanager, 37 sdkmanager,
16 "--sdk_root=%s" % (sdk_root), 38 '--sdk_root={}'.format(sdk_root),
17 "%s;%s" % (package, version) 39 '{};{}'.format(package, version)
18 ] 40 ]
19 41
20 if verbose: 42 if verbose:
21 args += [ "--verbose" ] 43 args += ['--verbose']
22 44
23 process = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=sys.stdout, std err=sys.stderr) 45 process = subprocess.Popen(args, stdin=subprocess.PIPE,
24 process.stdin.write('y') # Agree to License 46 stdout=sys.stdout, stderr=sys.stderr)
25 process.communicate()
26 process.stdin.close()
27 47
28 if process.returncode != 0: 48 # Agree to License
29 print("%s finished with error code %s" % (args, process.returncode)) 49 process.stdin.write('y')
50 process.communicate()
51 process.stdin.close()
30 52
31 return process.returncode 53 if process.returncode != 0:
54 print('{} finished with error code {}'.format(
55 args, process.returncode))
56
57 return process.returncode
58
32 59
33 def main(argv): 60 def main(argv):
34 # TODO: update when different version of built-tools and platform are required 61 duplicate_sdk()
35 bt25 = install("Build tools", "build-tools", "25.0.0", True)
36 if bt25 != 0:
37 return bt25
38 62
39 a16 = install("Platform 16", "platforms", "android-16", True) 63 # TODO: update when different version of built-tools
40 if a16 != 0: 64 # and platform are required
41 return a16 65 bt25 = install('Build tools', 'build-tools', '25.0.0', True)
66 if bt25 != 0:
67 return bt25
42 68
43 a21 = install("Platform 21", "platforms", "android-21", True) 69 a16 = install('Platform 16', 'platforms', 'android-16', True)
44 if a21 != 0: 70 if a16 != 0:
45 return a21 71 return a16
46 72
47 return 0 73 a21 = install('Platform 21', 'platforms', 'android-21', True)
74 if a21 != 0:
75 return a21
76
77 return 0
78
48 79
49 if '__main__' == __name__: 80 if '__main__' == __name__:
50 try: 81 try:
51 sys.exit(main(sys.argv[1:])) 82 sys.exit(main(sys.argv[1:]))
52 except KeyboardInterrupt: 83 except KeyboardInterrupt:
53 sys.stderr.write('interrupted\n') 84 sys.stderr.write('interrupted\n')
54 sys.exit(1) 85 sys.exit(1)
diegocarloslima 2018/01/17 13:08:53 Some of the changes here could go in a refactoring
anton 2018/01/17 13:12:11 I've created separate task for applying python cod
OLDNEW
« no previous file with comments | « third_party/libadblockplus_android/BUILD.gn ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld