Merge pull request #69 from hakril/improve_version_name

Improve `windows.system.version_name`
This commit is contained in:
hakril
2025-01-10 04:37:05 -08:00
committed by GitHub
2 changed files with 74 additions and 8 deletions
+1 -1
View File
@@ -13,6 +13,7 @@ class TestSystemWithCheckGarbage(object):
def test_version_name(self):
assert is_unicode(windows.system.version_name)
assert u"unknown" not in windows.system.version_name.lower()
def test_version_product_type(self):
assert windows.system.product_type
@@ -26,7 +27,6 @@ class TestSystemWithCheckGarbage(object):
def test_version_versionstr(self):
assert is_unicode(windows.system.windir)
def test_computer_name(self):
computer_name = windows.system.computer_name
assert computer_name
+73 -7
View File
@@ -260,12 +260,77 @@ class System(object):
result = tuple(result_tup[:2])
return result
# Based on:
# https://jrsoftware.org/ishelp/index.php?topic=winvernotes
# https://en.wikipedia.org/wiki/List_of_Microsoft_Windows_versions
WINDOWS_10_BUILD_NUMBER_VERSION = {
# (build_number, is_workstation): "version_name"
(10240, True): u"Windows 10 Version 1507",
(10586, True): u"Windows 10 Version 1511",
(14393, True): u"Windows 10 Version 1607",
(15063, True): u"Windows 10 Version 1703",
(16299, True): u"Windows 10 Version 1709",
(17134, True): u"Windows 10 Version 1803",
(17763, True): u"Windows 10 Version 1809",
(18362, True): u"Windows 10 Version 1903",
(18363, True): u"Windows 10 Version 1909",
(19041, True): u"Windows 10 Version 2004",
(19042, True): u"Windows 10 Version 20H2",
(19043, True): u"Windows 10 Version 21H1",
(19044, True): u"Windows 10 Version 21H2",
(19045, True): u"Windows 10 Version 22H2",
(22000, True): u"Windows 11 Version 21H2",
(22621, True): u"Windows 11 Version 22H2",
(22631, True): u"Windows 11 Version 23H2",
(26100, True): u"Windows 11 Version 24H2",
(14393, False): u"Windows Server 2016",
# 16299 : Windows Server, version 1709 ?
# 17134 : Windows Server, version 1803 ?
# 17134 : Windows Server, version 1803 ?
(17763, False): u"Windows Server 2019",
# 18362 : Windows Server, version 1903 ?
# 18363 : Windows Server, version 1909 ?
# 19041 : Windows Server, version 2004 ?
# 19042 : Windows Server, version 20H2 ?
(20348, False): u"Windows Server 2022",
# 25398 : Windows Server, version 23H2 ?
(26100, False): u"Windows Server 2025",
}
def _get_version_name_for_10_build(self, build_number, is_workstation):
try:
return self.WINDOWS_10_BUILD_NUMBER_VERSION[(build_number, is_workstation)]
except KeyError as e:
return u"Unknown Windows 10+ <versionstr={0} | is_workstation={1}>".format(self.versionstr, is_workstation)
@utils.fixedpropety
def version_name(self):
"""The name of the system version, values are:
* Windows Server 2025
* Windows 11 Version 24H2
* Windows 11 Version 23H2
* Windows 11 Version 22H2
* Windows 11 Version 21H2
* Windows 10 Version 22H2
* Windows 10 Version 21H2
* Windows Server 2022
* Windows 10 Version 21H1
* Windows 10 Version 20H2
* Windows 10 Version 2004
* Windows 10 Version 1909
* Windows 10 Version 1903
* Windows Server 2019
* Windows 10 Version 1809
* Windows 10 Version 1803
* Windows 10 Version 1709
* Windows 10 Version 1703
* Windows 10 Version 1607
* Windows 10 Version 1511
* Windows 10 Version 1507
* Windows Server 2016
* Windows 10
* Windows Server 2012 R2
* Windows 8.1
* Windows Server 2012
@@ -275,19 +340,20 @@ class System(object):
* Windows Server 2008
* Windows Vista
* Windows XP Professional x64 Edition
* TODO: version (5.2) + is_workstation + bitness == 32 (don't even know if possible..)
* Unknown: version (5.2) + is_workstation + bitness == 32 (don't even know if possible..)
* Windows Server 2003 R2
* Windows Server 2003
* Windows XP
* Windows 2000
* "Unknow Windows <version={0} | is_workstation={1}>".format(version, is_workstation)
* "Unknown Windows 10+ <versionstr={0} | is_workstation={1}>".format(self.versionstr, is_workstation)
* "Unknown Windows <version={0} | is_workstation={1}>".format(version, is_workstation)
:type: :class:`str`
:type: :class:`unicode`
"""
version = self.version
is_workstation = self.product_type == gdef.VER_NT_WORKSTATION
if version == (10, 0):
return [u"Windows Server 2016", u"Windows 10"][is_workstation]
return self._get_version_name_for_10_build(self.build_number, is_workstation)
elif version == (6, 3):
return [u"Windows Server 2012 R2", u"Windows 8.1"][is_workstation]
elif version == (6, 2):
@@ -302,7 +368,7 @@ class System(object):
if self.bitness == 64:
return u"Windows XP Professional x64 Edition"
else:
return u"TODO: version (5.2) + is_workstation + bitness == 32"
return u"Unknown: version (5.2) + is_workstation + bitness == 32"
elif metric != 0:
return u"Windows Server 2003 R2"
else:
@@ -312,7 +378,7 @@ class System(object):
elif version == (5, 0):
return u"Windows 2000"
else:
return u"Unknow Windows <version={0} | is_workstation={1}>".format(version, is_workstation)
return u"Unknown Windows <version={0} | is_workstation={1}>".format(version, is_workstation)
VERSION_MAPPER = gdef.FlagMapper(gdef.VER_NT_WORKSTATION, gdef.VER_NT_DOMAIN_CONTROLLER, gdef.VER_NT_SERVER)
@utils.fixedpropety