mirror of
https://github.com/azaion/annotations.git
synced 2026-04-23 08:26:31 +00:00
hardware service works on linux
This commit is contained in:
@@ -1,20 +1,9 @@
|
||||
import os
|
||||
import subprocess
|
||||
import pynvml
|
||||
|
||||
|
||||
cdef class HardwareService:
|
||||
"""Handles hardware information retrieval and hash generation."""
|
||||
|
||||
def __init__(self):
|
||||
try:
|
||||
res = subprocess.check_output("ver", shell=True).decode('utf-8')
|
||||
if "Microsoft Windows" in res:
|
||||
self.is_windows = True
|
||||
else:
|
||||
self.is_windows = False
|
||||
except Exception:
|
||||
print('Error during os type checking')
|
||||
self.is_windows = False
|
||||
|
||||
@staticmethod
|
||||
cdef has_nvidia_gpu():
|
||||
@@ -40,7 +29,7 @@ cdef class HardwareService:
|
||||
pass
|
||||
|
||||
cdef str get_hardware_info(self):
|
||||
if self.is_windows:
|
||||
if os.name == 'nt': # windows
|
||||
os_command = (
|
||||
"powershell -Command \""
|
||||
"Get-CimInstance -ClassName Win32_Processor | Select-Object -ExpandProperty Name | Write-Output; "
|
||||
@@ -51,20 +40,17 @@ cdef class HardwareService:
|
||||
)
|
||||
else:
|
||||
os_command = (
|
||||
"/bin/bash -c \" lscpu | grep 'Model name:' | cut -d':' -f2 && "
|
||||
"lscpu | grep 'Model name:' | cut -d':' -f2 && "
|
||||
"lspci | grep VGA | cut -d':' -f3 && "
|
||||
"free -g | grep Mem: | awk '{print $2}' && \""
|
||||
"udevadm info --query=property --name=\"/dev/$(lsblk -no pkname \"$(findmnt -n -o SOURCE --target /)\")\" | grep -E 'ID_SERIAL=|ID_SERIAL_SHORT=' | cut -d'=' -f2- | head -n1 && "
|
||||
"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"
|
||||
)
|
||||
# in case of subprocess error do:
|
||||
# cdef bytes os_command_bytes = os_command.encode('utf-8')
|
||||
# and use os_command_bytes
|
||||
|
||||
result = subprocess.check_output(os_command, shell=True).decode('utf-8')
|
||||
lines = [line.strip() for line in result.splitlines() if line.strip()]
|
||||
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].replace("Name=", "").replace(" ", " ")
|
||||
cdef str gpu = lines[1].replace("Name=", "").replace(" ", " ")
|
||||
cdef str cpu = lines[0]
|
||||
cdef str gpu = lines[1]
|
||||
# could be multiple gpus
|
||||
|
||||
len_lines = len(lines)
|
||||
|
||||
Reference in New Issue
Block a user