import os import subprocess cimport constants cdef class HardwareService: @staticmethod cdef str get_hardware_info(): if os.name == 'nt': # windows os_command = ( "powershell -Command \"" "Get-CimInstance -ClassName Win32_Processor | Select-Object -ExpandProperty Name | Write-Output; " "Get-CimInstance -ClassName Win32_VideoController | Select-Object -ExpandProperty Name | Write-Output; " "Get-CimInstance -ClassName Win32_OperatingSystem | Select-Object -ExpandProperty TotalVisibleMemorySize | Write-Output; " "(Get-Disk | Where-Object {$_.IsSystem -eq $true}).SerialNumber" "\"" ) else: os_command = ( "lscpu | grep 'Model name:' | cut -d':' -f2 && " "lspci | grep VGA | cut -d':' -f3 && " "free -k | awk '/^Mem:/ {print $2}' && " "cat /sys/block/sda/device/vpd_pg80 2>/dev/null || cat /sys/block/sda/device/serial 2>/dev/null" ) result = subprocess.check_output(os_command, shell=True).decode('utf-8', errors='ignore') lines = [line.replace(" ", " ").replace("Name=", "").strip('\x00\x14 \t\n\r\v\f') for line in result.splitlines() if line.strip()] cdef str cpu = lines[0] cdef str gpu = lines[1] # could be multiple gpus len_lines = len(lines) cdef str memory = lines[len_lines-2].replace("TotalVisibleMemorySize=", "").replace(" ", " ") cdef str drive_serial = lines[len_lines-1] cdef str res = f'CPU: {cpu}. GPU: {gpu}. Memory: {memory}. DriveSerial: {drive_serial}' constants.log(f'Gathered hardware: {res}') return res