Skip to content

Commit

Permalink
WinVersion: introduce WinVersion class. Re nvaccess#11837.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
josephsl committed Dec 2, 2020
1 parent 120d7d4 commit a00e1b4
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions source/winVersion.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import sys
import os
import functools
import winUser

winVersion=sys.getwindowsversion()
Expand All @@ -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)
Expand Down

0 comments on commit a00e1b4

Please sign in to comment.