def win_create_mdb(mdb_path, sort_order = "General\0\0"):
if sys.platform not in ('win32','cli'):
raise Exception('This function is available for use in Windows only.')
mdb_driver = [d for d in drivers() if 'Microsoft Access Driver (*.mdb' in d]
if mdb_driver == []:
raise Exception('Access Driver is not found.')
else:
driver_name = mdb_driver[0].encode('mbcs')
#CREATE_DB=<path name> <sort order>
ctypes.windll.ODBCCP32.SQLConfigDataSource.argtypes = [ctypes.c_void_p,ctypes.c_ushort,ctypes.c_char_p,ctypes.c_char_p]
if py_v3:
c_Path = bytes("CREATE_DB=" + mdb_path + " " + sort_order,'mbcs')
else:
c_Path = "CREATE_DB=" + mdb_path + " " + sort_order
ODBC_ADD_SYS_DSN = 1
ret = ctypes.windll.ODBCCP32.SQLConfigDataSource(None,ODBC_ADD_SYS_DSN,driver_name, c_Path)
if not ret:
raise Exception('Failed to create Access mdb file - "%s". Please check file path, permission and Access driver readiness.' %mdb_path)
python类c_ushort()的实例源码
def win_compact_mdb(mdb_path, compacted_mdb_path, sort_order = "General\0\0"):
if sys.platform not in ('win32','cli'):
raise Exception('This function is available for use in Windows only.')
mdb_driver = [d for d in drivers() if 'Microsoft Access Driver (*.mdb' in d]
if mdb_driver == []:
raise Exception('Access Driver is not found.')
else:
driver_name = mdb_driver[0].encode('mbcs')
#COMPACT_DB=<source path> <destination path> <sort order>
ctypes.windll.ODBCCP32.SQLConfigDataSource.argtypes = [ctypes.c_void_p,ctypes.c_ushort,ctypes.c_char_p,ctypes.c_char_p]
#driver_name = "Microsoft Access Driver (*.mdb)"
if py_v3:
c_Path = bytes("COMPACT_DB=" + mdb_path + " " + compacted_mdb_path + " " + sort_order,'mbcs')
#driver_name = bytes(driver_name,'mbcs')
else:
c_Path = "COMPACT_DB=" + mdb_path + " " + compacted_mdb_path + " " + sort_order
ODBC_ADD_SYS_DSN = 1
ret = ctypes.windll.ODBCCP32.SQLConfigDataSource(None,ODBC_ADD_SYS_DSN,driver_name, c_Path)
if not ret:
raise Exception('Failed to compact Access mdb file - "%s". Please check file path, permission and Access driver readiness.' %compacted_mdb_path)
def wrap(self, gammaramp):
'''
Wraps a nested python sequence.
'''
red, green, blue = gammaramp
size = min(len(red), len(green), len(blue))
array_type = ctypes.c_ushort*size
self.size = ctypes.c_uint(size)
self.red_array = array_type()
self.green_array = array_type()
self.blue_array = array_type()
for i in range(self.size):
self.red_array[i] = int(red[i]*65535)
self.green_array[i] = int(green[i]*65535)
self.blue_array[i] = int(blue[i]*65535)
pointer_type = ctypes.POINTER(ctypes.c_ushort)
self.red = ctypes.cast(self.red_array, pointer_type)
self.green = ctypes.cast(self.green_array, pointer_type)
self.blue = ctypes.cast(self.blue_array, pointer_type)
def win32_version():
import ctypes
class OSVERSIONINFOEXW(ctypes.Structure):
_fields_ = [('dwOSVersionInfoSize', ctypes.c_ulong),
('dwMajorVersion', ctypes.c_ulong),
('dwMinorVersion', ctypes.c_ulong),
('dwBuildNumber', ctypes.c_ulong),
('dwPlatformId', ctypes.c_ulong),
('szCSDVersion', ctypes.c_wchar*128),
('wServicePackMajor', ctypes.c_ushort),
('wServicePackMinor', ctypes.c_ushort),
('wSuiteMask', ctypes.c_ushort),
('wProductType', ctypes.c_byte),
('wReserved', ctypes.c_byte)]
"""
Get's the OS major and minor versions. Returns a tuple of
(OS_MAJOR, OS_MINOR).
"""
os_version = OSVERSIONINFOEXW()
os_version.dwOSVersionInfoSize = ctypes.sizeof(os_version)
retcode = ctypes.windll.Ntdll.RtlGetVersion(ctypes.byref(os_version))
if retcode != 0:
raise Exception("Failed to get OS version")
return os_version.dwMajorVersion
def win32_version():
import ctypes
class OSVERSIONINFOEXW(ctypes.Structure):
_fields_ = [('dwOSVersionInfoSize', ctypes.c_ulong),
('dwMajorVersion', ctypes.c_ulong),
('dwMinorVersion', ctypes.c_ulong),
('dwBuildNumber', ctypes.c_ulong),
('dwPlatformId', ctypes.c_ulong),
('szCSDVersion', ctypes.c_wchar*128),
('wServicePackMajor', ctypes.c_ushort),
('wServicePackMinor', ctypes.c_ushort),
('wSuiteMask', ctypes.c_ushort),
('wProductType', ctypes.c_byte),
('wReserved', ctypes.c_byte)]
"""
Get's the OS major and minor versions. Returns a tuple of
(OS_MAJOR, OS_MINOR).
"""
os_version = OSVERSIONINFOEXW()
os_version.dwOSVersionInfoSize = ctypes.sizeof(os_version)
retcode = ctypes.windll.Ntdll.RtlGetVersion(ctypes.byref(os_version))
if retcode != 0:
raise Exception("Failed to get OS version")
return os_version.dwMajorVersion
def wrap(self, gammaramp):
'''
Wraps a nested python sequence.
'''
red, green, blue = gammaramp
size = min(len(red), len(green), len(blue))
array_type = ctypes.c_ushort*size
self.size = ctypes.c_uint(size)
self.red_array = array_type()
self.green_array = array_type()
self.blue_array = array_type()
for i in range(self.size):
self.red_array[i] = int(red[i]*65535)
self.green_array[i] = int(green[i]*65535)
self.blue_array[i] = int(blue[i]*65535)
pointer_type = ctypes.POINTER(ctypes.c_ushort)
self.red = ctypes.cast(self.red_array, pointer_type)
self.green = ctypes.cast(self.green_array, pointer_type)
self.blue = ctypes.cast(self.blue_array, pointer_type)
def wrap(self, gammaramp):
'''
Wraps a nested python sequence.
'''
red, green, blue = gammaramp
size = min(len(red), len(green), len(blue))
array_type = ctypes.c_ushort*size
self.size = ctypes.c_uint(size)
self.red_array = array_type()
self.green_array = array_type()
self.blue_array = array_type()
for i in range(self.size):
self.red_array[i] = int(red[i]*65535)
self.green_array[i] = int(green[i]*65535)
self.blue_array[i] = int(blue[i]*65535)
pointer_type = ctypes.POINTER(ctypes.c_ushort)
self.red = ctypes.cast(self.red_array, pointer_type)
self.green = ctypes.cast(self.green_array, pointer_type)
self.blue = ctypes.cast(self.blue_array, pointer_type)
def win_create_mdb(mdb_path, sort_order = "General\0\0"):
if sys.platform not in ('win32','cli'):
raise Exception('This function is available for use in Windows only.')
mdb_driver = [d for d in drivers() if 'Microsoft Access Driver (*.mdb' in d]
if mdb_driver == []:
raise Exception('Access Driver is not found.')
else:
driver_name = mdb_driver[0].encode('mbcs')
#CREATE_DB=<path name> <sort order>
ctypes.windll.ODBCCP32.SQLConfigDataSource.argtypes = [ctypes.c_void_p,ctypes.c_ushort,ctypes.c_char_p,ctypes.c_char_p]
if py_v3:
c_Path = bytes("CREATE_DB=" + mdb_path + " " + sort_order,'mbcs')
else:
c_Path = "CREATE_DB=" + mdb_path + " " + sort_order
ODBC_ADD_SYS_DSN = 1
ret = ctypes.windll.ODBCCP32.SQLConfigDataSource(None,ODBC_ADD_SYS_DSN,driver_name, c_Path)
if not ret:
raise Exception('Failed to create Access mdb file - "%s". Please check file path, permission and Access driver readiness.' %mdb_path)
def win_compact_mdb(mdb_path, compacted_mdb_path, sort_order = "General\0\0"):
if sys.platform not in ('win32','cli'):
raise Exception('This function is available for use in Windows only.')
mdb_driver = [d for d in drivers() if 'Microsoft Access Driver (*.mdb' in d]
if mdb_driver == []:
raise Exception('Access Driver is not found.')
else:
driver_name = mdb_driver[0].encode('mbcs')
#COMPACT_DB=<source path> <destination path> <sort order>
ctypes.windll.ODBCCP32.SQLConfigDataSource.argtypes = [ctypes.c_void_p,ctypes.c_ushort,ctypes.c_char_p,ctypes.c_char_p]
#driver_name = "Microsoft Access Driver (*.mdb)"
if py_v3:
c_Path = bytes("COMPACT_DB=" + mdb_path + " " + compacted_mdb_path + " " + sort_order,'mbcs')
#driver_name = bytes(driver_name,'mbcs')
else:
c_Path = "COMPACT_DB=" + mdb_path + " " + compacted_mdb_path + " " + sort_order
ODBC_ADD_SYS_DSN = 1
ret = ctypes.windll.ODBCCP32.SQLConfigDataSource(None,ODBC_ADD_SYS_DSN,driver_name, c_Path)
if not ret:
raise Exception('Failed to compact Access mdb file - "%s". Please check file path, permission and Access driver readiness.' %compacted_mdb_path)
def win_create_mdb(mdb_path, sort_order = "General\0\0"):
if sys.platform not in ('win32','cli'):
raise Exception('This function is available for use in Windows only.')
mdb_driver = [d for d in drivers() if 'Microsoft Access Driver (*.mdb' in d]
if mdb_driver == []:
raise Exception('Access Driver is not found.')
else:
driver_name = mdb_driver[0].encode('mbcs')
#CREATE_DB=<path name> <sort order>
ctypes.windll.ODBCCP32.SQLConfigDataSource.argtypes = [ctypes.c_void_p,ctypes.c_ushort,ctypes.c_char_p,ctypes.c_char_p]
if py_v3:
c_Path = bytes("CREATE_DB=" + mdb_path + " " + sort_order,'mbcs')
else:
c_Path = "CREATE_DB=" + mdb_path + " " + sort_order
ODBC_ADD_SYS_DSN = 1
ret = ctypes.windll.ODBCCP32.SQLConfigDataSource(None,ODBC_ADD_SYS_DSN,driver_name, c_Path)
if not ret:
raise Exception('Failed to create Access mdb file - "%s". Please check file path, permission and Access driver readiness.' %mdb_path)
def win_compact_mdb(mdb_path, compacted_mdb_path, sort_order = "General\0\0"):
if sys.platform not in ('win32','cli'):
raise Exception('This function is available for use in Windows only.')
mdb_driver = [d for d in drivers() if 'Microsoft Access Driver (*.mdb' in d]
if mdb_driver == []:
raise Exception('Access Driver is not found.')
else:
driver_name = mdb_driver[0].encode('mbcs')
#COMPACT_DB=<source path> <destination path> <sort order>
ctypes.windll.ODBCCP32.SQLConfigDataSource.argtypes = [ctypes.c_void_p,ctypes.c_ushort,ctypes.c_char_p,ctypes.c_char_p]
#driver_name = "Microsoft Access Driver (*.mdb)"
if py_v3:
c_Path = bytes("COMPACT_DB=" + mdb_path + " " + compacted_mdb_path + " " + sort_order,'mbcs')
#driver_name = bytes(driver_name,'mbcs')
else:
c_Path = "COMPACT_DB=" + mdb_path + " " + compacted_mdb_path + " " + sort_order
ODBC_ADD_SYS_DSN = 1
ret = ctypes.windll.ODBCCP32.SQLConfigDataSource(None,ODBC_ADD_SYS_DSN,driver_name, c_Path)
if not ret:
raise Exception('Failed to compact Access mdb file - "%s". Please check file path, permission and Access driver readiness.' %compacted_mdb_path)
def win_create_mdb(mdb_path, sort_order = "General\0\0"):
if sys.platform not in ('win32','cli'):
raise Exception('This function is available for use in Windows only.')
mdb_driver = [d for d in drivers() if 'Microsoft Access Driver (*.mdb' in d]
if mdb_driver == []:
raise Exception('Access Driver is not found.')
else:
driver_name = mdb_driver[0].encode('mbcs')
#CREATE_DB=<path name> <sort order>
ctypes.windll.ODBCCP32.SQLConfigDataSource.argtypes = [ctypes.c_void_p,ctypes.c_ushort,ctypes.c_char_p,ctypes.c_char_p]
if py_v3:
c_Path = bytes("CREATE_DB=" + mdb_path + " " + sort_order,'mbcs')
else:
c_Path = "CREATE_DB=" + mdb_path + " " + sort_order
ODBC_ADD_SYS_DSN = 1
ret = ctypes.windll.ODBCCP32.SQLConfigDataSource(None,ODBC_ADD_SYS_DSN,driver_name, c_Path)
if not ret:
raise Exception('Failed to create Access mdb file - "%s". Please check file path, permission and Access driver readiness.' %mdb_path)
def win_compact_mdb(mdb_path, compacted_mdb_path, sort_order = "General\0\0"):
if sys.platform not in ('win32','cli'):
raise Exception('This function is available for use in Windows only.')
mdb_driver = [d for d in drivers() if 'Microsoft Access Driver (*.mdb' in d]
if mdb_driver == []:
raise Exception('Access Driver is not found.')
else:
driver_name = mdb_driver[0].encode('mbcs')
#COMPACT_DB=<source path> <destination path> <sort order>
ctypes.windll.ODBCCP32.SQLConfigDataSource.argtypes = [ctypes.c_void_p,ctypes.c_ushort,ctypes.c_char_p,ctypes.c_char_p]
#driver_name = "Microsoft Access Driver (*.mdb)"
if py_v3:
c_Path = bytes("COMPACT_DB=" + mdb_path + " " + compacted_mdb_path + " " + sort_order,'mbcs')
#driver_name = bytes(driver_name,'mbcs')
else:
c_Path = "COMPACT_DB=" + mdb_path + " " + compacted_mdb_path + " " + sort_order
ODBC_ADD_SYS_DSN = 1
ret = ctypes.windll.ODBCCP32.SQLConfigDataSource(None,ODBC_ADD_SYS_DSN,driver_name, c_Path)
if not ret:
raise Exception('Failed to compact Access mdb file - "%s". Please check file path, permission and Access driver readiness.' %compacted_mdb_path)
def rename_regkey(skey, ssubkey, dsubkey):
"""Rename an entire tree of values in the registry.
Function by Thorsten Sick."""
res_handle = HANDLE()
options = DWORD(0)
res = RegOpenKeyExW(
skey, ssubkey, options, _winreg.KEY_ALL_ACCESS, byref(res_handle)
)
if not res:
bsize = c_ushort(len(dsubkey) * 2)
us = UNICODE_STRING()
us.Buffer = c_wchar_p(dsubkey)
us.Length = bsize
us.MaximumLength = bsize
res = NtRenameKey(res_handle, pointer(us))
if res:
log.warning("Error renaming %s\\%s to %s (0x%x)",
skey, ssubkey, dsubkey, res % 2**32)
if res_handle:
RegCloseKey(res_handle)
def win_create_mdb(mdb_path, sort_order = "General\0\0"):
if sys.platform not in ('win32','cli'):
raise Exception('This function is available for use in Windows only.')
mdb_driver = [d for d in drivers() if 'Microsoft Access Driver (*.mdb' in d]
if mdb_driver == []:
raise Exception('Access Driver is not found.')
else:
driver_name = mdb_driver[0].encode('mbcs')
#CREATE_DB=<path name> <sort order>
ctypes.windll.ODBCCP32.SQLConfigDataSource.argtypes = [ctypes.c_void_p,ctypes.c_ushort,ctypes.c_char_p,ctypes.c_char_p]
if py_v3:
c_Path = bytes("CREATE_DB=" + mdb_path + " " + sort_order,'mbcs')
else:
c_Path = "CREATE_DB=" + mdb_path + " " + sort_order
ODBC_ADD_SYS_DSN = 1
ret = ctypes.windll.ODBCCP32.SQLConfigDataSource(None,ODBC_ADD_SYS_DSN,driver_name, c_Path)
if not ret:
raise Exception('Failed to create Access mdb file - "%s". Please check file path, permission and Access driver readiness.' %mdb_path)
def win_compact_mdb(mdb_path, compacted_mdb_path, sort_order = "General\0\0"):
if sys.platform not in ('win32','cli'):
raise Exception('This function is available for use in Windows only.')
mdb_driver = [d for d in drivers() if 'Microsoft Access Driver (*.mdb' in d]
if mdb_driver == []:
raise Exception('Access Driver is not found.')
else:
driver_name = mdb_driver[0].encode('mbcs')
#COMPACT_DB=<source path> <destination path> <sort order>
ctypes.windll.ODBCCP32.SQLConfigDataSource.argtypes = [ctypes.c_void_p,ctypes.c_ushort,ctypes.c_char_p,ctypes.c_char_p]
#driver_name = "Microsoft Access Driver (*.mdb)"
if py_v3:
c_Path = bytes("COMPACT_DB=" + mdb_path + " " + compacted_mdb_path + " " + sort_order,'mbcs')
#driver_name = bytes(driver_name,'mbcs')
else:
c_Path = "COMPACT_DB=" + mdb_path + " " + compacted_mdb_path + " " + sort_order
ODBC_ADD_SYS_DSN = 1
ret = ctypes.windll.ODBCCP32.SQLConfigDataSource(None,ODBC_ADD_SYS_DSN,driver_name, c_Path)
if not ret:
raise Exception('Failed to compact Access mdb file - "%s". Please check file path, permission and Access driver readiness.' %compacted_mdb_path)
def win32_version():
import ctypes
class OSVERSIONINFOEXW(ctypes.Structure):
_fields_ = [('dwOSVersionInfoSize', ctypes.c_ulong),
('dwMajorVersion', ctypes.c_ulong),
('dwMinorVersion', ctypes.c_ulong),
('dwBuildNumber', ctypes.c_ulong),
('dwPlatformId', ctypes.c_ulong),
('szCSDVersion', ctypes.c_wchar*128),
('wServicePackMajor', ctypes.c_ushort),
('wServicePackMinor', ctypes.c_ushort),
('wSuiteMask', ctypes.c_ushort),
('wProductType', ctypes.c_byte),
('wReserved', ctypes.c_byte)]
"""
Get's the OS major and minor versions. Returns a tuple of
(OS_MAJOR, OS_MINOR).
"""
os_version = OSVERSIONINFOEXW()
os_version.dwOSVersionInfoSize = ctypes.sizeof(os_version)
retcode = ctypes.windll.Ntdll.RtlGetVersion(ctypes.byref(os_version))
if retcode != 0:
raise Exception("Failed to get OS version")
return os_version.dwMajorVersion
def win_create_mdb(mdb_path, sort_order = "General\0\0"):
if sys.platform not in ('win32','cli'):
raise Exception('This function is available for use in Windows only.')
mdb_driver = [d for d in drivers() if 'Microsoft Access Driver (*.mdb' in d]
if mdb_driver == []:
raise Exception('Access Driver is not found.')
else:
driver_name = mdb_driver[0].encode('mbcs')
#CREATE_DB=<path name> <sort order>
ctypes.windll.ODBCCP32.SQLConfigDataSource.argtypes = [ctypes.c_void_p,ctypes.c_ushort,ctypes.c_char_p,ctypes.c_char_p]
if py_v3:
c_Path = bytes("CREATE_DB=" + mdb_path + " " + sort_order,'mbcs')
else:
c_Path = "CREATE_DB=" + mdb_path + " " + sort_order
ODBC_ADD_SYS_DSN = 1
ret = ctypes.windll.ODBCCP32.SQLConfigDataSource(None,ODBC_ADD_SYS_DSN,driver_name, c_Path)
if not ret:
raise Exception('Failed to create Access mdb file - "%s". Please check file path, permission and Access driver readiness.' %mdb_path)
def win_compact_mdb(mdb_path, compacted_mdb_path, sort_order = "General\0\0"):
if sys.platform not in ('win32','cli'):
raise Exception('This function is available for use in Windows only.')
mdb_driver = [d for d in drivers() if 'Microsoft Access Driver (*.mdb' in d]
if mdb_driver == []:
raise Exception('Access Driver is not found.')
else:
driver_name = mdb_driver[0].encode('mbcs')
#COMPACT_DB=<source path> <destination path> <sort order>
ctypes.windll.ODBCCP32.SQLConfigDataSource.argtypes = [ctypes.c_void_p,ctypes.c_ushort,ctypes.c_char_p,ctypes.c_char_p]
#driver_name = "Microsoft Access Driver (*.mdb)"
if py_v3:
c_Path = bytes("COMPACT_DB=" + mdb_path + " " + compacted_mdb_path + " " + sort_order,'mbcs')
#driver_name = bytes(driver_name,'mbcs')
else:
c_Path = "COMPACT_DB=" + mdb_path + " " + compacted_mdb_path + " " + sort_order
ODBC_ADD_SYS_DSN = 1
ret = ctypes.windll.ODBCCP32.SQLConfigDataSource(None,ODBC_ADD_SYS_DSN,driver_name, c_Path)
if not ret:
raise Exception('Failed to compact Access mdb file - "%s". Please check file path, permission and Access driver readiness.' %compacted_mdb_path)
def win32_version():
import ctypes
class OSVERSIONINFOEXW(ctypes.Structure):
_fields_ = [('dwOSVersionInfoSize', ctypes.c_ulong),
('dwMajorVersion', ctypes.c_ulong),
('dwMinorVersion', ctypes.c_ulong),
('dwBuildNumber', ctypes.c_ulong),
('dwPlatformId', ctypes.c_ulong),
('szCSDVersion', ctypes.c_wchar*128),
('wServicePackMajor', ctypes.c_ushort),
('wServicePackMinor', ctypes.c_ushort),
('wSuiteMask', ctypes.c_ushort),
('wProductType', ctypes.c_byte),
('wReserved', ctypes.c_byte)]
"""
Get's the OS major and minor versions. Returns a tuple of
(OS_MAJOR, OS_MINOR).
"""
os_version = OSVERSIONINFOEXW()
os_version.dwOSVersionInfoSize = ctypes.sizeof(os_version)
retcode = ctypes.windll.Ntdll.RtlGetVersion(ctypes.byref(os_version))
if retcode != 0:
raise Exception("Failed to get OS version")
return os_version.dwMajorVersion
canlib.py 文件源码
项目:Udacity-SDC-Radar-Driver-Micro-Challenge
作者: diyjac
项目源码
文件源码
阅读 30
收藏 0
点赞 0
评论 0
def getChannelData_Firmware(self, channel):
"""Get device firmware version
Retrieves the firmvare version numbers for the device connected to
channel.
Args:
channel (int): The channel you are interested in
Returns:
major (int): The major version number
minor (int): The minor version number
build (int): The build number
"""
self.fn = inspect.currentframe().f_code.co_name
buf_type = ct.c_ushort * 4
buf = buf_type()
self.dll.canGetChannelData(channel,
canCHANNELDATA_CARD_FIRMWARE_REV,
ct.byref(buf), ct.sizeof(buf))
(build, release, minor, major) = struct.unpack('HHHH', buf)
return (major, minor, build)
canlib.py 文件源码
项目:Udacity-SDC-Radar-Driver-Micro-Challenge
作者: diyjac
项目源码
文件源码
阅读 28
收藏 0
点赞 0
评论 0
def getChannelData_Firmware(self, channel):
"""Get device firmware version
Retrieves the firmvare version numbers for the device connected to
channel.
Args:
channel (int): The channel you are interested in
Returns:
major (int): The major version number
minor (int): The minor version number
build (int): The build number
"""
self.fn = inspect.currentframe().f_code.co_name
buf_type = ct.c_ushort * 4
buf = buf_type()
self.dll.canGetChannelData(channel,
canCHANNELDATA_CARD_FIRMWARE_REV,
ct.byref(buf), ct.sizeof(buf))
(build, release, minor, major) = struct.unpack('HHHH', buf)
return (major, minor, build)
def wrap(self, gammaramp):
'''
Wraps a nested python sequence.
'''
red, green, blue = gammaramp
size = min(len(red), len(green), len(blue))
array_type = ctypes.c_ushort*size
self.size = ctypes.c_uint(size)
self.red_array = array_type()
self.green_array = array_type()
self.blue_array = array_type()
for i in range(self.size):
self.red_array[i] = int(red[i]*65535)
self.green_array[i] = int(green[i]*65535)
self.blue_array[i] = int(blue[i]*65535)
pointer_type = ctypes.POINTER(ctypes.c_ushort)
self.red = ctypes.cast(self.red_array, pointer_type)
self.green = ctypes.cast(self.green_array, pointer_type)
self.blue = ctypes.cast(self.blue_array, pointer_type)
def wrap(self, gammaramp):
'''
Wraps a nested python sequence.
'''
red, green, blue = gammaramp
size = min(len(red), len(green), len(blue))
array_type = ctypes.c_ushort*size
self.size = ctypes.c_uint(size)
self.red_array = array_type()
self.green_array = array_type()
self.blue_array = array_type()
for i in range(self.size):
self.red_array[i] = int(red[i]*65535)
self.green_array[i] = int(green[i]*65535)
self.blue_array[i] = int(blue[i]*65535)
pointer_type = ctypes.POINTER(ctypes.c_ushort)
self.red = ctypes.cast(self.red_array, pointer_type)
self.green = ctypes.cast(self.green_array, pointer_type)
self.blue = ctypes.cast(self.blue_array, pointer_type)
def win_create_mdb(mdb_path, sort_order = "General\0\0"):
if sys.platform not in ('win32','cli'):
raise Exception('This function is available for use in Windows only.')
mdb_driver = [d for d in drivers() if 'Microsoft Access Driver (*.mdb' in d]
if mdb_driver == []:
raise Exception('Access Driver is not found.')
else:
driver_name = mdb_driver[0].encode('mbcs')
#CREATE_DB=<path name> <sort order>
ctypes.windll.ODBCCP32.SQLConfigDataSource.argtypes = [ctypes.c_void_p,ctypes.c_ushort,ctypes.c_char_p,ctypes.c_char_p]
if py_v3:
c_Path = bytes("CREATE_DB=" + mdb_path + " " + sort_order,'mbcs')
else:
c_Path = "CREATE_DB=" + mdb_path + " " + sort_order
ODBC_ADD_SYS_DSN = 1
ret = ctypes.windll.ODBCCP32.SQLConfigDataSource(None,ODBC_ADD_SYS_DSN,driver_name, c_Path)
if not ret:
raise Exception('Failed to create Access mdb file - "%s". Please check file path, permission and Access driver readiness.' %mdb_path)
def win_compact_mdb(mdb_path, compacted_mdb_path, sort_order = "General\0\0"):
if sys.platform not in ('win32','cli'):
raise Exception('This function is available for use in Windows only.')
mdb_driver = [d for d in drivers() if 'Microsoft Access Driver (*.mdb' in d]
if mdb_driver == []:
raise Exception('Access Driver is not found.')
else:
driver_name = mdb_driver[0].encode('mbcs')
#COMPACT_DB=<source path> <destination path> <sort order>
ctypes.windll.ODBCCP32.SQLConfigDataSource.argtypes = [ctypes.c_void_p,ctypes.c_ushort,ctypes.c_char_p,ctypes.c_char_p]
#driver_name = "Microsoft Access Driver (*.mdb)"
if py_v3:
c_Path = bytes("COMPACT_DB=" + mdb_path + " " + compacted_mdb_path + " " + sort_order,'mbcs')
#driver_name = bytes(driver_name,'mbcs')
else:
c_Path = "COMPACT_DB=" + mdb_path + " " + compacted_mdb_path + " " + sort_order
ODBC_ADD_SYS_DSN = 1
ret = ctypes.windll.ODBCCP32.SQLConfigDataSource(None,ODBC_ADD_SYS_DSN,driver_name, c_Path)
if not ret:
raise Exception('Failed to compact Access mdb file - "%s". Please check file path, permission and Access driver readiness.' %compacted_mdb_path)
def win32_version_string():
import ctypes
class OSVERSIONINFOEXW(ctypes.Structure):
_fields_ = [('dwOSVersionInfoSize', ctypes.c_ulong),
('dwMajorVersion', ctypes.c_ulong),
('dwMinorVersion', ctypes.c_ulong),
('dwBuildNumber', ctypes.c_ulong),
('dwPlatformId', ctypes.c_ulong),
('szCSDVersion', ctypes.c_wchar*128),
('wServicePackMajor', ctypes.c_ushort),
('wServicePackMinor', ctypes.c_ushort),
('wSuiteMask', ctypes.c_ushort),
('wProductType', ctypes.c_byte),
('wReserved', ctypes.c_byte)]
"""
Get's the OS major and minor versions. Returns a tuple of
(OS_MAJOR, OS_MINOR).
"""
os_version = OSVERSIONINFOEXW()
os_version.dwOSVersionInfoSize = ctypes.sizeof(os_version)
retcode = ctypes.windll.Ntdll.RtlGetVersion(ctypes.byref(os_version))
if retcode != 0:
raise Exception("Failed to get OS version")
version_string = "Version:%d-%d; Build:%d; Platform:%d; CSD:%s; ServicePack:%d-%d; Suite:%d; ProductType:%d" % (
os_version.dwMajorVersion, os_version.dwMinorVersion,
os_version.dwBuildNumber,
os_version.dwPlatformId,
os_version.szCSDVersion,
os_version.wServicePackMajor, os_version.wServicePackMinor,
os_version.wSuiteMask,
os_version.wReserved
)
return version_string
def win32_version_string():
import ctypes
class OSVERSIONINFOEXW(ctypes.Structure):
_fields_ = [('dwOSVersionInfoSize', ctypes.c_ulong),
('dwMajorVersion', ctypes.c_ulong),
('dwMinorVersion', ctypes.c_ulong),
('dwBuildNumber', ctypes.c_ulong),
('dwPlatformId', ctypes.c_ulong),
('szCSDVersion', ctypes.c_wchar*128),
('wServicePackMajor', ctypes.c_ushort),
('wServicePackMinor', ctypes.c_ushort),
('wSuiteMask', ctypes.c_ushort),
('wProductType', ctypes.c_byte),
('wReserved', ctypes.c_byte)]
"""
Get's the OS major and minor versions. Returns a tuple of
(OS_MAJOR, OS_MINOR).
"""
os_version = OSVERSIONINFOEXW()
os_version.dwOSVersionInfoSize = ctypes.sizeof(os_version)
retcode = ctypes.windll.Ntdll.RtlGetVersion(ctypes.byref(os_version))
if retcode != 0:
raise Exception("Failed to get OS version")
version_string = "Version:%d-%d; Build:%d; Platform:%d; CSD:%s; ServicePack:%d-%d; Suite:%d; ProductType:%d" % (
os_version.dwMajorVersion, os_version.dwMinorVersion,
os_version.dwBuildNumber,
os_version.dwPlatformId,
os_version.szCSDVersion,
os_version.wServicePackMajor, os_version.wServicePackMinor,
os_version.wSuiteMask,
os_version.wReserved
)
return version_string
awa_gateway_client_api_wrapper.py 文件源码
项目:creator-system-test-framework
作者: CreatorDev
项目源码
文件源码
阅读 25
收藏 0
点赞 0
评论 0
def AwaClientSession_SetIPCAsUDP(self, session, address, port):
self._lib.AwaClientSession_SetIPCAsUDP.restype = c_int
self._lib.AwaClientSession_SetIPCAsUDP.argtypes = [c_void_p, c_char_p, c_ushort]
return self._lib.AwaClientSession_SetIPCAsUDP(session, address, port)
awa_gateway_server_api_wrapper.py 文件源码
项目:creator-system-test-framework
作者: CreatorDev
项目源码
文件源码
阅读 24
收藏 0
点赞 0
评论 0
def AwaServerSession_SetIPCAsUDP(self, session, address, port):
self._lib.AwaClientSession_SetIPCAsUDP.restype = c_int
self._lib.AwaClientSession_SetIPCAsUDP.argtypes = [c_void_p, c_char_p, c_ushort]
return self._lib.AwaServerSession_SetIPCAsUDP(session, address, port)