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

Unified 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.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/libadblockplus/prepare_dependencies.py
diff --git a/third_party/libadblockplus/prepare_dependencies.py b/third_party/libadblockplus/prepare_dependencies.py
index 9676c2a238b3677395c725fceae5c729d83e2228..48937e472c482b0509dad210cd85178ffff878d2 100644
--- a/third_party/libadblockplus/prepare_dependencies.py
+++ b/third_party/libadblockplus/prepare_dependencies.py
@@ -2,110 +2,129 @@ import sys
import os
import shutil
+
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.
- if (os.path.exists(dst)):
- if (os.path.isdir(dst)):
- print('Deleting %s' % dst)
- shutil.rmtree(dst);
+ if os.path.exists(dst):
+ if os.path.isdir(dst):
+ 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
+ shutil.rmtree(dst)
+ else:
+ # 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.
+ os.unlink(dst)
+
+ dst_parent = os.path.abspath(os.path.join(dst, os.pardir))
+ if not os.path.exists(dst_parent):
+ print('Creating parent directory {} for {}'.format(dst_parent, dst))
+ os.makedirs(dst_parent)
+
+ if symlink:
+ print('Symlinking {} to {}'.format(src, dst))
+ os.symlink(src, dst)
else:
- # symlink
- os.unlink(dst)
-
- dst_parent = os.path.abspath(os.path.join(dst, os.pardir))
- if not os.path.exists(dst_parent):
- print('Creating parent directory %s for %s' % (dst_parent, dst))
- os.makedirs(dst_parent)
-
- if symlink:
- print('Symlinking %s to %s' % (src, dst))
- os.symlink(src, dst)
- else:
- print('Copying %s to %s' % (src, dst))
- shutil.copytree(src, dst)
+ print('Copying {} to {}'.format(src, dst))
+ shutil.copytree(src, dst)
+
def prepare_deps():
- cwd = os.getcwd()
- libadblockplus_root = os.path.join(cwd, 'src', 'third_party', 'libadblockplus', 'third_party')
-
- # googletest
- # Chromium's googletest has a bit different directories structure ('src' as subdirectory)
- #googletest_src = os.path.join(cwd, 'src', 'third_party', 'googletest')
- #googletest_dst = os.path.join(libadblockplus_root, 'googletest')
- #duplicate(googletest_src, googletest_dst)
-
- # gyp
- # Chromium's gyp can't be used because of compile error:
- # *** No rule to make target `shell/src/Main.cpp', needed by `local/armeabi-v7a/objs/abpshell/shell/src/Main.o'. Stop.
- # See. https://hg.adblockplus.org/gyp/rev/fix-issue-339
- #gyp_src = os.path.join(cwd, 'src', 'tools', 'gyp')
- #gyp_dst = os.path.join(libadblockplus_root, 'gyp')
- #duplicate(gyp_src, gyp_dst)
-
- # back-up /v8/testing/gtest as it will be deleted while preparing v8
- gtest_bak_src = os.path.join(libadblockplus_root, 'v8', 'testing', 'gtest')
- gtest_bak_dst = os.path.join(libadblockplus_root, 'gtest.bak')
- shutil.move(gtest_bak_src, gtest_bak_dst)
-
- # v8
- v8_src = os.path.join(cwd, 'src', 'v8')
- v8_dst = os.path.join(libadblockplus_root, 'v8')
- duplicate(v8_src, v8_dst)
-
- # restore /v8/testing/gtest from backup
- shutil.move(gtest_bak_dst, gtest_bak_src)
-
- # v8/base/trace_event/common
- trace_common_src = os.path.join(cwd, 'src', 'base', 'trace_event', 'common')
- trace_common_dst = os.path.join(libadblockplus_root, 'v8', 'base', 'trace_event', 'common')
- duplicate(trace_common_src, trace_common_dst)
-
- # v8/build
- build_src = os.path.join(cwd, 'src', 'build')
- build_dst = os.path.join(libadblockplus_root, 'v8', 'build')
- duplicate(build_src, build_dst)
-
- # v8/testing/gtest
- # Chromium's gtest can't be used becuase of compile error:
- # fatal error: third_party/googletest/src/googletest/include/gtest/gtest_prod.h: No such file or directory
- # #include "third_party/googletest/src/googletest/include/gtest/gtest_prod.h"
- # so we have to back-up gtest above and restore it after prepring of 'v8' directory
- #gtest_src = os.path.join(cwd, 'src', 'testing', 'gtest')
- #gtest_dst = os.path.join(libadblockplus_root, 'v8', 'testing', 'gtest')
- #duplicate(gtest_src, gtest_dst)
-
- # v8/tools/gyp
- tools_gyp_src = os.path.join(cwd, 'src', 'tools', 'gyp')
- tools_gyp_dst = os.path.join(libadblockplus_root, 'v8', 'tools', 'gyp')
- duplicate(tools_gyp_src, tools_gyp_dst)
-
- # v8/tools/clang
- clang_src = os.path.join(cwd, 'src', 'tools', 'clang')
- clang_dst = os.path.join(libadblockplus_root, 'v8', 'tools', 'clang')
- duplicate(clang_src, clang_dst)
-
- # v8/third_party/icu
- icu_src = os.path.join(cwd, 'src', 'third_party', 'icu')
- icu_dst = os.path.join(libadblockplus_root, 'v8', 'third_party', 'icu')
- duplicate(icu_src, icu_dst)
-
- # v8/third_party/jinja2
- jinja2_src = os.path.join(cwd, 'src', 'third_party', 'jinja2')
- jinja2_dst = os.path.join(libadblockplus_root, 'v8', 'third_party', 'jinja2')
- duplicate(jinja2_src, jinja2_dst)
-
- # v8/third_party/markupsafe
- markupsafe_src = os.path.join(cwd, 'src', 'third_party', 'markupsafe')
- markupsafe_dst = os.path.join(libadblockplus_root, 'v8', 'third_party', 'markupsafe')
- duplicate(markupsafe_src, markupsafe_dst)
-
- return 0
+ cwd = os.getcwd()
+ 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
+ 'src', 'third_party',
+ 'libadblockplus', 'third_party')
+
+ # googletest
+ #
+ # Chromium's googletest has a bit different directories structure
+ # ('src' as subdirectory)
+ #
+ # 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
+ # googletest_dst = os.path.join(libadblockplus_root, 'googletest')
+ # duplicate(googletest_src, googletest_dst)
+
+ # gyp
+ #
+ # Chromium's gyp can't be used because of compile error:
+ # *** No rule to make target `shell/src/Main.cpp',
+ # needed by `local/armeabi-v7a/objs/abpshell/shell/src/Main.o'. Stop.
+ # See. https://hg.adblockplus.org/gyp/rev/fix-issue-339
+ #
+ # gyp_src = os.path.join(cwd, 'src', 'tools', 'gyp')
+ # gyp_dst = os.path.join(libadblockplus_root, 'gyp')
+ # duplicate(gyp_src, gyp_dst)
+
+ # back-up /v8/testing/gtest as it will be deleted while preparing v8
+ gtest_bak_src = os.path.join(libadblockplus_root, 'v8', 'testing', 'gtest')
+ gtest_bak_dst = os.path.join(libadblockplus_root, 'gtest.bak')
+ shutil.move(gtest_bak_src, gtest_bak_dst)
+
+ # v8
+ v8_src = os.path.join(cwd, 'src', 'v8')
+ v8_dst = os.path.join(libadblockplus_root, 'v8')
+ duplicate(v8_src, v8_dst)
+
+ # restore /v8/testing/gtest from backup
+ shutil.move(gtest_bak_dst, gtest_bak_src)
+
+ # v8/base/trace_event/common
+ trace_common_src = os.path.join(cwd,
+ 'src', 'base', 'trace_event', 'common')
+ trace_common_dst = os.path.join(libadblockplus_root,
+ 'v8', 'base', 'trace_event', 'common')
+ duplicate(trace_common_src, trace_common_dst)
+
+ # v8/build
+ build_src = os.path.join(cwd, 'src', 'build')
+ build_dst = os.path.join(libadblockplus_root, 'v8', 'build')
+ duplicate(build_src, build_dst)
+
+ # v8/testing/gtest
+ #
+ # Chromium's gtest can't be used becuase of compile error:
+ # fatal error: third_party/googletest/src/googletest/include/gtest/gtest_prod.h: No such file or directory
+ # #include "third_party/googletest/src/googletest/include/gtest/gtest_prod.h"
+ # so we have to back-up gtest above and restore it
+ # after prepring of 'v8' directory
+ #
+ # gtest_src = os.path.join(cwd, 'src', 'testing', 'gtest')
+ # gtest_dst = os.path.join(libadblockplus_root, 'v8', 'testing', 'gtest')
+ # duplicate(gtest_src, gtest_dst)
+
+ # 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 [
+ tools_gyp_src = os.path.join(cwd, 'src', 'tools', 'gyp')
+ tools_gyp_dst = os.path.join(libadblockplus_root, 'v8', 'tools', 'gyp')
+ duplicate(tools_gyp_src, tools_gyp_dst)
+
+ # v8/tools/clang
+ clang_src = os.path.join(cwd, 'src', 'tools', 'clang')
+ clang_dst = os.path.join(libadblockplus_root, 'v8', 'tools', 'clang')
+ duplicate(clang_src, clang_dst)
+
+ # v8/third_party/icu
+ icu_src = os.path.join(cwd, 'src', 'third_party', 'icu')
+ icu_dst = os.path.join(libadblockplus_root, 'v8', 'third_party', 'icu')
+ duplicate(icu_src, icu_dst)
+
+ # v8/third_party/jinja2
+ jinja2_src = os.path.join(cwd, 'src', 'third_party', 'jinja2')
+ jinja2_dst = os.path.join(libadblockplus_root,
+ 'v8', 'third_party', 'jinja2')
+ duplicate(jinja2_src, jinja2_dst)
+
+ # v8/third_party/markupsafe
+ markupsafe_src = os.path.join(cwd, 'src', 'third_party', 'markupsafe')
+ markupsafe_dst = os.path.join(libadblockplus_root,
+ 'v8', 'third_party', 'markupsafe')
+ duplicate(markupsafe_src, markupsafe_dst)
+
+ return 0
+
def main(argv):
- return prepare_deps();
+ return prepare_deps()
+
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.
- try:
- sys.exit(main(sys.argv[1:]))
- except KeyboardInterrupt:
- sys.stderr.write('interrupted\n')
- sys.exit(1)
+ try:
+ 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.
+ except KeyboardInterrupt:
+ 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.
+ sys.exit(1)
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld