def os_id_index():
"""Get the index of the machine OS in the `OS_ID` tuple.
The `OS_ID` tuple contains the major and minor version of all
affected Windows versions. These are matched against
the major and minor version of `sys.getwindowsversion()`.
For Windows 8.1 and above `sys.getwindowsversion()` doesn't
report the correct value, these systems are handled specially.
Windows 8 and Server 2012 are special cased because the have the
same version numbers but require different KBs.
:return: The index of the operating system in `OS_ID`.
:rtype: int
"""
winver = sys.getwindowsversion()
# sys.getwindowsversion is not enough by itself as the underlying
# API has been deprecated. Only applications which have been
# developed specifically for Windows 8.1 and above, and write that
# into their manifest file get the correct Windows version on those
# systems. Other applications (Python doesn't have the manifest)
# get a version that pretends to be Windows 8 (major=6, minor=2).
# See:
# https://msdn.microsoft.com/en-us/library/windows/desktop/ms724834.aspx
major, minor = winver.major, winver.minor
if (major, minor) == (6, 2):
# Determine if this system is a newer version than Windows 8 by
# parsing the version string in `platform.win32_ver()[1]`:
major, minor = tuple(map(int, platform.win32_ver()[1].split('.')[:2]))
for i, os_id in enumerate(OS_ID):
if os_id[:2] == (major, minor):
if len(os_id) == 2:
return i
# else evaluate the third item if present which is a lambda:
if os_id[2]():
return i
# otherwise continue with the next item
评论列表
文章目录