Advertisement
Python253

check_ctype_wintype_tool

May 31st, 2024 (edited)
684
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.00 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. # Filename: check_ctype_wintype_tool.py
  4. # Version: 1.0.0
  5. # Author: Jeoi Reqi
  6.  
  7. """
  8. Description:
  9.    - This script checks Python installation, verifies the availability of the ctypes module,
  10.      and checks if the wintypes attribute is available within the ctypes module on a Windows OS.
  11.  
  12. Requirements:
  13.    - Python 3.x
  14.    - Windows OS
  15.    - The following modules:
  16.        - sys
  17.        - ctypes
  18.  
  19. Functions:
  20.    - check_python_installation():
  21.        Checks Python installation and prints the installed Python version.
  22.    - verify_ctypes_module():
  23.        Verifies if the ctypes module can be imported successfully. If not, prompts to reinstall Python.
  24.    - check_wintypes_attribute():
  25.        Checks if the wintypes attribute is available within the ctypes module and prints its attributes if available.
  26.  
  27. Example Output:
  28.  
  29.        Checking Python installation...
  30.        Python 3.10.6 is installed.
  31.  
  32.        Verifying ctypes module...
  33.        ctypes module is imported successfully.
  34.  
  35.        Checking wintypes attribute...
  36.        wintypes attribute is available within ctypes module.
  37.        Attributes:
  38.                     ['ATOM', 'BOOL', 'BOOLEAN', 'BYTE', 'CHAR', 'COLORREF', 'DOUBLE', 'DWORD', 'FILETIME',
  39.                     'FLOAT', 'HACCEL', 'HANDLE', 'HBITMAP', 'HBRUSH', 'HCOLORSPACE', 'HDC', 'HDESK', 'HDWP',
  40.                     'HENHMETAFILE', 'HFONT', 'HGDIOBJ', 'HGLOBAL', 'HHOOK', 'HICON', 'HINSTANCE', 'HKEY',
  41.                     'HKL', 'HLOCAL', 'HMENU', 'HMETAFILE', 'HMODULE', 'HMONITOR', 'HPALETTE', 'HPEN', 'HRGN',
  42.                     'HRSRC', 'HSTR', 'HTASK', 'HWINSTA', 'HWND', 'INT', 'LANGID', 'LARGE_INTEGER', 'LCID',
  43.                     'LCTYPE', 'LGRPID', 'LONG', 'LPARAM', 'LPBOOL', 'LPBYTE', 'LPCOLESTR', 'LPCOLORREF',
  44.                     'LPCSTR', 'LPCVOID', 'LPCWSTR', 'LPDWORD', 'LPFILETIME', 'LPHANDLE', 'LPHKL', 'LPINT',
  45.                     'LPLONG', 'LPMSG', 'LPOLESTR', 'LPPOINT', 'LPRECT', 'LPRECTL', 'LPSC_HANDLE', 'LPSIZE',
  46.                     'LPSIZEL', 'LPSTR', 'LPUINT', 'LPVOID', 'LPWIN32_FIND_DATAA', 'LPWIN32_FIND_DATAW',
  47.                     'LPWORD', 'LPWSTR', 'MAX_PATH', 'MSG', 'OLESTR', 'PBOOL', 'PBOOLEAN', 'PBYTE', 'PCHAR',
  48.                     'PDWORD', 'PFILETIME', 'PFLOAT', 'PHANDLE', 'PHKEY', 'PINT', 'PLARGE_INTEGER', 'PLCID',
  49.                     'PLONG', 'PMSG', 'POINT', 'POINTL', 'PPOINT', 'PPOINTL', 'PRECT', 'PRECTL', 'PSHORT',
  50.                     'PSIZE', 'PSIZEL', 'PSMALL_RECT', 'PUINT', 'PULARGE_INTEGER', 'PULONG', 'PUSHORT',
  51.                     'PWCHAR', 'PWIN32_FIND_DATAA', 'PWIN32_FIND_DATAW', 'PWORD', 'RECT', 'RECTL', 'RGB',
  52.                     'SC_HANDLE', 'SERVICE_STATUS_HANDLE', 'SHORT', 'SIZE', 'SIZEL', 'SMALL_RECT', 'UINT',
  53.                     'ULARGE_INTEGER', 'ULONG', 'USHORT', 'VARIANT_BOOL', 'WCHAR', 'WIN32_FIND_DATAA',
  54.                     'WIN32_FIND_DATAW', 'WORD', 'WPARAM', '_COORD', '_FILETIME', '_LARGE_INTEGER', '_POINTL',
  55.                     '_RECTL', '_SMALL_RECT', '_ULARGE_INTEGER', '__builtins__', '__cached__', '__doc__',
  56.                     '__file__', '__loader__', '__name__', '__package__', '__spec__', 'ctypes', 'tagMSG',
  57.                     'tagPOINT', 'tagRECT', 'tagSIZE']
  58.  
  59.        Process ended with exit code 0.
  60.  
  61. Usage:
  62.    - Run this script in a Python environment.
  63.  
  64. Additional Notes:
  65.    - This script is designed to run on Windows OS.
  66.    - Ensure that Python 3.x is installed.
  67. """
  68.  
  69. import sys
  70. from ctypes import wintypes
  71.  
  72. def check_python_installation():
  73.     """
  74.    Check Python installation and print the installed Python version.
  75.    """
  76.     try:
  77.         version = sys.version.split()[0]
  78.         print(f"Python {version} is installed.")
  79.     except Exception as e:
  80.         print(f"Error: {e}")
  81.  
  82. def verify_ctypes_module():
  83.     """
  84.    Verify if the ctypes module can be imported successfully.
  85.    If not, prompt to reinstall Python.
  86.    """
  87.     try:
  88.         import ctypes
  89.         print("ctypes module is imported successfully.")
  90.     except ImportError:
  91.         print("ctypes module is not imported. Reinstall Python.")
  92.  
  93. def check_wintypes_attribute():
  94.     """
  95.    Check if the wintypes attribute is available within the ctypes module.
  96.    Print its attributes if available.
  97.    """
  98.     try:
  99.         attributes = dir(wintypes)
  100.         print("wintypes attribute is available within ctypes module.")
  101.         print("Attributes:", attributes)  # Add this line to print the attributes
  102.     except AttributeError:
  103.         print("wintypes attribute is not found within ctypes module.")
  104.  
  105. def main():
  106.     """
  107.    Main function to run checks on Python installation, ctypes module, and wintypes attribute.
  108.    """
  109.     print("Checking Python installation...")
  110.     check_python_installation()
  111.  
  112.     print("\nVerifying ctypes module...")
  113.     verify_ctypes_module()
  114.  
  115.     print("\nChecking wintypes attribute...")
  116.     check_wintypes_attribute()
  117.    
  118.     sys.exit()  # Exit the script upon completion
  119.  
  120. if __name__ == "__main__":
  121.     main()
  122.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement