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

Delta Between Two Patch Sets: third_party/libadblockplus_android/prepare_build_tools.py

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

Powered by Google App Engine
This is Rietveld