|
| 1 | +import urllib.request |
| 2 | +import tarfile |
| 3 | +import os |
| 4 | + |
| 5 | +version = "0.6.0" # see objectbox/c.py required_version |
| 6 | + |
| 7 | +conan_repo = "https://dl.bintray.com/objectbox/conan/objectbox/objectbox-c" |
| 8 | +conan_channel = "testing" |
| 9 | + |
| 10 | +# map between ./objectbox/lib paths and hashes in the conan_repo |
| 11 | +# see https://github.com/objectbox/objectbox-c/blob/main/download.sh for the hashes |
| 12 | +out_dir = "objectbox/lib" |
| 13 | +file_hashes = { |
| 14 | + # objectbox.h is common for all types, get it from the linux x86_64 distributable |
| 15 | + "objectbox.h": "4db1be536558d833e52e862fd84d64d75c2b3656", |
| 16 | + |
| 17 | + # linux |
| 18 | + "x86_64/libobjectbox.so": "4db1be536558d833e52e862fd84d64d75c2b3656", |
| 19 | + "armv7l/libobjectbox.so": "4a625f0bd5f477eacd9bd35e9c44c834d057524b", |
| 20 | + "armv6l/libobjectbox.so": "d42930899c74345edc43f8b7519ec7645c13e4d8", |
| 21 | + |
| 22 | + # mac |
| 23 | + "x86_64/libobjectbox.dylib": "46f53f156846659bf39ad6675fa0ee8156e859fe", |
| 24 | + |
| 25 | + # windows |
| 26 | + "AMD64/objectbox.dll": "ca33edce272a279b24f87dc0d4cf5bbdcffbc187", |
| 27 | +} |
| 28 | + |
| 29 | + |
| 30 | +def url_for(rel_path: str) -> str: |
| 31 | + return conan_repo + "/" + version + "/" + conan_channel + "/0/package/" \ |
| 32 | + + file_hashes[rel_path] + "/0/conan_package.tgz" |
| 33 | + |
| 34 | + |
| 35 | +def fullmkdir(path: str): |
| 36 | + if not os.path.exists(path): |
| 37 | + os.makedirs(path) |
| 38 | + |
| 39 | + |
| 40 | +def download(rel_path: str): |
| 41 | + basename = os.path.basename(rel_path) |
| 42 | + archive_dir = "include" if basename.endswith(".h") else "lib" |
| 43 | + out_path = out_dir + "/" + rel_path |
| 44 | + |
| 45 | + print("Downloading", out_path) |
| 46 | + fullmkdir(os.path.dirname(out_path)) |
| 47 | + |
| 48 | + # Download the file from `url`, save it in a temporary directory and get the path to it (e.g. '/tmp/tmpb48zma') |
| 49 | + tmp_file, headers = urllib.request.urlretrieve(url_for(rel_path)) |
| 50 | + |
| 51 | + # extract the file |
| 52 | + archive = tarfile.open(tmp_file, mode='r:gz') |
| 53 | + archived_file = archive.extractfile(archive_dir + "/" + basename) |
| 54 | + with open(out_path, 'wb') as file: |
| 55 | + file.writelines(archived_file.readlines()) |
| 56 | + |
| 57 | + |
| 58 | +# execute the download for each item in the file hashes |
| 59 | +for key in file_hashes: |
| 60 | + download(key) |
0 commit comments