Skip to content

Commit 4a57fa2

Browse files
authored
[3.10] bpo-45382: test.pythoninfo logs more Windows versions (GH-30891)
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. (cherry picked from commit b0898f4) * bpo-45382: test.pythoninfo: set wmic.exe encoding to OEM (GH-30890) (cherry picked from commit cef0a54)
1 parent 75d88b9 commit 4a57fa2

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

Lib/test/pythoninfo.py

+42
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,48 @@ def collect_windows(info_add):
720720
except (ImportError, AttributeError):
721721
pass
722722

723+
import subprocess
724+
try:
725+
# When wmic.exe output is redirected to a pipe,
726+
# it uses the OEM code page
727+
proc = subprocess.Popen(["wmic", "os", "get", "Caption,Version", "/value"],
728+
stdout=subprocess.PIPE,
729+
stderr=subprocess.PIPE,
730+
encoding="oem",
731+
text=True)
732+
output, stderr = proc.communicate()
733+
if proc.returncode:
734+
output = ""
735+
except OSError:
736+
pass
737+
else:
738+
for line in output.splitlines():
739+
line = line.strip()
740+
if line.startswith('Caption='):
741+
line = line.removeprefix('Caption=').strip()
742+
if line:
743+
info_add('windows.version_caption', line)
744+
elif line.startswith('Version='):
745+
line = line.removeprefix('Version=').strip()
746+
if line:
747+
info_add('windows.version', line)
748+
749+
try:
750+
proc = subprocess.Popen(["ver"], shell=True,
751+
stdout=subprocess.PIPE,
752+
stderr=subprocess.PIPE,
753+
text=True)
754+
output = proc.communicate()[0]
755+
if proc.returncode:
756+
output = ""
757+
except OSError:
758+
return
759+
else:
760+
output = output.strip()
761+
line = output.splitlines()[0]
762+
if line:
763+
info_add('windows.ver', line)
764+
723765

724766
def collect_fips(info_add):
725767
try:

0 commit comments

Comments
 (0)