From d516fc712514330a1365869b4a749573c46a64a3 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Sun, 23 Jan 2022 02:50:13 +0100 Subject: [PATCH 1/2] bpo-45382: test.pythoninfo logs more Windows versions Add the following info to test.pythoninfo: * windows.ver: output of the shell "ver" command * windows.version and windows.version_caption: output of the "wmic os get Caption,Version /value" command. --- Lib/test/pythoninfo.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/Lib/test/pythoninfo.py b/Lib/test/pythoninfo.py index 9d733c5721cde8..4796982885b269 100644 --- a/Lib/test/pythoninfo.py +++ b/Lib/test/pythoninfo.py @@ -729,6 +729,42 @@ def collect_windows(info_add): except (ImportError, AttributeError): pass + import subprocess + try: + proc = subprocess.Popen(["wmic", "os", "get", "Caption,Version", "/value"], + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + text=True) + output, stderr = proc.communicate() + if proc.returncode: + output = "" + except OSError: + pass + else: + for line in output.splitlines(): + line = line.strip() + if line.startswith('Caption='): + line = line.removeprefix('Caption=') + info_add('windows.version_caption', line.strip()) + elif line.startswith('Version='): + line = line.removeprefix('Version=') + info_add('windows.version', line.strip()) + + try: + proc = subprocess.Popen(["ver"], shell=True, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + text=True) + output = proc.communicate()[0] + if proc.returncode: + output = "" + except OSError: + return + else: + output = output.strip() + line = output.splitlines()[0] + info_add('windows.ver', line) + def collect_fips(info_add): try: From 4de003ea7e44b9e70152caf44f7ca9886ad588a9 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Sun, 23 Jan 2022 03:39:19 +0100 Subject: [PATCH 2/2] Skip empty string --- Lib/test/pythoninfo.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Lib/test/pythoninfo.py b/Lib/test/pythoninfo.py index 4796982885b269..cfd7ac2755d519 100644 --- a/Lib/test/pythoninfo.py +++ b/Lib/test/pythoninfo.py @@ -744,11 +744,13 @@ def collect_windows(info_add): for line in output.splitlines(): line = line.strip() if line.startswith('Caption='): - line = line.removeprefix('Caption=') - info_add('windows.version_caption', line.strip()) + line = line.removeprefix('Caption=').strip() + if line: + info_add('windows.version_caption', line) elif line.startswith('Version='): - line = line.removeprefix('Version=') - info_add('windows.version', line.strip()) + line = line.removeprefix('Version=').strip() + if line: + info_add('windows.version', line) try: proc = subprocess.Popen(["ver"], shell=True, @@ -763,7 +765,8 @@ def collect_windows(info_add): else: output = output.strip() line = output.splitlines()[0] - info_add('windows.ver', line) + if line: + info_add('windows.ver', line) def collect_fips(info_add):