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

Side by Side Diff: third_party/libadblockplus/prepare_dependencies.py

Issue 29674555: Issue 6273 - Apply eyeo python code style (Closed)
Patch Set: Created Jan. 19, 2018, 7:28 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 | « no previous file | 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 sys 1 import sys
2 import os 2 import os
3 import shutil 3 import shutil
4 4
5
5 def duplicate(src, dst, symlink=False): 6 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.
6 if (os.path.exists(dst)): 7 if os.path.exists(dst):
7 if (os.path.isdir(dst)): 8 if os.path.isdir(dst):
8 print('Deleting %s' % dst) 9 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
9 shutil.rmtree(dst); 10 shutil.rmtree(dst)
11 else:
12 # 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)
14
15 dst_parent = os.path.abspath(os.path.join(dst, os.pardir))
16 if not os.path.exists(dst_parent):
17 print('Creating parent directory {} for {}'.format(dst_parent, dst))
18 os.makedirs(dst_parent)
19
20 if symlink:
21 print('Symlinking {} to {}'.format(src, dst))
22 os.symlink(src, dst)
10 else: 23 else:
11 # symlink 24 print('Copying {} to {}'.format(src, dst))
12 os.unlink(dst) 25 shutil.copytree(src, dst)
13
14 dst_parent = os.path.abspath(os.path.join(dst, os.pardir))
15 if not os.path.exists(dst_parent):
16 print('Creating parent directory %s for %s' % (dst_parent, dst))
17 os.makedirs(dst_parent)
18 26
19 if symlink:
20 print('Symlinking %s to %s' % (src, dst))
21 os.symlink(src, dst)
22 else:
23 print('Copying %s to %s' % (src, dst))
24 shutil.copytree(src, dst)
25 27
26 def prepare_deps(): 28 def prepare_deps():
27 cwd = os.getcwd() 29 cwd = os.getcwd()
28 libadblockplus_root = os.path.join(cwd, 'src', 'third_party', 'libadblockplus' , 'third_party') 30 libadblockplus_root = 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
29 31 'src', 'third_party',
30 # googletest 32 'libadblockplus', 'third_party')
31 # Chromium's googletest has a bit different directories structure ('src' as su bdirectory)
32 #googletest_src = os.path.join(cwd, 'src', 'third_party', 'googletest')
33 #googletest_dst = os.path.join(libadblockplus_root, 'googletest')
34 #duplicate(googletest_src, googletest_dst)
35 33
36 # gyp 34 # googletest
37 # Chromium's gyp can't be used because of compile error: 35 #
38 # *** No rule to make target `shell/src/Main.cpp', needed by `local/armeabi-v7 a/objs/abpshell/shell/src/Main.o'. Stop. 36 # Chromium's googletest has a bit different directories structure
39 # See. https://hg.adblockplus.org/gyp/rev/fix-issue-339 37 # ('src' as subdirectory)
40 #gyp_src = os.path.join(cwd, 'src', 'tools', 'gyp') 38 #
41 #gyp_dst = os.path.join(libadblockplus_root, 'gyp') 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
42 #duplicate(gyp_src, gyp_dst) 40 # googletest_dst = os.path.join(libadblockplus_root, 'googletest')
41 # duplicate(googletest_src, googletest_dst)
43 42
44 # back-up /v8/testing/gtest as it will be deleted while preparing v8 43 # gyp
45 gtest_bak_src = os.path.join(libadblockplus_root, 'v8', 'testing', 'gtest') 44 #
46 gtest_bak_dst = os.path.join(libadblockplus_root, 'gtest.bak') 45 # Chromium's gyp can't be used because of compile error:
47 shutil.move(gtest_bak_src, gtest_bak_dst) 46 # *** No rule to make target `shell/src/Main.cpp',
47 # needed by `local/armeabi-v7a/objs/abpshell/shell/src/Main.o'. Stop.
48 # 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)
48 53
49 # v8 54 # back-up /v8/testing/gtest as it will be deleted while preparing v8
50 v8_src = os.path.join(cwd, 'src', 'v8') 55 gtest_bak_src = os.path.join(libadblockplus_root, 'v8', 'testing', 'gtest')
51 v8_dst = os.path.join(libadblockplus_root, 'v8') 56 gtest_bak_dst = os.path.join(libadblockplus_root, 'gtest.bak')
52 duplicate(v8_src, v8_dst) 57 shutil.move(gtest_bak_src, gtest_bak_dst)
53 58
54 # restore /v8/testing/gtest from backup 59 # v8
55 shutil.move(gtest_bak_dst, gtest_bak_src) 60 v8_src = os.path.join(cwd, 'src', 'v8')
61 v8_dst = os.path.join(libadblockplus_root, 'v8')
62 duplicate(v8_src, v8_dst)
56 63
57 # v8/base/trace_event/common 64 # restore /v8/testing/gtest from backup
58 trace_common_src = os.path.join(cwd, 'src', 'base', 'trace_event', 'common') 65 shutil.move(gtest_bak_dst, gtest_bak_src)
59 trace_common_dst = os.path.join(libadblockplus_root, 'v8', 'base', 'trace_even t', 'common')
60 duplicate(trace_common_src, trace_common_dst)
61 66
62 # v8/build 67 # v8/base/trace_event/common
63 build_src = os.path.join(cwd, 'src', 'build') 68 trace_common_src = os.path.join(cwd,
64 build_dst = os.path.join(libadblockplus_root, 'v8', 'build') 69 'src', 'base', 'trace_event', 'common')
65 duplicate(build_src, build_dst) 70 trace_common_dst = os.path.join(libadblockplus_root,
71 'v8', 'base', 'trace_event', 'common')
72 duplicate(trace_common_src, trace_common_dst)
66 73
67 # v8/testing/gtest 74 # v8/build
68 # Chromium's gtest can't be used becuase of compile error: 75 build_src = os.path.join(cwd, 'src', 'build')
69 # fatal error: third_party/googletest/src/googletest/include/gtest/gtest_prod. h: No such file or directory 76 build_dst = os.path.join(libadblockplus_root, 'v8', 'build')
70 # #include "third_party/googletest/src/googletest/include/gtest/gtest_prod.h" 77 duplicate(build_src, build_dst)
71 # so we have to back-up gtest above and restore it after prepring of 'v8' dire ctory
72 #gtest_src = os.path.join(cwd, 'src', 'testing', 'gtest')
73 #gtest_dst = os.path.join(libadblockplus_root, 'v8', 'testing', 'gtest')
74 #duplicate(gtest_src, gtest_dst)
75 78
76 # v8/tools/gyp 79 # v8/testing/gtest
77 tools_gyp_src = os.path.join(cwd, 'src', 'tools', 'gyp') 80 #
78 tools_gyp_dst = os.path.join(libadblockplus_root, 'v8', 'tools', 'gyp') 81 # Chromium's gtest can't be used becuase of compile error:
79 duplicate(tools_gyp_src, tools_gyp_dst) 82 # 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 "
84 # so we have to back-up gtest above and restore it
85 # 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)
80 90
81 # v8/tools/clang 91 # v8/tools/gyp
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 [
82 clang_src = os.path.join(cwd, 'src', 'tools', 'clang') 92 tools_gyp_src = os.path.join(cwd, 'src', 'tools', 'gyp')
83 clang_dst = os.path.join(libadblockplus_root, 'v8', 'tools', 'clang') 93 tools_gyp_dst = os.path.join(libadblockplus_root, 'v8', 'tools', 'gyp')
84 duplicate(clang_src, clang_dst) 94 duplicate(tools_gyp_src, tools_gyp_dst)
85 95
86 # v8/third_party/icu 96 # v8/tools/clang
87 icu_src = os.path.join(cwd, 'src', 'third_party', 'icu') 97 clang_src = os.path.join(cwd, 'src', 'tools', 'clang')
88 icu_dst = os.path.join(libadblockplus_root, 'v8', 'third_party', 'icu') 98 clang_dst = os.path.join(libadblockplus_root, 'v8', 'tools', 'clang')
89 duplicate(icu_src, icu_dst) 99 duplicate(clang_src, clang_dst)
90 100
91 # v8/third_party/jinja2 101 # v8/third_party/icu
92 jinja2_src = os.path.join(cwd, 'src', 'third_party', 'jinja2') 102 icu_src = os.path.join(cwd, 'src', 'third_party', 'icu')
93 jinja2_dst = os.path.join(libadblockplus_root, 'v8', 'third_party', 'jinja2') 103 icu_dst = os.path.join(libadblockplus_root, 'v8', 'third_party', 'icu')
94 duplicate(jinja2_src, jinja2_dst) 104 duplicate(icu_src, icu_dst)
95 105
96 # v8/third_party/markupsafe 106 # v8/third_party/jinja2
97 markupsafe_src = os.path.join(cwd, 'src', 'third_party', 'markupsafe') 107 jinja2_src = os.path.join(cwd, 'src', 'third_party', 'jinja2')
98 markupsafe_dst = os.path.join(libadblockplus_root, 'v8', 'third_party', 'marku psafe') 108 jinja2_dst = os.path.join(libadblockplus_root,
99 duplicate(markupsafe_src, markupsafe_dst) 109 'v8', 'third_party', 'jinja2')
110 duplicate(jinja2_src, jinja2_dst)
100 111
101 return 0 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
102 120
103 def main(argv): 121 def main(argv):
104 return prepare_deps(); 122 return prepare_deps()
123
105 124
106 if '__main__' == __name__: 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.
107 try: 126 try:
108 sys.exit(main(sys.argv[1:])) 127 sys.exit(main(sys.argv[1:]))
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.
109 except KeyboardInterrupt: 128 except KeyboardInterrupt:
110 sys.stderr.write('interrupted\n') 129 sys.stderr.write('interrupted\n')
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.
111 sys.exit(1) 130 sys.exit(1)
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld