Functions/InstallerUtilities.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
. "$PSScriptRoot\Get-PythonInstallerUrl.ps1"

function Get-PythonInstaller([string]$FullVersion) {
    # Returns the path to the installer for that version, downloading it if it isn't already cached.
$Null = @(
    $installerCache = Get-PythonInstallerCache
    $installerName = "python$($FullVersion)-Installer.exe"
    $installerEXEPath = "$installerCache\$installerName"
    if (!(Test-Path -Path $installerEXEPath)){
        $installerUrl = Get-PythonInstallerUrl -Version $FullVersion
        Write-Host "Downloading Python $FullVersion Installer..."
        [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
        $wc = New-Object System.Net.WebClient
        $wc.DownloadFile($installerUrl, $installerEXEPath)
    }
)
    return $installerEXEPath
}


function Remove-PythonInstaller([string]$FullVersion) {
$Null = @(
    $installerCache = Get-PythonInstallerCache
    $installerName = "python$($FullVersion)-Installer.exe"
    $installerEXEPath = "$installerCache\$installerName"
    if (Test-Path -Path $installerEXEPath){
        Remove-Item -Path $installerEXEPath -Force
    }
    else {
        Write-Warning "Could not find an installer for python version $FullVersion."
    }
)
}