|
| 1 | +import sys |
| 2 | +import re |
| 3 | +import datetime |
| 4 | +from urllib import request |
| 5 | + |
| 6 | + |
| 7 | +def request_repo_info(url: str): |
| 8 | + req = request.Request(url) |
| 9 | + resp = request.urlopen(req) |
| 10 | + if not resp.status == 200: |
| 11 | + print(f"[ERROR] could not contact server: {url}") |
| 12 | + quit(1) |
| 13 | + return resp |
| 14 | + |
| 15 | + |
| 16 | +if sys.argv[1] == "--do_choco_release?": |
| 17 | + now = datetime.datetime.now() |
| 18 | + blenderbim_date = now.strftime("%y%m%d") |
| 19 | + url = "https://github.com/IfcOpenShell/IfcOpenShell/releases/latest" |
| 20 | + resp = request_repo_info(url) |
| 21 | + if blenderbim_date in resp.url: |
| 22 | + print("do_choco_release", end="") |
| 23 | + |
| 24 | + |
| 25 | +elif sys.argv[1] == "--latest_blender_release_min_maj_pat?": |
| 26 | + re_blender_version_min_maj_pat = r"Latest Version.+<span>Blender (\d+\.\d+\.\d+)</span>" |
| 27 | + url = "https://community.chocolatey.org/packages/blender" |
| 28 | + resp = request_repo_info(url) |
| 29 | + html_txt = str(resp.read()) |
| 30 | + found = re.findall(re_blender_version_min_maj_pat, html_txt) |
| 31 | + if found: |
| 32 | + print(found[0], end="") |
| 33 | + |
| 34 | + |
| 35 | +elif sys.argv[1] == "--latest_blender_release_min_maj?": |
| 36 | + re_blender_version_min_maj = r"Latest Version.+<span>Blender (\d+\.\d+)\..+</span>" |
| 37 | + url = "https://community.chocolatey.org/packages/blender" |
| 38 | + resp = request_repo_info(url) |
| 39 | + html_txt = str(resp.read()) |
| 40 | + found = re.findall(re_blender_version_min_maj, html_txt) |
| 41 | + if found: |
| 42 | + print(found[0], end="") |
| 43 | + |
| 44 | +elif sys.argv[1] == "--latest_blender_python_version_maj_min?": |
| 45 | + # get latest blender version first |
| 46 | + re_blender_version_min_maj_pat = r"Latest Version.+<span>Blender (\d+\.\d+\.\d+)</span>" |
| 47 | + url = "https://community.chocolatey.org/packages/blender" |
| 48 | + resp = request_repo_info(url) |
| 49 | + html_txt = str(resp.read()) |
| 50 | + found = re.findall(re_blender_version_min_maj_pat, html_txt) |
| 51 | + if found: |
| 52 | + latest_blender_version_tag = f"v{found[0]}" |
| 53 | + re_blender_python_version_maj_min = r"SET\(PYTHON_VERSION (\d+.\d+) " |
| 54 | + url = f"https://raw.githubusercontent.com/blender/blender/{latest_blender_version_tag}/build_files/cmake/Modules/FindPythonLibsUnix.cmake" |
| 55 | + resp = request_repo_info(url) |
| 56 | + html_txt = str(resp.read()) |
| 57 | + found = re.findall(re_blender_python_version_maj_min, html_txt) |
| 58 | + if found: |
| 59 | + print(found[0], end="") |
| 60 | + |
| 61 | + |
| 62 | +elif sys.argv[1] == "--pyver?": |
| 63 | + # get latest blender version first |
| 64 | + re_blender_version_min_maj_pat = r"Latest Version.+<span>Blender (\d+\.\d+\.\d+)</span>" |
| 65 | + url = "https://community.chocolatey.org/packages/blender" |
| 66 | + resp = request_repo_info(url) |
| 67 | + html_txt = str(resp.read()) |
| 68 | + found = re.findall(re_blender_version_min_maj_pat, html_txt) |
| 69 | + if found: |
| 70 | + latest_blender_version_tag = f"v{found[0]}" |
| 71 | + re_blender_python_version_maj_min = r"SET\(PYTHON_VERSION (\d+.\d+) " |
| 72 | + url = f"https://raw.githubusercontent.com/blender/blender/{latest_blender_version_tag}/build_files/cmake/Modules/FindPythonLibsUnix.cmake" |
| 73 | + resp = request_repo_info(url) |
| 74 | + html_txt = str(resp.read()) |
| 75 | + found = re.findall(re_blender_python_version_maj_min, html_txt) |
| 76 | + if found: |
| 77 | + print(f"py{found[0].replace('.', '')}", end="") |
| 78 | + |
0 commit comments