File: //var/opt/nydus/ops/customer_local_ops/operating_system/powershell/get_system_info.ps1
function Get-OSInfo {
$os = Get-CimInstance -ClassName Win32_OperatingSystem
return @{
name = ($os.Caption -replace '^Microsoft ', '').Trim()
version = $os.Version
}
}
function Get-PythonVersions {
$found = @{}
$versions = @()
$default = "None"
$validNames = @("python.exe")
$baseDirs = @(
"C:\",
"C:\Program Files",
"C:\Program Files (x86)"
)
$searchDirs = @()
foreach ($base in $baseDirs) {
if (Test-Path $base) {
try {
$searchDirs += Get-ChildItem -Path $base -Directory -Filter "Python*" -ErrorAction SilentlyContinue | Select-Object -ExpandProperty FullName
} catch {}
}
}
$searchDirs += ($env:PATH).Split(';') | Where-Object { $_ -and (Test-Path $_) }
$searchDirs = $searchDirs | Sort-Object -Unique
foreach ($dir in $searchDirs) {
try {
Get-ChildItem -Path $dir -Filter "python.exe" -ErrorAction SilentlyContinue | ForEach-Object {
$exe = $_.FullName
$name = $_.Name
if (-not $found.ContainsKey($exe) -and $validNames -contains $name) {
try {
$output = & $exe --version 2>&1
$ver = $output -replace '.*?([\d\.]+)$', '$1'
if ($ver) {
$versions += @{ name = $name; version = $ver }
$found[$exe] = $true
if ($name -eq "python.exe" -and $default -eq "None") {
$default = $ver
}
}
} catch {}
}
}
} catch {}
}
return ,@($versions, $default)
}
function Get-NydusVersion {
$nydusMetadataPath = "C:\nydus\pyvenv\Lib\site-packages"
try {
$metadataDir = Get-ChildItem -Path $nydusMetadataPath -Directory -Filter "nydus-*.dist-info" -ErrorAction Stop | Select-Object -First 1
$metadataFile = Join-Path $metadataDir.FullName "METADATA"
if (Test-Path $metadataFile) {
$lines = Get-Content $metadataFile
foreach ($line in $lines) {
if ($line -like "Version:*") {
return $line -replace "^Version:\s*", ""
}
}
}
return "Version not found in METADATA"
} catch {
return "Nydus not installed"
}
}
function Get-SystemInfo {
$osInfo = Get-OSInfo
$pyResult = Get-PythonVersions
$pythonVersions = $pyResult[0]
$defaultPython = $pyResult[1]
$nydusVersion = Get-NydusVersion
$output = @{
os_info = $osInfo
python_versions = if ($pythonVersions) { $pythonVersions } else { @() }
default_python_version = $defaultPython
nydus_packages = $nydusVersion
}
return $output | ConvertTo-Json -Depth 3 -Compress
}
Get-SystemInfo