From bbce3aa26afc3d55831954231579a5456b0da61a Mon Sep 17 00:00:00 2001 From: CYPT71 <51490865+CYPT71@users.noreply.github.com> Date: Thu, 22 Jul 2021 11:47:56 +0200 Subject: 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 ?? --- archinstall/lib/hardware.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'archinstall/lib') diff --git a/archinstall/lib/hardware.py b/archinstall/lib/hardware.py index a63155f5..d040c19a 100644 --- a/archinstall/lib/hardware.py +++ b/archinstall/lib/hardware.py @@ -69,10 +69,7 @@ def has_amd_cpu() -> bool: def has_intel_cpu() -> bool: - if subprocess.check_output("lscpu | grep Intel", shell=True).strip().decode(): - return True - return False - + return subprocess.check_output("lscpu | grep Intel", shell=True).strip().decode() def has_uefi() -> bool: return os.path.isdir('/sys/firmware/efi') @@ -106,7 +103,7 @@ def cpu_vendor() -> Optional[str]: for info in cpu_info: if info.get('field', None) == "Vendor ID:": return info.get('data', None) - return None + return def cpu_model() -> Optional[str]: @@ -116,7 +113,7 @@ def cpu_model() -> Optional[str]: for info in cpu_info: if info.get('field', None) == "Model name:": return info.get('data', None) - return None + return def sys_vendor() -> Optional[str]: @@ -151,6 +148,8 @@ def virtualization() -> Optional[str]: def is_vm() -> bool: + return b"none" not in b"".join(SysCommand("systemd-detect-virt")).lower() + """ try: # 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(): @@ -159,5 +158,7 @@ def is_vm() -> bool: pass return False + + """ # TODO: Add more identifiers -- cgit v1.2.3-70-g09d2 From 5fe752cf7223cc9ff1cf1a50ad5f7873594f83c1 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Mon, 6 Sep 2021 13:22:53 +0000 Subject: No need for try/catch any longer. The old behavior of SysCommand was that exit codes raised an exception, which needed to be handled by each individual caller. We now utilize `.exit_code` instead to manually detect faulty commands and raise exceptions where needed. --- archinstall/lib/hardware.py | 11 ----------- 1 file changed, 11 deletions(-) (limited to 'archinstall/lib') diff --git a/archinstall/lib/hardware.py b/archinstall/lib/hardware.py index d040c19a..f38d46da 100644 --- a/archinstall/lib/hardware.py +++ b/archinstall/lib/hardware.py @@ -149,16 +149,5 @@ def virtualization() -> Optional[str]: def is_vm() -> bool: return b"none" not in b"".join(SysCommand("systemd-detect-virt")).lower() - """ - try: - # 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(): - return True - except: - pass - - return False - - """ # TODO: Add more identifiers -- cgit v1.2.3-70-g09d2 From 8d7ccde1626afbf358e38caa2733aff554b51ea9 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Mon, 6 Sep 2021 13:40:45 +0000 Subject: 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.`. --- archinstall/lib/hardware.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'archinstall/lib') diff --git a/archinstall/lib/hardware.py b/archinstall/lib/hardware.py index f38d46da..c64d21a9 100644 --- a/archinstall/lib/hardware.py +++ b/archinstall/lib/hardware.py @@ -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') -- cgit v1.2.3-70-g09d2