versioning
napt.versioning.compare
Core version comparison utilities for NAPT.
This module is format-agnostic: it does NOT download or read files. It only parses and compares version strings consistently across sources.
version_key
Computes a sortable comparison key for a version string.
Uses semver-like parsing with prerelease ordering; falls back to lexicographic comparison when no numeric prefix is found.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
version
|
str
|
Version string to convert. |
required |
Returns:
| Type | Description |
|---|---|
tuple
|
An opaque tuple suitable for use as a sort key. |
Note
Equal parsed keys (e.g., "v1.2.3" and "1.2.3") produce the same tuple, so the raw string is not included as a tiebreaker.
Source code in napt/versioning/compare.py
compare
Compares two version strings and returns their ordering.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
version_a
|
str
|
First version string. |
required |
version_b
|
str
|
Second version string. |
required |
Returns:
| Type | Description |
|---|---|
int
|
-1 if version_a is older than version_b, 0 if equal, 1 if newer. |
Source code in napt/versioning/compare.py
is_newer
Determines whether a remote version is newer than the current version.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
remote
|
str
|
Version string to check (e.g., from the download source). |
required |
current
|
str | None
|
Currently cached version string, or None if not yet downloaded. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if remote is newer than current. Always True when current is None. |
Source code in napt/versioning/compare.py
napt.versioning.msi
MSI metadata extraction for NAPT.
This module extracts metadata from Windows Installer (MSI) database files, including ProductVersion, ProductName, and architecture (from Template).
Backend Priority:
- Windows: PowerShell COM (Windows Installer COM API, always available)
- Linux/macOS: msiinfo (from the msitools package, must be installed separately)
Installation Requirements:
- Windows: No additional packages required (PowerShell is always available).
- Linux/macOS: Install the msitools package (
apt-get install msitools,dnf install msitools, orbrew install msitools).
Example
Extract metadata including architecture:
Note
This is pure file introspection; no network calls are made. The PowerShell COM backend reads both the Property table (ProductName, ProductVersion) and Summary Information stream (Template/architecture) in a single database open.
MSIMetadata
dataclass
Represents metadata extracted from an MSI file.
Attributes:
| Name | Type | Description |
|---|---|---|
product_name |
str
|
ProductName from MSI Property table (display name). |
product_version |
str
|
ProductVersion from MSI Property table. |
architecture |
Architecture
|
Installer architecture from MSI Template Summary Information property. Always one of "x86", "x64", or "arm64". |
Source code in napt/versioning/msi.py
extract_msi_metadata
Extracts ProductName, ProductVersion, and architecture from an MSI file.
Reads the MSI Property table (ProductName, ProductVersion) and Summary Information stream (Template/architecture) in a single database open. On Windows, uses the PowerShell COM API. On Linux/macOS, requires msitools.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
str | Path
|
Path to the MSI file. |
required |
Returns:
| Type | Description |
|---|---|
MSIMetadata
|
MSI metadata including product name, version, and architecture. |
Raises:
| Type | Description |
|---|---|
PackagingError
|
If the MSI file does not exist or extraction fails. |
ConfigError
|
If the MSI platform is not supported by Intune. |
NotImplementedError
|
If no extraction backend is available on this system. |
Example
Extract MSI metadata:
Note
ProductName may be empty string if not found in MSI. The build phase validates ProductName and raises ConfigError if empty — it is required for detection script generation.
Source code in napt/versioning/msi.py
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 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 | |