@@ -497,57 +497,61 @@ def _syscmd_ver(system='', release='', version='',
497
497
(6 , None ): "post2012ServerR2" ,
498
498
}
499
499
500
- def _get_real_winver (maj , min , build ):
501
- if maj < 6 or (maj == 6 and min < 2 ):
502
- return maj , min , build
503
-
504
- from ctypes import (c_buffer , POINTER , byref , create_unicode_buffer ,
505
- Structure , WinDLL )
506
- from ctypes .wintypes import DWORD , HANDLE
500
+ if sys .platform == 'win32' :
501
+ import ctypes
502
+ import ctypes .wintypes
507
503
508
- class VS_FIXEDFILEINFO (Structure ):
504
+ class VS_FIXEDFILEINFO (ctypes . Structure ):
509
505
_fields_ = [
510
- ("dwSignature" , DWORD ),
511
- ("dwStrucVersion" , DWORD ),
512
- ("dwFileVersionMS" , DWORD ),
513
- ("dwFileVersionLS" , DWORD ),
514
- ("dwProductVersionMS" , DWORD ),
515
- ("dwProductVersionLS" , DWORD ),
516
- ("dwFileFlagsMask" , DWORD ),
517
- ("dwFileFlags" , DWORD ),
518
- ("dwFileOS" , DWORD ),
519
- ("dwFileType" , DWORD ),
520
- ("dwFileSubtype" , DWORD ),
521
- ("dwFileDateMS" , DWORD ),
522
- ("dwFileDateLS" , DWORD ),
506
+ ("dwSignature" , ctypes . wintypes . DWORD ),
507
+ ("dwStrucVersion" , ctypes . wintypes . DWORD ),
508
+ ("dwFileVersionMS" , ctypes . wintypes . DWORD ),
509
+ ("dwFileVersionLS" , ctypes . wintypes . DWORD ),
510
+ ("dwProductVersionMS" , ctypes . wintypes . DWORD ),
511
+ ("dwProductVersionLS" , ctypes . wintypes . DWORD ),
512
+ ("dwFileFlagsMask" , ctypes . wintypes . DWORD ),
513
+ ("dwFileFlags" , ctypes . wintypes . DWORD ),
514
+ ("dwFileOS" , ctypes . wintypes . DWORD ),
515
+ ("dwFileType" , ctypes . wintypes . DWORD ),
516
+ ("dwFileSubtype" , ctypes . wintypes . DWORD ),
517
+ ("dwFileDateMS" , ctypes . wintypes . DWORD ),
518
+ ("dwFileDateLS" , ctypes . wintypes . DWORD ),
523
519
]
524
520
525
- kernel32 = WinDLL ('kernel32' )
526
- version = WinDLL ('version' )
521
+ P_VS_FIXEDFILEINFO = ctypes .POINTER (VS_FIXEDFILEINFO )
522
+
523
+ def _get_real_winver (maj , min , build ):
524
+ if maj < 6 or (maj == 6 and min < 2 ):
525
+ return maj , min , build
527
526
527
+ kernel32 = ctypes .WinDLL ('kernel32' )
528
528
# We will immediately double the length up to MAX_PATH, but the
529
529
# path may be longer, so we retry until the returned string is
530
530
# shorter than our buffer.
531
531
name_len = actual_len = 130
532
532
while actual_len == name_len :
533
533
name_len *= 2
534
- name = create_unicode_buffer (name_len )
535
- actual_len = kernel32 .GetModuleFileNameW (HANDLE (kernel32 ._handle ),
536
- name , len (name ))
534
+ name = ctypes .create_unicode_buffer (name_len )
535
+ actual_len = kernel32 .GetModuleFileNameW (
536
+ ctypes .wintypes .HANDLE (kernel32 ._handle ),
537
+ name , len (name )
538
+ )
537
539
if not actual_len :
538
540
return maj , min , build
539
541
542
+ version = ctypes .WinDLL ('version' )
540
543
size = version .GetFileVersionInfoSizeW (name , None )
541
544
if not size :
542
545
return maj , min , build
543
546
544
- ver_block = c_buffer (size )
547
+ ver_block = ctypes . c_buffer (size )
545
548
if (not version .GetFileVersionInfoW (name , None , size , ver_block ) or
546
549
not ver_block ):
547
550
return maj , min , build
548
551
549
- pvi = POINTER (VS_FIXEDFILEINFO )()
550
- if not version .VerQueryValueW (ver_block , "" , byref (pvi ), byref (DWORD ())):
552
+ pvi = P_VS_FIXEDFILEINFO ()
553
+ if not version .VerQueryValueW (ver_block , "" ,
554
+ ctypes .byref (pvi ), ctypes .byref (ctypes .wintypes .DWORD ())):
551
555
return maj , min , build
552
556
553
557
maj = pvi .contents .dwProductVersionMS >> 16
0 commit comments