|
| 1 | +#! /usr/local/bin/python3 |
| 2 | + |
| 3 | +from github import Github |
| 4 | +import toml |
| 5 | +import urllib3 |
| 6 | +import certifi |
| 7 | +import os.path |
| 8 | +import os |
| 9 | +import tarfile |
| 10 | + |
| 11 | + |
| 12 | +# find root of project and leanpkg.toml |
| 13 | +cwd = os.getcwd() |
| 14 | +while not os.path.isfile('leanpkg.toml') and not os.getcwd() == '/': |
| 15 | + os.chdir(os.path.dirname(os.getcwd())) |
| 16 | +if not os.path.isfile('leanpkg.toml'): |
| 17 | + raise('no leanpkg.toml found') |
| 18 | + |
| 19 | +mathlib_dir = os.path.join( os.environ['HOME'], '.mathlib' ) |
| 20 | +if not os.path.isdir(mathlib_dir): |
| 21 | + os.mkdir(mathlib_dir) |
| 22 | + |
| 23 | +# parse leanpkg.toml |
| 24 | +leanpkg = toml.load('leanpkg.toml') |
| 25 | +lib = leanpkg['dependencies']['mathlib'] |
| 26 | + |
| 27 | +# download archive |
| 28 | +if lib['git'] in ['https://github.com/leanprover/mathlib','https://github.com/leanprover-community/mathlib']: |
| 29 | + rev = lib['rev'] |
| 30 | + hash = rev[:7] |
| 31 | + |
| 32 | + g = Github("cipher1024","sZ2335743") |
| 33 | + repo = g.get_repo("leanprover-community/mathlib") |
| 34 | + assets = [r.get_assets() for r in (repo.get_releases()) |
| 35 | + if r.tag_name.split('-')[3] == hash and r.tag_name.split('-')[0] == 'bin'] |
| 36 | + a = assets[0][0] |
| 37 | + cd = os.getcwd() |
| 38 | + os.chdir(mathlib_dir) |
| 39 | + if not os.path.isfile(a.name): |
| 40 | + http = urllib3.PoolManager( |
| 41 | + cert_reqs='CERT_REQUIRED', |
| 42 | + ca_certs=certifi.where()) |
| 43 | + r = http.request('GET', a.browser_download_url) |
| 44 | + f = open(a.name,'wb') |
| 45 | + f.write(r.data) |
| 46 | + f.close() |
| 47 | + os.chdir(cd) |
| 48 | + |
| 49 | + # extract archive |
| 50 | + ar = tarfile.open(os.path.join(mathlib_dir, a.name)) |
| 51 | + ar.extractall('_target/deps/mathlib') |
0 commit comments