psadt
napt.psadt.release
PSADT release management for NAPT.
This module handles fetching, downloading, and caching PSAppDeployToolkit releases from the official GitHub repository. It reuses NAPT's existing GitHub release discovery infrastructure for consistency.
Key Features:
- Fetch latest PSADT version from GitHub API
- Download and cache specific PSADT versions
- Extract releases to cache directory
- Version resolution ("latest" keyword support)
Example
Get and cache PSADT releases:
from pathlib import Path
from napt.psadt import get_psadt_release, is_psadt_cached
# Get latest PSADT
psadt_dir = get_psadt_release("latest", Path("cache/psadt"))
# Get specific version
psadt_dir = get_psadt_release("4.1.7", Path("cache/psadt"))
# Check if cached
if is_psadt_cached("4.1.7", Path("cache/psadt")):
print("Already cached!")
Note
- Reuses notapkgtool.discovery.api_github for API calls
- Caches releases by version: cache/psadt/{version}/
- Downloads .zip releases and extracts to cache
- Validates extracted PSADT structure (PSAppDeployToolkit/ folder exists)
fetch_latest_psadt_version
Fetch the latest PSADT release version from GitHub.
Queries the GitHub API for the latest release and extracts the version number from the tag name (e.g., "4.1.7" from tag "4.1.7").
Returns:
| Type | Description |
|---|---|
str
|
Version number (e.g., "4.1.7"). |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If the GitHub API request fails or version cannot be extracted. |
Example
Get latest PSADT version from GitHub:
Note
- Uses GitHub's public API (60 requests/hour limit without auth)
- Version is extracted from release tag name
- For higher rate limits, set GITHUB_TOKEN environment variable
Source code in napt/psadt/release.py
is_psadt_cached
Check if a PSADT version is already cached.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
version
|
str
|
PSADT version to check (e.g., "4.1.7"). |
required |
cache_dir
|
Path
|
Base cache directory (e.g., Path("cache/psadt")). |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the version is cached and valid, False otherwise. |
Example
Check if PSADT version is cached:
Note
Validates that the cache contains the expected PSADT structure:
- PSAppDeployToolkit/ folder must exist
- PSAppDeployToolkit.psd1 manifest must exist
Source code in napt/psadt/release.py
get_psadt_release
Download and extract a PSADT release to the cache directory.
Resolves "latest" to the current latest version from GitHub, then downloads the release .zip file and extracts it to the cache.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
release_spec
|
str
|
Version specifier - either "latest" or specific version (e.g., "4.1.7"). |
required |
cache_dir
|
Path
|
Base cache directory for PSADT releases. |
required |
Returns:
| Type | Description |
|---|---|
Path
|
Path to the cached PSADT directory (cache_dir/{version}). |
Raises:
| Type | Description |
|---|---|
NetworkError
|
If download fails. |
PackagingError
|
If extraction fails. |
ConfigError
|
If release_spec is invalid. |
Example
Get latest version:
from pathlib import Path
psadt = get_psadt_release("latest", Path("cache/psadt"))
print(psadt) # Output: cache/psadt/4.1.7
Get specific version:
Note
- Caches by version: cache/psadt/{version}/PSAppDeployToolkit/
- If already cached, returns path immediately (no re-download)
- Downloads from GitHub releases as .zip files
- Extracts entire archive to version directory
Source code in napt/psadt/release.py
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 | |