Index: third_party/libadblockplus/download_ndk.py |
diff --git a/third_party/libadblockplus/download_ndk.py b/third_party/libadblockplus/download_ndk.py |
index 77a77231004ae514e1cf3b4d9040aab847ef1d29..386f474ec557960cb00f80ebcb350b0944e939f8 100644 |
--- a/third_party/libadblockplus/download_ndk.py |
+++ b/third_party/libadblockplus/download_ndk.py |
@@ -2,39 +2,51 @@ import os |
import urllib |
import zipfile |
import sys |
+import shutil |
-def main(argv): |
- # Download |
- ndk_src = 'https://dl.google.com/android/repository/android-ndk-r12b-linux-x86_64.zip' |
- |
- cwd = os.getcwd() |
- libadblockplus_root = os.path.join(cwd, 'src', 'third_party', 'libadblockplus', 'third_party') |
- ndk_dst = os.path.join(libadblockplus_root, 'android-ndk-r12b-linux-x86_64.zip') |
- if os.path.exists(ndk_dst): |
+def main(argv): |
+ # Download |
+ ndk_src = 'https://dl.google.com/android/repository/android-ndk-r12b-linux-x86_64.zip' |
+ |
+ cwd = os.getcwd() |
+ libadblockplus_third_party = os.path.join(cwd, |
+ 'src', 'third_party', |
+ 'libadblockplus', 'third_party') |
+ ndk_dst = os.path.join(libadblockplus_third_party, |
+ 'android-ndk-r12b-linux-x86_64.zip') |
+ |
+ if os.path.exists(ndk_dst): |
+ os.remove(ndk_dst) |
+ |
+ print('Downloading {} to {}'.format(ndk_src, ndk_dst)) |
+ urllib.urlretrieve(ndk_src, ndk_dst) |
+ |
+ # Delete existing NDK directory |
+ ndk_dir = os.path.join(libadblockplus_third_party, 'android-ndk-r12b') |
+ if os.path.exists(ndk_dir): |
+ print('Deleting {}'.format(ndk_dir)) |
+ shutil.rmtree(ndk_dir) |
+ |
+ # Extract zip (preserving file permissions) |
+ print('Extracting {} to {}'.format(ndk_dst, libadblockplus_third_party)) |
+ with zipfile.ZipFile(ndk_dst, 'r') as zf: |
+ for info in zf.infolist(): |
+ zf.extract(info.filename, path=libadblockplus_third_party) |
+ out_path = os.path.join(libadblockplus_third_party, info.filename) |
+ |
+ perm = info.external_attr >> 16L |
+ os.chmod(out_path, perm) |
+ |
+ # Delete zip |
os.remove(ndk_dst) |
- print('Downloading %s to %s' % (ndk_src, ndk_dst)) |
- urllib.urlretrieve(ndk_src, ndk_dst) |
- |
- # Extract zip (preserving file permissions) |
- print('Extracting %s to %s' % (ndk_dst, libadblockplus_root)) |
- with zipfile.ZipFile(ndk_dst, 'r') as zf: |
- for info in zf.infolist(): |
- zf.extract(info.filename, path=libadblockplus_root) |
- out_path = os.path.join(libadblockplus_root, info.filename) |
- |
- perm = info.external_attr >> 16L |
- os.chmod(out_path, perm) |
- |
- # Delete zip |
- os.remove(ndk_dst) |
+ return 0 |
- return 0 |
if '__main__' == __name__: |
- try: |
- sys.exit(main(sys.argv[1:])) |
- except KeyboardInterrupt: |
- sys.stderr.write('interrupted\n') |
- sys.exit(1) |
+ try: |
+ sys.exit(main(sys.argv[1:])) |
+ except KeyboardInterrupt: |
+ sys.stderr.write('interrupted\n') |
+ sys.exit(1) |