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