added return value for functions in hardware.py plus cpuVendor function

This commit is contained in:
advaithm 2021-04-07 07:29:49 +05:30
parent 39e354f395
commit 5c83682efd
1 changed files with 16 additions and 9 deletions

View File

@ -1,19 +1,19 @@
import os, subprocess import os, subprocess, json
from .general import sys_command from .general import sys_command
from .networking import list_interfaces, enrichIfaceTypes from .networking import list_interfaces, enrichIfaceTypes
from typing import Optional
def hasWifi(): def hasWifi()->bool:
return 'WIRELESS' in enrichIfaceTypes(list_interfaces().values()).values() return 'WIRELESS' in enrichIfaceTypes(list_interfaces().values()).values()
def hasAMDCPU(): def hasAMDCPU()->bool:
if subprocess.check_output("lscpu | grep AMD", shell=True).strip().decode(): if subprocess.check_output("lscpu | grep AMD", shell=True).strip().decode():
return True return True
return False return False
def hasUEFI(): def hasUEFI()->bool:
return os.path.isdir('/sys/firmware/efi') return os.path.isdir('/sys/firmware/efi')
def graphicsDevices(): def graphicsDevices()->dict:
cards = {} cards = {}
for line in sys_command(f"lspci"): for line in sys_command(f"lspci"):
if b' VGA ' in line: if b' VGA ' in line:
@ -21,13 +21,20 @@ def graphicsDevices():
cards[identifier.strip().lower().decode('UTF-8')] = line cards[identifier.strip().lower().decode('UTF-8')] = line
return cards return cards
def hasNvidiaGraphics(): def hasNvidiaGraphics()->bool:
return any('nvidia' in x for x in graphicsDevices()) return any('nvidia' in x for x in graphicsDevices())
def hasAmdGraphics(): def hasAmdGraphics()->bool:
return any('amd' in x for x in graphicsDevices()) return any('amd' in x for x in graphicsDevices())
def hasIntelGraphics(): def hasIntelGraphics()->bool:
return any('intel' in x for x in graphicsDevices()) return any('intel' in x for x in graphicsDevices())
def cpuVendor()-> Optional[str]:
cpu_info = json.loads(subprocess.check_output("lscpu -J", shell=True).decode('utf-8'))['lscpu']
for info in cpu_info:
if info.get('field',None):
if info.get('field',None) == "Vendor ID:":
return info.get('data',None)
# TODO: Add more identifiers # TODO: Add more identifiers