Update hardware.py
Rewrite some function if condition is True then return true else return false, transform in return condition directly Also I don't understand why we need a try/except at line 151 and why we not write return condition ??
This commit is contained in:
parent
3a40764194
commit
bbce3aa26a
|
|
@ -69,10 +69,7 @@ def has_amd_cpu() -> bool:
|
||||||
|
|
||||||
|
|
||||||
def has_intel_cpu() -> bool:
|
def has_intel_cpu() -> bool:
|
||||||
if subprocess.check_output("lscpu | grep Intel", shell=True).strip().decode():
|
return subprocess.check_output("lscpu | grep Intel", shell=True).strip().decode()
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
def has_uefi() -> bool:
|
def has_uefi() -> bool:
|
||||||
return os.path.isdir('/sys/firmware/efi')
|
return os.path.isdir('/sys/firmware/efi')
|
||||||
|
|
@ -106,7 +103,7 @@ def cpu_vendor() -> Optional[str]:
|
||||||
for info in cpu_info:
|
for info in cpu_info:
|
||||||
if info.get('field', None) == "Vendor ID:":
|
if info.get('field', None) == "Vendor ID:":
|
||||||
return info.get('data', None)
|
return info.get('data', None)
|
||||||
return None
|
return
|
||||||
|
|
||||||
|
|
||||||
def cpu_model() -> Optional[str]:
|
def cpu_model() -> Optional[str]:
|
||||||
|
|
@ -116,7 +113,7 @@ def cpu_model() -> Optional[str]:
|
||||||
for info in cpu_info:
|
for info in cpu_info:
|
||||||
if info.get('field', None) == "Model name:":
|
if info.get('field', None) == "Model name:":
|
||||||
return info.get('data', None)
|
return info.get('data', None)
|
||||||
return None
|
return
|
||||||
|
|
||||||
|
|
||||||
def sys_vendor() -> Optional[str]:
|
def sys_vendor() -> Optional[str]:
|
||||||
|
|
@ -151,6 +148,8 @@ def virtualization() -> Optional[str]:
|
||||||
|
|
||||||
|
|
||||||
def is_vm() -> bool:
|
def is_vm() -> bool:
|
||||||
|
return b"none" not in b"".join(SysCommand("systemd-detect-virt")).lower()
|
||||||
|
"""
|
||||||
try:
|
try:
|
||||||
# systemd-detect-virt issues a non-zero exit code if it is not on a virtual machine
|
# systemd-detect-virt issues a non-zero exit code if it is not on a virtual machine
|
||||||
if b"none" not in b"".join(SysCommand("systemd-detect-virt")).lower():
|
if b"none" not in b"".join(SysCommand("systemd-detect-virt")).lower():
|
||||||
|
|
@ -160,4 +159,6 @@ def is_vm() -> bool:
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
# TODO: Add more identifiers
|
# TODO: Add more identifiers
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue