Tries to figure out the OS version used and returns a tuple (system, release, version). It uses the "ver" shell command for this which is known to exists on Windows, DOS. XXX Others too ? In case this fails, the given parameters are used as defaults.
(system='', release='', version='',
supported_platforms=('win32', 'win16', 'dos'))
| 261 | # Windows versions. |
| 262 | |
| 263 | def _syscmd_ver(system='', release='', version='', |
| 264 | |
| 265 | supported_platforms=('win32', 'win16', 'dos')): |
| 266 | |
| 267 | """ Tries to figure out the OS version used and returns |
| 268 | a tuple (system, release, version). |
| 269 | |
| 270 | It uses the "ver" shell command for this which is known |
| 271 | to exists on Windows, DOS. XXX Others too ? |
| 272 | |
| 273 | In case this fails, the given parameters are used as |
| 274 | defaults. |
| 275 | |
| 276 | """ |
| 277 | if sys.platform not in supported_platforms: |
| 278 | return system, release, version |
| 279 | |
| 280 | # Try some common cmd strings |
| 281 | import subprocess |
| 282 | for cmd in ('ver', 'command /c ver', 'cmd /c ver'): |
| 283 | try: |
| 284 | info = subprocess.check_output(cmd, |
| 285 | stdin=subprocess.DEVNULL, |
| 286 | stderr=subprocess.DEVNULL, |
| 287 | text=True, |
| 288 | encoding="locale", |
| 289 | shell=True) |
| 290 | except (OSError, subprocess.CalledProcessError) as why: |
| 291 | #print('Command %s failed: %s' % (cmd, why)) |
| 292 | continue |
| 293 | else: |
| 294 | break |
| 295 | else: |
| 296 | return system, release, version |
| 297 | |
| 298 | # Parse the output |
| 299 | info = info.strip() |
| 300 | m = _ver_output.match(info) |
| 301 | if m is not None: |
| 302 | system, release, version = m.groups() |
| 303 | # Strip trailing dots from version and release |
| 304 | if release[-1] == '.': |
| 305 | release = release[:-1] |
| 306 | if version[-1] == '.': |
| 307 | version = version[:-1] |
| 308 | # Normalize the version and build strings (eliminating additional |
| 309 | # zeros) |
| 310 | version = _norm_version(version) |
| 311 | return system, release, version |
| 312 | |
| 313 | _WIN32_CLIENT_RELEASES = { |
| 314 | (5, 0): "2000", |
no test coverage detected