Skip to content

Commit d058f17

Browse files
befrMoult
authored andcommitted
add logic to build blenderbim-nightly chocolatey package
1 parent bbb3b62 commit d058f17

9 files changed

Lines changed: 239 additions & 0 deletions

choco/blenderbim/blenderbim.nuspec

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- Do not remove this test for UTF-8: if “Ω” doesn’t appear as greek uppercase omega letter enclosed in quotation marks, you should use an editor that supports UTF-8, not this one. -->
3+
<package xmlns="http://schemas.microsoft.com/packaging/2015/06/nuspec.xsd">
4+
<metadata>
5+
<id>blenderbim-nightly</id>
6+
<version>blenderbim_build_version</version>
7+
<packageSourceUrl>https://github.com/IfcOpenShell/IfcOpenShell</packageSourceUrl>
8+
<owners>fbpyr</owners>
9+
<!-- == SOFTWARE SPECIFIC SECTION == -->
10+
<title>BlenderBIM install nightly</title>
11+
<authors>Dion Moult and many more, see: https://github.com/IfcOpenShell/IfcOpenShell/graphs/contributors</authors>
12+
<projectUrl>https://github.com/IfcOpenShell/IfcOpenShell</projectUrl>
13+
<iconUrl>https://rawcdn.githack.com/fbpyr/IfcOpenShell/9662598ad4a7e4b6cd8980e430d07263835d0eda/choco/blenderbim/blenderbim.png</iconUrl>
14+
<!-- <copyright>Year Software Vendor</copyright> -->
15+
<licenseUrl>https://github.com/IfcOpenShell/IfcOpenShell/blob/v0.7.0/COPYING</licenseUrl>
16+
<requireLicenseAcceptance>true</requireLicenseAcceptance>
17+
<projectSourceUrl>https://github.com/IfcOpenShell/IfcOpenShell</projectSourceUrl>
18+
<docsUrl>https://blenderbim.org/docs/</docsUrl>
19+
<!--<mailingListUrl></mailingListUrl>-->
20+
<bugTrackerUrl>https://github.com/IfcOpenShell/IfcOpenShell/issues</bugTrackerUrl>
21+
<tags>blender bim blenderbim python opensource foss</tags>
22+
<summary>opensource bim</summary>
23+
<description>opensource bim addon for blender</description>
24+
<!-- <releaseNotes>__REPLACE_OR_REMOVE__MarkDown_Okay</releaseNotes> -->
25+
26+
<dependencies>
27+
<dependency id="blender" version="latest_blender_version_maj_min_pat" />
28+
<dependency id="7zip" version="22.1"/>
29+
</dependencies>
30+
</metadata>
31+
<files>
32+
<file src="tools\**" target="tools" />
33+
</files>
34+
</package>

choco/blenderbim/blenderbim.png

4.94 KB
Loading
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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+
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import os
2+
from pathlib import Path
3+
4+
5+
print("[INFO] inserting dynamic chocolatey package parameters")
6+
HERE_DIR = Path(__file__).parent.absolute()
7+
# print(f"[INFO] HERE_DIR: {HERE_DIR}")
8+
9+
topics = {
10+
"spec": {
11+
"path": HERE_DIR / "blenderbim.nuspec",
12+
"env_vars": {
13+
"latest_blender_version_maj_min_pat",
14+
"blenderbim_build_version",
15+
},
16+
},
17+
"install": {
18+
"path": HERE_DIR / "tools" / "chocolateyinstall.ps1",
19+
"env_vars": {
20+
"url_blenderbim_py310_win_zip",
21+
"sha256sum_blenderbim_py310_win_zip",
22+
"latest_blender_version_maj_min",
23+
},
24+
},
25+
"uninstall": {
26+
"path": HERE_DIR / "tools" / "chocolateyuninstall.ps1",
27+
"env_vars": {
28+
"latest_blender_version_maj_min",
29+
},
30+
},
31+
}
32+
33+
for topic, info in topics.items():
34+
print(f"[INFO] {topic}:")
35+
for env_var_name in info["env_vars"]:
36+
print(f"[INFO] {env_var_name} exists?: {os.environ[env_var_name]}")
37+
38+
with open(info["path"], encoding="utf-8") as txt:
39+
content = txt.read()
40+
41+
for env_var_name in info["env_vars"]:
42+
# print(f"[INFO] replace: {env_var_name}")
43+
content = content.replace(env_var_name, os.environ[env_var_name])
44+
45+
with open(info["path"], "w", encoding="utf-8") as txt:
46+
txt.write(content)
47+
print(f"[INFO] written: {info['path']}")
48+
49+
print("[INFO] inserting dynamic chocolatey package parameters successful")
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
$processName = "blender"
2+
$blenderIsRunning = Get-Process -Name $processName -ErrorAction SilentlyContinue
3+
4+
if($blenderIsRunning -eq $null) {
5+
echo "Blender is not running ready for next action."
6+
}
7+
else {
8+
Write-Warning "$processName is still running - installer cannot safely proceed to next action."
9+
Write-Warning "Please retry after closing all running blender applications."
10+
exit 1
11+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
$ErrorActionPreference = 'Stop'
2+
3+
$url64 = 'url_blenderbim_py310_win_zip'
4+
$checksum64 = 'sha256sum_blenderbim_py310_win_zip'
5+
$checksumType64 = 'sha256'
6+
7+
$appDataUserDir = [System.Environment]::GetEnvironmentVariable('appdata')
8+
$unzipTargetDir = "$appDataUserDir\Blender Foundation\Blender\latest_blender_version_maj_min\scripts\addons"
9+
10+
$chocoBaseDir = [System.Environment]::GetEnvironmentVariable('ChocolateyInstall')
11+
$addonEnable = "$chocoBaseDir\lib\blenderbim\tools\enable_blenderbim_addon.py"
12+
13+
$programFilesDir = [System.Environment]::GetEnvironmentVariable('ProgramFiles')
14+
$blenderExePath = "$env:ProgramFiles\Blender Foundation\Blender latest_blender_version_maj_min\blender.exe"
15+
16+
$processName = "blender"
17+
$blenderIsRunning = Get-Process -Name $processName -ErrorAction SilentlyContinue
18+
19+
20+
if($blenderIsRunning -eq $null) {
21+
echo "attempting to install blenderbim."
22+
Install-ChocolateyZipPackage -PackageName $env:ChocolateyPackageName -Url64 $url64 -Checksum64 $checksum64 -checksumType $checksumType64 -UnzipLocation $unzipTargetDir
23+
Start-Process -FilePath $blenderExePath -ArgumentList "-b", "-y", "--python", "$addonEnable"
24+
}
25+
else {
26+
Write-Warning "$processName is still running - blenderbim cannot be safely installed."
27+
Write-Warning "Please retry after closing all running blender applications."
28+
exit 1
29+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
$appDataUserDir = [System.Environment]::GetEnvironmentVariable('appdata')
2+
$unzippedDir = "$appDataUserDir\Blender Foundation\Blender\latest_blender_version_maj_min\scripts\addons\blenderbim"
3+
4+
$chocoBaseDir = [System.Environment]::GetEnvironmentVariable('ChocolateyInstall')
5+
$addonDisable = "$chocoBaseDir\lib\blenderbim\tools\disable_blenderbim_addon.py"
6+
7+
$programFilesDir = [System.Environment]::GetEnvironmentVariable('ProgramFiles')
8+
$blenderExePath = "$env:ProgramFiles\Blender Foundation\Blender latest_blender_version_maj_min\blender.exe"
9+
10+
$processName = "blender"
11+
$blenderIsRunning = Get-Process -Name $processName -ErrorAction SilentlyContinue
12+
13+
if($blenderIsRunning -eq $null) {
14+
echo "attempting to uninstall blenderbim."
15+
Start-Process -FilePath $blenderExePath -ArgumentList "-b", "-y", "--python", "$addonDisable"
16+
Remove-Item -LiteralPath $unzippedDir -Force -Recurse
17+
}
18+
else {
19+
Write-Warning "$processName is still running - blenderbim cannot be safely uninstalled."
20+
Write-Warning "Please retry after closing all running blender applications."
21+
exit 1
22+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import bpy
2+
3+
4+
bpy.ops.preferences.addon_disable(module='blenderbim')
5+
bpy.ops.wm.save_userpref()
6+
7+
print("disabled blenderbim addon successfully.")
8+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import bpy
2+
3+
4+
bpy.ops.preferences.addon_enable(module='blenderbim')
5+
bpy.ops.wm.save_userpref()
6+
7+
print("enabled blenderbim addon successfully.")
8+

0 commit comments

Comments
 (0)