| LEFT | RIGHT | 
|---|
| (no file at all) |  | 
| 1 import os | 1 import os | 
| 2 import urllib | 2 import urllib | 
| 3 import zipfile | 3 import zipfile | 
| 4 import sys | 4 import sys | 
|  | 5 import shutil | 
|  | 6 | 
| 5 | 7 | 
| 6 def main(argv): | 8 def main(argv): | 
| 7   # Download | 9     # Download | 
| 8   ndk_src = 'https://dl.google.com/android/repository/android-ndk-r12b-linux-x86
    _64.zip' | 10     ndk_src = 'https://dl.google.com/android/repository/android-ndk-r12b-linux-x
    86_64.zip' | 
| 9 | 11 | 
| 10   cwd = os.getcwd() | 12     cwd = os.getcwd() | 
| 11   libadblockplus_root = os.path.join(cwd, 'src', 'third_party', 'libadblockplus'
    , 'third_party') | 13     libadblockplus_third_party = os.path.join(cwd, | 
| 12   ndk_dst = os.path.join(libadblockplus_root, 'android-ndk-r12b-linux-x86_64.zip
    ') | 14                                               'src', 'third_party', | 
|  | 15                                               'libadblockplus', 'third_party') | 
|  | 16     ndk_dst = os.path.join(libadblockplus_third_party, | 
|  | 17                            'android-ndk-r12b-linux-x86_64.zip') | 
| 13 | 18 | 
| 14   if os.path.exists(ndk_dst): | 19     if os.path.exists(ndk_dst): | 
|  | 20         os.remove(ndk_dst) | 
|  | 21 | 
|  | 22     print('Downloading {} to {}'.format(ndk_src, ndk_dst)) | 
|  | 23     urllib.urlretrieve(ndk_src, ndk_dst) | 
|  | 24 | 
|  | 25     # Delete existing NDK directory | 
|  | 26     ndk_dir = os.path.join(libadblockplus_third_party, 'android-ndk-r12b') | 
|  | 27     if os.path.exists(ndk_dir): | 
|  | 28         print('Deleting {}'.format(ndk_dir)) | 
|  | 29         shutil.rmtree(ndk_dir) | 
|  | 30 | 
|  | 31     # Extract zip (preserving file permissions) | 
|  | 32     print('Extracting {} to {}'.format(ndk_dst, libadblockplus_third_party)) | 
|  | 33     with zipfile.ZipFile(ndk_dst, 'r') as zf: | 
|  | 34         for info in zf.infolist(): | 
|  | 35             zf.extract(info.filename, path=libadblockplus_third_party) | 
|  | 36             out_path = os.path.join(libadblockplus_third_party, info.filename) | 
|  | 37 | 
|  | 38             perm = info.external_attr >> 16L | 
|  | 39             os.chmod(out_path, perm) | 
|  | 40 | 
|  | 41     # Delete zip | 
| 15     os.remove(ndk_dst) | 42     os.remove(ndk_dst) | 
| 16 | 43 | 
| 17   print('Downloading %s to %s' % (ndk_src, ndk_dst)) | 44     return 0 | 
| 18   urllib.urlretrieve(ndk_src, ndk_dst) |  | 
| 19 | 45 | 
| 20   # Extract zip (preserving file permissions) |  | 
| 21   print('Extracting %s to %s' % (ndk_dst, libadblockplus_root)) |  | 
| 22   with zipfile.ZipFile(ndk_dst, 'r') as zf: |  | 
| 23     for info in zf.infolist(): |  | 
| 24       zf.extract(info.filename, path=libadblockplus_root) |  | 
| 25       out_path = os.path.join(libadblockplus_root, info.filename) |  | 
| 26 |  | 
| 27       perm = info.external_attr >> 16L |  | 
| 28       os.chmod(out_path, perm) |  | 
| 29 |  | 
| 30   # Delete zip |  | 
| 31   os.remove(ndk_dst) |  | 
| 32 |  | 
| 33   return 0 |  | 
| 34 | 46 | 
| 35 if '__main__' == __name__: | 47 if '__main__' == __name__: | 
| 36   try: | 48     try: | 
| 37     sys.exit(main(sys.argv[1:])) | 49         sys.exit(main(sys.argv[1:])) | 
| 38   except KeyboardInterrupt: | 50     except KeyboardInterrupt: | 
| 39     sys.stderr.write('interrupted\n') | 51         sys.stderr.write('interrupted\n') | 
| 40     sys.exit(1) | 52         sys.exit(1) | 
| LEFT | RIGHT | 
|---|