Skip to content

Commit

Permalink
winVersion.WinVersion: add repr method. Re nvaccess#11837.
Browse files Browse the repository at this point in the history
Add repr method to be used to print Windows version information to the console and to announce it at startup (future commit). It uses a helper function to obtain release name, then adds version string, service pack (if any), and product type. In essence, the work of old winVersionText was transfered to repr.
  • Loading branch information
josephsl committed Dec 12, 2020
1 parent a1dd33d commit 79db425
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions source/winVersion.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,33 @@ def __init__(
self.servicePack = servicePack
self.productType = productType

def _windowsVersionToReleaseName(self):
"""Returns release names for a given Windows version.
For example, 6.1 will return 'Windows 7'.
For Windows 10, feature update release name will be included.
On server systems, client release names will be returned.
For example, 'Windows 10 1809' will be returned on Server 2019 systems.
"""
if (self.major, self.minor) == (6, 1):
return "Windows 7"
elif (self.major, self.minor) == (6, 2):
return "Windows 8"
elif (self.major, self.minor) == (6, 3):
return "Windows 8.1"
elif self.major == 10:
buildsToReleases = {build: release for release, build in WIN10_RELEASE_NAME_TO_BUILDS.items()}
return f"Windows 10 {buildsToReleases[self.build]}"
else:
raise RuntimeError("Unknown Windows release")

def __repr__(self):
winVersionText = [self._windowsVersionToReleaseName()]
winVersionText.append(f"{self.major}.{self.minor}.{self.build}")
if self.servicePack != "":
winVersionText.append(f"service pack {self.servicePack}")
winVersionText.append(self.productType)
return " ".join(winVersionText)

def __eq__(self, other):
return (
(self.major, self.minor, self.build)
Expand Down

0 comments on commit 79db425

Please sign in to comment.