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

Delta Between Two Patch Sets: third_party/libadblockplus/prepare_dependencies.py

Issue 29674555: Issue 6273 - Apply eyeo python code style (Closed)
Left Patch Set: Created Jan. 19, 2018, 7:28 a.m.
Right Patch Set: Removed sys.exit() where return code is always 0 Created Jan. 29, 2018, 12:50 p.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/download_ndk.py ('k') | third_party/libadblockplus_android/prepare_build_tools.py » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 from __future__ import print_function
2
1 import sys 3 import sys
2 import os 4 import os
3 import shutil 5 import shutil
4 6
5 7
6 def duplicate(src, dst, symlink=False): 8 def duplicate(src, dst, symlink=False):
Vasily Kuznetsov 2018/01/19 13:06:53 It seems like `symlink` argument is not used in th
anton 2018/01/19 13:17:15 That's true that actually it's not used anywhere.
7 if os.path.exists(dst): 9 if os.path.exists(dst):
8 if os.path.isdir(dst): 10 if os.path.isdir(dst):
9 print('Deleting {}'.format(dst)) 11 print('Deleting {}'.format(dst))
Vasily Kuznetsov 2018/01/19 13:06:53 There's no `from __future__ import print_function`
anton 2018/01/19 13:17:15 I'm not Python expert but i'm having python 2.x in
Vasily Kuznetsov 2018/01/19 13:35:17 Yeah, in Python 2 it's parsed as: print ("bla
10 shutil.rmtree(dst) 12 shutil.rmtree(dst)
11 else: 13 else:
12 # symlink 14 # symlink
Vasily Kuznetsov 2018/01/19 13:06:53 Good idea with the comment, but it could also be a
anton 2018/01/19 13:17:15 originally i've tried to symlink the dependencies
Vasily Kuznetsov 2018/01/19 13:35:17 Acknowledged.
13 os.unlink(dst) 15 os.unlink(dst)
14 16
15 dst_parent = os.path.abspath(os.path.join(dst, os.pardir)) 17 dst_parent = os.path.abspath(os.path.join(dst, os.pardir))
16 if not os.path.exists(dst_parent): 18 if not os.path.exists(dst_parent):
17 print('Creating parent directory {} for {}'.format(dst_parent, dst)) 19 print('Creating parent directory {} for {}'.format(dst_parent, dst))
18 os.makedirs(dst_parent) 20 os.makedirs(dst_parent)
19 21
20 if symlink: 22 if symlink:
21 print('Symlinking {} to {}'.format(src, dst)) 23 print('Symlinking {} to {}'.format(src, dst))
22 os.symlink(src, dst) 24 os.symlink(src, dst)
23 else: 25 else:
24 print('Copying {} to {}'.format(src, dst)) 26 print('Copying {} to {}'.format(src, dst))
25 shutil.copytree(src, dst) 27 shutil.copytree(src, dst)
26 28
27 29
28 def prepare_deps(): 30 def prepare_deps():
29 cwd = os.getcwd() 31 cwd = os.getcwd()
30 libadblockplus_root = os.path.join(cwd, 32 libadblockplus_third_party = os.path.join(cwd,
anton 2018/01/19 07:30:20 It would be better to rename it to `libadblockplus
Vasily Kuznetsov 2018/01/19 13:06:53 Given how much we use `os.path.join` in this funct
anton 2018/01/19 13:17:14 Great ideas. However we will save just about 7 cha
Vasily Kuznetsov 2018/01/19 13:35:17 Acknowledged.
sergei 2018/01/19 14:19:43 What about calling os.path.join only when it's rea
31 'src', 'third_party', 33 'src', 'third_party',
32 'libadblockplus', 'third_party') 34 'libadblockplus', 'third_party')
33 35
34 # googletest 36 # googletest
35 # 37 #
36 # Chromium's googletest has a bit different directories structure 38 # Chromium's googletest has a bit different directories structure
37 # ('src' as subdirectory) 39 # ('src' as subdirectory)
38 #
39 # googletest_src = os.path.join(cwd, 'src', 'third_party', 'googletest')
Vasily Kuznetsov 2018/01/19 13:06:52 This commented out code (as well as other below) w
anton 2018/01/19 13:17:15 Agree, i tend to think we should remove the commen
sergei 2018/01/19 14:19:43 Just remove everything and leave a comment if it's
40 # googletest_dst = os.path.join(libadblockplus_root, 'googletest')
41 # duplicate(googletest_src, googletest_dst)
42 40
43 # gyp 41 # gyp
44 # 42 #
45 # Chromium's gyp can't be used because of compile error: 43 # Chromium's gyp can't be used because of compile error:
46 # *** No rule to make target `shell/src/Main.cpp', 44 # *** No rule to make target `shell/src/Main.cpp',
47 # needed by `local/armeabi-v7a/objs/abpshell/shell/src/Main.o'. Stop. 45 # needed by `local/armeabi-v7a/objs/abpshell/shell/src/Main.o'. Stop.
48 # See. https://hg.adblockplus.org/gyp/rev/fix-issue-339 46 # See. https://hg.adblockplus.org/gyp/rev/fix-issue-339
49 #
50 # gyp_src = os.path.join(cwd, 'src', 'tools', 'gyp')
51 # gyp_dst = os.path.join(libadblockplus_root, 'gyp')
52 # duplicate(gyp_src, gyp_dst)
53 47
54 # back-up /v8/testing/gtest as it will be deleted while preparing v8 48 # back-up /v8/testing/gtest as it will be deleted while preparing v8
55 gtest_bak_src = os.path.join(libadblockplus_root, 'v8', 'testing', 'gtest') 49 gtest_bak_src = os.path.join(libadblockplus_third_party,
56 gtest_bak_dst = os.path.join(libadblockplus_root, 'gtest.bak') 50 'v8', 'testing', 'gtest')
51 gtest_bak_dst = os.path.join(libadblockplus_third_party, 'gtest.bak')
57 shutil.move(gtest_bak_src, gtest_bak_dst) 52 shutil.move(gtest_bak_src, gtest_bak_dst)
58 53
59 # v8 54 # v8
60 v8_src = os.path.join(cwd, 'src', 'v8') 55 v8_src = os.path.join(cwd, 'src', 'v8')
61 v8_dst = os.path.join(libadblockplus_root, 'v8') 56 v8_dst = os.path.join(libadblockplus_third_party, 'v8')
62 duplicate(v8_src, v8_dst) 57 duplicate(v8_src, v8_dst)
63 58
64 # restore /v8/testing/gtest from backup 59 # restore /v8/testing/gtest from backup
65 shutil.move(gtest_bak_dst, gtest_bak_src) 60 shutil.move(gtest_bak_dst, gtest_bak_src)
66
67 # v8/base/trace_event/common
68 trace_common_src = os.path.join(cwd,
69 'src', 'base', 'trace_event', 'common')
70 trace_common_dst = os.path.join(libadblockplus_root,
71 'v8', 'base', 'trace_event', 'common')
72 duplicate(trace_common_src, trace_common_dst)
73
74 # v8/build
75 build_src = os.path.join(cwd, 'src', 'build')
76 build_dst = os.path.join(libadblockplus_root, 'v8', 'build')
77 duplicate(build_src, build_dst)
78 61
79 # v8/testing/gtest 62 # v8/testing/gtest
80 # 63 #
81 # Chromium's gtest can't be used becuase of compile error: 64 # Chromium's gtest can't be used becuase of compile error:
82 # fatal error: third_party/googletest/src/googletest/include/gtest/gtest_pro d.h: No such file or directory 65 # fatal error: third_party/googletest/src/googletest/include/gtest/gtest_pro d.h: No such file or directory
83 # #include "third_party/googletest/src/googletest/include/gtest/gtest_prod.h " 66 # #include "third_party/googletest/src/googletest/include/gtest/gtest_prod.h "
84 # so we have to back-up gtest above and restore it 67 # so we have to back-up gtest above and restore it
85 # after prepring of 'v8' directory 68 # after prepring of 'v8' directory
86 #
87 # gtest_src = os.path.join(cwd, 'src', 'testing', 'gtest')
88 # gtest_dst = os.path.join(libadblockplus_root, 'v8', 'testing', 'gtest')
89 # duplicate(gtest_src, gtest_dst)
90 69
91 # v8/tools/gyp 70 for path in [
Vasily Kuznetsov 2018/01/19 13:06:52 Lines 91-112 could be rolled into a loop -- all fi
anton 2018/01/19 13:17:14 did you mean iterating over array of 'gyp','clang'
Vasily Kuznetsov 2018/01/19 13:35:17 Yeah, something like this: for path in [
92 tools_gyp_src = os.path.join(cwd, 'src', 'tools', 'gyp') 71 ('base', 'trace_event', 'common'),
93 tools_gyp_dst = os.path.join(libadblockplus_root, 'v8', 'tools', 'gyp') 72 ('build',),
94 duplicate(tools_gyp_src, tools_gyp_dst) 73 ('tools', 'gyp'),
95 74 ('tools', 'clang'),
96 # v8/tools/clang 75 ('third_party', 'icu'),
97 clang_src = os.path.join(cwd, 'src', 'tools', 'clang') 76 ('third_party' , 'jinja2'),
98 clang_dst = os.path.join(libadblockplus_root, 'v8', 'tools', 'clang') 77 ('third_party', 'markupsafe')
99 duplicate(clang_src, clang_dst) 78 ]:
100 79 src = os.path.join(cwd, 'src', *path)
101 # v8/third_party/icu 80 dst = os.path.join(libadblockplus_third_party, 'v8', *path)
102 icu_src = os.path.join(cwd, 'src', 'third_party', 'icu') 81 duplicate(src, dst)
103 icu_dst = os.path.join(libadblockplus_root, 'v8', 'third_party', 'icu')
104 duplicate(icu_src, icu_dst)
105
106 # v8/third_party/jinja2
107 jinja2_src = os.path.join(cwd, 'src', 'third_party', 'jinja2')
108 jinja2_dst = os.path.join(libadblockplus_root,
109 'v8', 'third_party', 'jinja2')
110 duplicate(jinja2_src, jinja2_dst)
111
112 # v8/third_party/markupsafe
113 markupsafe_src = os.path.join(cwd, 'src', 'third_party', 'markupsafe')
114 markupsafe_dst = os.path.join(libadblockplus_root,
115 'v8', 'third_party', 'markupsafe')
116 duplicate(markupsafe_src, markupsafe_dst)
117
118 return 0
119 82
120 83
121 def main(argv): 84 if __name__ == '__main__':
122 return prepare_deps()
123
124
125 if '__main__' == __name__:
Vasily Kuznetsov 2018/01/19 13:06:52 Yoda-conditions are generally frowned upon in Pyth
anton 2018/01/19 13:17:15 Acknowledged.
126 try: 85 try:
127 sys.exit(main(sys.argv[1:])) 86 prepare_deps()
Vasily Kuznetsov 2018/01/19 13:06:53 Since `main()` always returns the result of `prepa
Vasily Kuznetsov 2018/01/19 13:06:53 It seems like we could just call `prepare_deps()`
anton 2018/01/19 13:17:14 Acknowledged.
128 except KeyboardInterrupt: 87 except KeyboardInterrupt:
129 sys.stderr.write('interrupted\n') 88 sys.exit('interrupted')
Vasily Kuznetsov 2018/01/19 13:06:52 You can just use `sys.exit('interrupted')` to achi
anton 2018/01/19 13:17:15 Acknowledged.
130 sys.exit(1)
LEFTRIGHT

Powered by Google App Engine
This is Rietveld