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