-
Notifications
You must be signed in to change notification settings - Fork 25
python: add installer option #46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ader1990
wants to merge
1
commit into
cloudbase:master
Choose a base branch
from
ader1990:python_download_installer
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,7 +10,8 @@ Param( | |
| [switch]$ClonePullInstallerRepo = $true, | ||
| [string]$InstallerDir = $null, | ||
| [string]$VSRedistDir = "${ENV:ProgramFiles(x86)}\Common Files\Merge Modules", | ||
| [string]$SignTimestampUrl = "http://timestamp.digicert.com?alg=sha256" | ||
| [string]$SignTimestampUrl = "http://timestamp.digicert.com?alg=sha256", | ||
| [string]$PythonMsiChecksum = $null | ||
| ) | ||
|
|
||
| $ErrorActionPreference = "Stop" | ||
|
|
@@ -76,6 +77,10 @@ try | |
|
|
||
| $python_template_dir = join-path $cloudbaseInitInstallerDir "Python$($pythonversion.replace('.', ''))_${platform}_Template" | ||
|
|
||
| if ($PythonMsiChecksum) { | ||
| DownloadInstall-PythonMsi $platform $python_template_dir $pythonversion $PythonMsiChecksum | ||
| } | ||
|
|
||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After the MSI build is done, the python_template_dir can be cleaned up as well. |
||
| CheckCopyDir $python_template_dir $python_dir | ||
|
|
||
| # Make sure that we don't have temp files from a previous build | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -387,8 +387,70 @@ function ImportCertificateUser($pfxPath, $pfxPassword) { | |
| } | ||
|
|
||
| function ChechFileHash($path, $hash, $algorithm="SHA1") { | ||
| $h = Get-Filehash -Algorithm $algorithm $path | ||
| if ($h.Hash.ToUpper() -ne $hash.ToUpper()) { | ||
| throw "Hash comparison failed for file: $path" | ||
| $actualHash = (Get-Filehash -Algorithm $algorithm $path).Hash.ToUpper() | ||
| if ($actualHash -ne $hash.ToUpper()) { | ||
| throw "Hash comparison failed for file: $path. Expected hash: ${hash}. Actual hash: ${actualHash}" | ||
| } | ||
| } | ||
|
|
||
|
|
||
| function DownloadInstall-PythonMsi($platform, $python_template_dir, $pythonVersion, $PythonMsiChecksum, $algorithm="SHA1") { | ||
| $platformSuffix = "" | ||
| if ($platform -eq "x64") { | ||
| $platformSuffix = "-amd64" | ||
| } | ||
|
|
||
| if (Test-Path $python_template_dir) { | ||
| throw "$python_template_dir folder already exists" | ||
| } | ||
|
|
||
| $pythonInstallerPath = Join-Path (Resolve-Path "${python_template_dir}/..").Path "/python-${pythonVersion}${platformSuffix}.exe" | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use parent path instead of .. |
||
| $pythonVersionEscaped = $pythonVersion.replace("_",".") | ||
| $PythonMsiUrl = "https://www.python.org/ftp/python/${pythonVersionEscaped}/python-${pythonVersionEscaped}${platformSuffix}.exe" | ||
|
|
||
| if ($python_template_dir -and (Test-Path $python_template_dir)) { | ||
| throw "Python template directory already exists" | ||
| } | ||
|
|
||
| $tmp_python_template_dir = "${python_template_dir}_tmp" | ||
| if ($tmp_python_template_dir -and (Test-Path $tmp_python_template_dir)) { | ||
| throw "Python temp template directory already exists" | ||
| } | ||
|
|
||
| try { | ||
| ExecRetry { DownloadFile $PythonMsiUrl $pythonInstallerPath } | ||
| ChechFileHash $pythonInstallerPath $PythonMsiChecksum $algorithm | ||
|
|
||
| Write-Host "Trying to uninstall Python using $pythonInstallerPath" | ||
| Start-Process -FilePath "${pythonInstallerPath}" -NoNewWindow -Wait ` | ||
| -ArgumentList @("/quiet", "/uninstall") | ||
|
|
||
| $package = Get-Package -Name "Python ${pythonVersionEscaped}*" -ErrorAction SilentlyContinue | ||
| if ($package) { | ||
| throw "Python package was already installed" | ||
| } | ||
|
|
||
| Write-Host "Installing Python using $pythonInstallerPath" | ||
| Start-Process -FilePath "${pythonInstallerPath}" -NoNewWindow -Wait ` | ||
| -ArgumentList @("/quiet", "TargetDir=${tmp_python_template_dir}","Include_test=0","Include_tcltk=0","Include_launcher=0","Include_doc=0") | ||
|
|
||
| Copy-Item -Recurse $tmp_python_template_dir $python_template_dir | ||
|
|
||
| } finally { | ||
|
|
||
| Start-Process -FilePath "${pythonInstallerPath}" -NoNewWindow -Wait ` | ||
| -ArgumentList @("/quiet", "/uninstall") | ||
|
|
||
| if (Test-Path $pythonInstallerPath) { | ||
| Remove-Item $pythonInstallerPath | ||
| } | ||
|
|
||
| if (Test-Path $tmp_python_template_dir) { | ||
| Remove-Item $tmp_python_template_dir -Recurse -Force | ||
| } | ||
| } | ||
| if (!(Test-Path $python_template_dir)) { | ||
| throw "$python_template_dir has not been created" | ||
| } | ||
|
|
||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it is worth adding a boolean flag?