From a00e1b4f255f1968775103271842926837d6e957 Mon Sep 17 00:00:00 2001 From: Joseph Lee Date: Tue, 1 Dec 2020 20:56:33 -0800 Subject: [PATCH] WinVersion: introduce WinVersion class. Re #11837. Introduce winVersion.WinVersion class to serve as a hub of Windows version information for the system. The class (wrapped inside functools.total_ordering) will record version major, minor, build, and service pack information if present. It will also include a way to check for specific Windows 10 releases i.e. transplant winVersion.isWin10 function to winVersion.WinVersion.isWin10 method (later commit), as well as preparing for other checks such as Windows 10 X, Windows 10 on S mode, server, and others in the future. The class itself is wrapped inside functools.total_ordering decorator so that instnaces (Windows version data) can be compared easily. --- source/winVersion.py | 58 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/source/winVersion.py b/source/winVersion.py index 3067b4cee42..326b3416d77 100644 --- a/source/winVersion.py +++ b/source/winVersion.py @@ -5,6 +5,7 @@ import sys import os +import functools import winUser winVersion=sys.getwindowsversion() @@ -15,6 +16,63 @@ winVersionText+=".%d"%winVersion.service_pack_minor winVersionText+=" %s" % ("workstation","domain controller","server")[winVersion.product_type-1] +@functools.total_ordering +class WinVersion(object): + """ + Represents a Windows release. + Includes version major, minor, build, service pack information, + as well as tools such as checking for specific Windows 10 releases. + """ + + def __init__( + self, + release: str = None, + major: int = 0, + minor: int = 0, + build: int = 0, + servicePack: str = "" + ): + if release in (None, ""): + self.major = major + self.minor = minor + self.build = build + elif release == "7": + self.major = 6 + self.minor = 1 + self.build = 7601 + elif release == "8": + self.major = 6 + self.minor = 2 + self.build = 9200 + elif release == "8.1": + self.major = 6 + self.minor = 3 + self.build = 9600 + elif release in ("10", "1507"): + self.major = 10 + self.minor = 0 + self.build = 10240 + elif release in WIN10_VERSIONS_TO_BUILDS: + self.major = 10 + self.minor = 0 + self.build = WIN10_VERSIONS_TO_BUILDS[release] + else: + raise ValueError("Cannot create Windows version information for the specified release") + self.servicePack = "1" if release == "7" else "" + + def __eq__(self, other): + return ( + (self.major, self.minor, self.build) + == (other.major, other.minor, other.build) + ) + + def __ge__(self, other): + return ( + (self.major, self.minor, self.build) + >= (other.major, other.minor, other.build) + ) + + def isSupportedOS(): # NVDA can only run on Windows 7 Service pack 1 and above return (winVersion.major,winVersion.minor,winVersion.service_pack_major) >= (6,1,1)