]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.10] bpo-45382: test.pythoninfo logs more Windows versions (GH-30891) (GH-30894)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Wed, 16 Mar 2022 10:13:55 +0000 (03:13 -0700)
committerGitHub <noreply@github.com>
Wed, 16 Mar 2022 10:13:55 +0000 (11:13 +0100)
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 b0898f4aa90d9397e23aef98a2d6b82445ee7455)

* bpo-45382: test.pythoninfo: set wmic.exe encoding to OEM (GH-30890)

(cherry picked from commit cef0a5458f254c2f8536b928dee25862ca90ffa6)
(cherry picked from commit 4a57fa296b92125e41220ecd201eb2e432b79fb0)

Co-authored-by: Victor Stinner <vstinner@python.org>
Lib/test/pythoninfo.py

index cc228fb3b54c9449fcb0a86b8ae12b882d68d09e..fd1b49ecc8af4f374612afb8fe5a1a14eeaff4f3 100644 (file)
@@ -719,6 +719,48 @@ def collect_windows(info_add):
     except (ImportError, AttributeError):
         pass
 
+    import subprocess
+    try:
+        # When wmic.exe output is redirected to a pipe,
+        # it uses the OEM code page
+        proc = subprocess.Popen(["wmic", "os", "get", "Caption,Version", "/value"],
+                                stdout=subprocess.PIPE,
+                                stderr=subprocess.PIPE,
+                                encoding="oem",
+                                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=').strip()
+                if line:
+                    info_add('windows.version_caption', line)
+            elif line.startswith('Version='):
+                line = line.removeprefix('Version=').strip()
+                if line:
+                    info_add('windows.version', line)
+
+    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]
+        if line:
+            info_add('windows.ver', line)
+
 
 def collect_fips(info_add):
     try: