Added exception handling to check_output

I tweaked the optimized return of check_output. Worth mentioning that `check_output()` will raise an exception `subprocess.CalledProcessError: Command 'lscpu | grep AMD' returned non-zero exit status 1.`.
This commit is contained in:
Anton Hvornum 2021-09-06 13:40:45 +00:00 committed by GitHub
parent 5fe752cf72
commit 8d7ccde162
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 3 deletions

View File

@ -63,13 +63,19 @@ def has_wifi() -> bool:
def has_amd_cpu() -> bool:
if subprocess.check_output("lscpu | grep AMD", shell=True).strip().decode():
return True
try:
return subprocess.check_output("lscpu | grep AMD", shell=True).strip().decode()
except:
pass
return False
def has_intel_cpu() -> bool:
return subprocess.check_output("lscpu | grep Intel", shell=True).strip().decode()
try:
return subprocess.check_output("lscpu | grep Intel", shell=True).strip().decode()
except:
pass
return False
def has_uefi() -> bool:
return os.path.isdir('/sys/firmware/efi')