Skip to content

Commit

Permalink
finalize cleanup powershell scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
th3w1zard1 committed Feb 24, 2024
1 parent 97a3e87 commit 98eb477
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 91 deletions.
17 changes: 8 additions & 9 deletions compile/compile_batchpatcher.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@ $this_noprompt_arg = if ($this_noprompt) {'-noprompt'} else {''}
$venv_name_arg = if ($venv_name) {"-venv_name $venv_name"} else {''}
. $rootPath/install_python_venv.ps1 $this_noprompt_arg $venv_name_arg

Write-Host "Initializing python virtual environment..."
$this_noprompt_arg = if ($this_noprompt) {'-noprompt'} else {''}
$venv_name_arg = if ($venv_name) {"-venv_name $venv_name"} else {''}
. $rootPath/install_python_venv.ps1 $this_noprompt_arg $venv_name_arg

$current_working_dir = (Get-Location).Path
Set-Location -LiteralPath (Resolve-Path -LiteralPath "$rootPath/Tools/BatchPatcher/src").Path

Expand All @@ -40,21 +35,22 @@ if (Test-Path -Path $finalExecutablePath) {
Write-Host "Compiling BatchPatcher..."
$pyInstallerArgs = @{
'exclude-module' = @(
''
'dl_translate',
'torch'
'PyQt5'
'PyOpenGL'
'PyGLM'
'numpy'
'multiprocessing'
'pykotor-gl '
'pykotor-gl'
)
'clean' = $true
'console' = $true
'onefile' = $true
'noconfirm' = $true
'name' = 'K_BatchPatcher'
'distpath' = ($rootPath + $pathSep + 'dist')
'upx-dir' = "C:\GitHub\upx-win64"
}

$pyInstallerArgs = $pyInstallerArgs.GetEnumerator() | ForEach-Object {
Expand All @@ -63,8 +59,11 @@ $pyInstallerArgs = $pyInstallerArgs.GetEnumerator() | ForEach-Object {

if ($value -is [System.Array]) {
# Handle array values
$value -join "--$key="
$value = "--$key=$value"
$arr = @()
foreach ($elem in $value) {
$arr += "--$key=$elem"
}
$arr
} else {
# Handle key-value pair arguments
if ($value -eq $true) {
Expand Down
84 changes: 50 additions & 34 deletions compile/compile_gui_duplicator.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,33 @@ $this_noprompt_arg = if ($this_noprompt) {'-noprompt'} else {''}
$venv_name_arg = if ($venv_name) {"-venv_name $venv_name"} else {''}
. $rootPath/install_python_venv.ps1 $this_noprompt_arg $venv_name_arg

Write-Host "Installing required packages to build the holocron toolset..."
Write-Host "Installing required packages to build the gui duplicator..."
. $pythonExePath -m pip install --upgrade pip --prefer-binary --progress-bar on
. $pythonExePath -m pip install pyinstaller --prefer-binary --progress-bar on
. $pythonExePath -m pip install -r ($rootPath + $pathSep + "Libraries" + $pathSep + "PyKotor" + $pathSep + "requirements.txt") --prefer-binary --compile --progress-bar on -U

$current_working_dir = (Get-Location).Path
Set-Location -LiteralPath (Resolve-Path -LiteralPath "$rootPath/Tools/GuiDuplicator/src").Path

# Determine the final executable path
$finalExecutablePath = $null
if ((Get-OS) -eq "Windows") {
$finalExecutablePath = "$rootPath\dist\GuiDuplicator.exe"
} elseif ((Get-OS) -eq "Linux") {
$finalExecutablePath = "$rootPath/dist/GuiDuplicator"
} elseif ((Get-OS) -eq "Mac") {
$finalExecutablePath = "$rootPath/dist/GuiDuplicator.app"
}

# Delete the final executable if it exists
if (Test-Path -Path $finalExecutablePath) {
Remove-Item -Path $finalExecutablePath -Force
}

Write-Host "Compiling GuiDuplicator..."
Write-Host "EXTRA PYTHONPATH: '$env:PYTHONPATH'"
$pyInstallerArgs = @{
'exclude-module' = @(
'',
'numpy',
'PyQt5',
'PIL',
Expand Down Expand Up @@ -57,62 +75,60 @@ $pyInstallerArgs = @{
'install_playwright',
'greenlet',
'cssselect',
'beautifulsoup4 '
'beautifulsoup4'
)
'clean' = $true
'console' = $true
'onefile' = $true
'noconfirm' = $true
'name' = "GuiDuplicator"
'distpath'=($rootPath + $pathSep + "dist")
'upx-dir' = "C:\GitHub\upx-win32"
'distpath' = ($rootPath + $pathSep + 'dist')
'upx-dir' = "C:\GitHub\upx-win64"
}
$pyInstallerArgsString = ($pyInstallerArgs.GetEnumerator() | ForEach-Object {

$pyInstallerArgs = $pyInstallerArgs.GetEnumerator() | ForEach-Object {
$key = $_.Key
$value = $_.Value

if ($value -is [System.Array]) {
# Handle array values
$value -join " --$key="
$value = " --$key=$value "
$arr = @()
foreach ($elem in $value) {
$arr += "--$key=$elem"
}
$arr
} else {
# Handle key-value pair arguments
if ($value -eq $true) {
"--$key "
"--$key"
} elseif ($value -eq $false) {
} else {
"--$key=$value "
"--$key=$value"
}
}
}) -join ''

# Format PYTHONPATH paths and add them to the pyInstallerArgsString
$pythonPaths = $env:PYTHONPATH -split ';'
$pythonPathArgs = $pythonPaths | ForEach-Object { "--path=$_" }
$pythonPathArgsString = $pythonPathArgs -join ' '
}

# Determine the final executable path
$finalExecutablePath = $null
if ((Get-OS) -eq "Windows") {
$finalExecutablePath = "$rootPath\dist\GuiDuplicator.exe"
} elseif ((Get-OS) -eq "Linux") {
$finalExecutablePath = "$rootPath/dist/GuiDuplicator"
} elseif ((Get-OS) -eq "Mac") {
$finalExecutablePath = "$rootPath/dist/GuiDuplicator.app"
# Add PYTHONPATH paths as arguments
$env:PYTHONPATH -split ';' | ForEach-Object {
$pyInstallerArgs += "--path=$_"
}

# Delete the final executable if it exists
if (Test-Path -Path $finalExecutablePath) {
Remove-Item -Path $finalExecutablePath -Force
# Define each argument as an element in an array
$argumentsArray = @(
"-m",
"PyInstaller"
)
# Unpack $pyInstallerArgs into $argumentsArray
foreach ($arg in $pyInstallerArgs) {
$argumentsArray += $arg
}

# Combine pyInstallerArgsString with pythonPathArgsString
$finalPyInstallerArgsString = "$pythonPathArgsString $pyInstallerArgsString"
# Append the final script path
$argumentsArray += "__main__.py"

$current_working_dir = (Get-Location).Path
Set-Location -LiteralPath (Resolve-Path -LiteralPath "$rootPath/Tools/GuiDuplicator/src").Path
$command = "$pythonExePath -m PyInstaller $finalPyInstallerArgsString `"__main__.py`""
Write-Host $command
Invoke-Expression $command
# Use the call operator with the arguments array
Write-Host "Executing command: $pythonExePath $argumentsArray"
& $pythonExePath $argumentsArray

# Check if the final executable exists
if (-not (Test-Path -Path $finalExecutablePath)) {
Expand Down
10 changes: 6 additions & 4 deletions compile/compile_holopatcher.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ Write-Host "Compiling HoloPatcher..."
$iconExtension = if ((Get-OS) -eq 'Mac') {'icns'} else {'ico'}
$pyInstallerArgs = @{
'exclude-module' = @(
'',
'numpy',
'PyQt5',
'PIL',
Expand Down Expand Up @@ -72,7 +71,7 @@ $pyInstallerArgs = @{
'install_playwright',
'greenlet',
'cssselect',
'beautifulsoup4 '
'beautifulsoup4'
)
'clean' = $true
'noconsole' = $true
Expand All @@ -90,8 +89,11 @@ $pyInstallerArgs = $pyInstallerArgs.GetEnumerator() | ForEach-Object {

if ($value -is [System.Array]) {
# Handle array values
$value -join "--$key="
$value = "--$key=$value"
$arr = @()
foreach ($elem in $value) {
$arr += "--$key=$elem"
}
$arr
} else {
# Handle key-value pair arguments
if ($value -eq $true) {
Expand Down
96 changes: 56 additions & 40 deletions compile/compile_kotordiff.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,33 @@ $this_noprompt_arg = if ($this_noprompt) {'-noprompt'} else {''}
$venv_name_arg = if ($venv_name) {"-venv_name $venv_name"} else {''}
. $rootPath/install_python_venv.ps1 $this_noprompt_arg $venv_name_arg

Write-Host "Installing required packages to build kotordiff..."
Write-Host "Installing required packages to build the kotordiff tool..."
. $pythonExePath -m pip install --upgrade pip --prefer-binary --progress-bar on
. $pythonExePath -m pip install pyinstaller --prefer-binary --progress-bar on
. $pythonExePath -m pip install -r ($rootPath + $pathSep + "Tools" + $pathSep + "KotorDiff" + $pathSep + "requirements.txt") --prefer-binary --progress-bar on -U
. $pythonExePath -m pip install -r ($rootPath + $pathSep + "Tools" + $pathSep + "KotorDiff" + $pathSep + "recommended.txt") --prefer-binary --progress-bar on -U
. $pythonExePath -m pip install -r ($rootPath + $pathSep + "Libraries" + $pathSep + "PyKotor" + $pathSep + "requirements.txt") --prefer-binary --progress-bar on -U
. $pythonExePath -m pip install -r ($rootPath + $pathSep + "Libraries" + $pathSep + "PyKotor" + $pathSep + "requirements.txt") --prefer-binary --compile --progress-bar on -U

$current_working_dir = (Get-Location).Path
Set-Location -LiteralPath (Resolve-Path -LiteralPath "$rootPath/Tools/KotorDiff/src").Path

# Determine the final executable path
$finalExecutablePath = $null
if ((Get-OS) -eq "Windows") {
$finalExecutablePath = "$rootPath\dist\KotorDiff.exe"
} elseif ((Get-OS) -eq "Linux") {
$finalExecutablePath = "$rootPath/dist/KotorDiff"
} elseif ((Get-OS) -eq "Mac") {
$finalExecutablePath = "$rootPath/dist/KotorDiff.app"
}

# Delete the final executable if it exists
if (Test-Path -Path $finalExecutablePath) {
Remove-Item -Path $finalExecutablePath -Force
}

Write-Host "Compiling KotorDiff..."
Write-Host "EXTRA PYTHONPATH: '$env:PYTHONPATH'"
$pyInstallerArgs = @{
'exclude-module' = @(
'',
'numpy',
'PyQt5',
'PIL',
Expand All @@ -49,70 +65,70 @@ $pyInstallerArgs = @{
'ruff',
'pylint',
'pykotor.gl',
'pykotorgl',
'pykotor.font',
'pykotorfont'
'pykotor.secure_xml',
'mypy-extensions',
'mypy',
'isort',
'install_playwright',
'greenlet',
'cssselect',
'beautifulsoup4 '
'beautifulsoup4'
)
'clean' = $true
'noconsole' = $true
'console' = $true
'onefile' = $true
'noconfirm' = $true
'distpath' = ($rootPath + $pathSep + "dist")
'name' = 'KotorDiff'
'upx-dir' = "$env:USERPROFILE\Documents\GitHub\upx-win32"
'name' = "KotorDiff"
'distpath' = ($rootPath + $pathSep + 'dist')
'upx-dir' = "C:\GitHub\upx-win64"
}
$pyInstallerArgsString = ($pyInstallerArgs.GetEnumerator() | ForEach-Object {

$pyInstallerArgs = $pyInstallerArgs.GetEnumerator() | ForEach-Object {
$key = $_.Key
$value = $_.Value

if ($value -is [System.Array]) {
# Handle array values
$value -join " --$key="
$value = " --$key=$value "
$arr = @()
foreach ($elem in $value) {
$arr += "--$key=$elem"
}
$arr
} else {
# Handle key-value pair arguments
if ($value -eq $true) {
"--$key "
"--$key"
} elseif ($value -eq $false) {
} else {
"--$key=$value "
"--$key=$value"
}
}
}) -join ''

# Format PYTHONPATH paths and add them to the pyInstallerArgsString
$pythonPaths = $env:PYTHONPATH -split ';'
$pythonPathArgs = $pythonPaths | ForEach-Object { "--path=$_" }
$pythonPathArgsString = $pythonPathArgs -join ' '
}

# Determine the final executable path
$finalExecutablePath = $null
if ((Get-OS) -eq "Windows") {
$finalExecutablePath = "$rootPath\dist\KotorDiff.exe"
} elseif ((Get-OS) -eq "Linux") {
$finalExecutablePath = "$rootPath/dist/KotorDiff"
} elseif ((Get-OS) -eq "Mac") {
$finalExecutablePath = "$rootPath/dist/KotorDiff.app"
# Add PYTHONPATH paths as arguments
$env:PYTHONPATH -split ';' | ForEach-Object {
$pyInstallerArgs += "--path=$_"
}

# Delete the final executable if it exists
if (Test-Path -Path $finalExecutablePath) {
Remove-Item -Path $finalExecutablePath -Recurse -Force
# Define each argument as an element in an array
$argumentsArray = @(
"-m",
"PyInstaller"
)
# Unpack $pyInstallerArgs into $argumentsArray
foreach ($arg in $pyInstallerArgs) {
$argumentsArray += $arg
}

# Combine pyInstallerArgsString with pythonPathArgsString
$finalPyInstallerArgsString = "$pythonPathArgsString $pyInstallerArgsString"
# Append the final script path
$argumentsArray += "__main__.py"

$current_working_dir = (Get-Location).Path
Set-Location -LiteralPath (Resolve-Path -LiteralPath "$rootPath/Tools/KotorDiff/src").Path
$command = "$pythonExePath -m PyInstaller $finalPyInstallerArgsString `"__main__.py`""
Write-Host $command
Invoke-Expression $command
# Use the call operator with the arguments array
Write-Host "Executing command: $pythonExePath $argumentsArray"
& $pythonExePath $argumentsArray

# Check if the final executable exists
if (-not (Test-Path -Path $finalExecutablePath)) {
Expand All @@ -125,4 +141,4 @@ Set-Location -LiteralPath $current_working_dir
if (-not $this_noprompt) {
Write-Host "Press any key to exit..."
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
}
}
10 changes: 6 additions & 4 deletions compile/compile_toolset.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@ Write-Host "Extra PYTHONPATH paths:\n'$env:PYTHONPATH'\n\n"
$iconExtension = if ((Get-OS) -eq 'Mac') {'icns'} else {'ico'}
$pyInstallerArgs = @{
'exclude-module' = @(
'',
'dl_translate',
'torch '
'torch'
)
'clean' = $true
'console' = $true
Expand All @@ -56,8 +55,11 @@ $pyInstallerArgs = $pyInstallerArgs.GetEnumerator() | ForEach-Object {

if ($value -is [System.Array]) {
# Handle array values
$value -join "--$key="
$value = "--$key=$value"
$arr = @()
foreach ($elem in $value) {
$arr += "--$key=$elem"
}
$arr
} else {
# Handle key-value pair arguments
if ($value -eq $true) {
Expand Down

0 comments on commit 98eb477

Please sign in to comment.