Gate Windows Utils

This commit is contained in:
twangboy 2016-12-27 16:56:09 -07:00
parent 7c7799162b
commit c20111142f
4 changed files with 54 additions and 19 deletions

View file

@ -22,12 +22,12 @@ except ImportError:
HAS_WIN32 = False
# Although utils are often directly imported, it is also possible to use the
# loader.
def __virtual__():
'''
Load only on Windows with necessary modules
Only load if Win32 Libraries are installed
'''
if not salt.utils.is_windows():
return False, 'This utility only works on Windows'
if not HAS_WIN32:
return False, 'This utility requires pywin32'

View file

@ -1,14 +1,32 @@
# -*- coding: utf-8 -*-
'''
Get Versioning information from Windows
Get Version information from Windows
'''
# http://stackoverflow.com/questions/32300004/python-ctypes-getting-0-with-getversionex-function
from __future__ import absolute_import
# Import Third Party Libs
import ctypes
from ctypes.wintypes import BYTE, WORD, DWORD, WCHAR
try:
from ctypes.wintypes import BYTE, WORD, DWORD, WCHAR
HAS_WIN32 = True
except (ImportError, ValueError):
HAS_WIN32 = False
kernel32 = ctypes.WinDLL('kernel32', use_last_error=True)
if HAS_WIN32:
kernel32 = ctypes.WinDLL('kernel32', use_last_error=True)
# Although utils are often directly imported, it is also possible to use the
# loader.
def __virtual__():
'''
Only load if Win32 Libraries are installed
'''
if not HAS_WIN32:
return False, 'This utility requires pywin32'
return 'win_osinfo'
class OSVERSIONINFO(ctypes.Structure):
@ -38,8 +56,9 @@ def errcheck_bool(result, func, args):
raise ctypes.WinError(ctypes.get_last_error())
return args
kernel32.GetVersionExW.errcheck = errcheck_bool
kernel32.GetVersionExW.argtypes = (ctypes.POINTER(OSVERSIONINFO),)
if HAS_WIN32:
kernel32.GetVersionExW.errcheck = errcheck_bool
kernel32.GetVersionExW.argtypes = (ctypes.POINTER(OSVERSIONINFO),)
def get_os_version_info():

View file

@ -27,20 +27,20 @@ try:
except ImportError:
HAS_WIN32 = False
# Import Salt Libs
import salt.utils
# Set up logging
log = logging.getLogger(__name__)
# Although utils are often directly imported, it is also possible to use the
# loader.
def __virtual__():
'''
Load only on Windows
Only load if Win32 Libraries are installed
'''
if salt.utils.is_windows() and HAS_WIN32:
return 'win_runas'
return False
if not HAS_WIN32:
return False, 'This utility requires pywin32'
return 'win_runas'
if HAS_WIN32:

View file

@ -8,10 +8,26 @@ from os.path import splitext, abspath
from sys import modules
# Import third party libs
import win32serviceutil
import win32service
import win32event
import win32api
try:
import win32serviceutil
import win32service
import win32event
import win32api
HAS_WIN32 = True
except ImportError:
HAS_WIN32 = False
# Although utils are often directly imported, it is also possible to use the
# loader.
def __virtual__():
'''
Only load if Win32 Libraries are installed
'''
if not HAS_WIN32:
return False, 'This utility requires pywin32'
return 'winservice'
class Service(win32serviceutil.ServiceFramework):