Skip to content

Commit

Permalink
Fix wmic warning (#229)
Browse files Browse the repository at this point in the history
* fix wmic warning

* lint

* lint

* lint
  • Loading branch information
ramkrishna2910 authored Sep 23, 2024
1 parent 642af9e commit dbbea14
Showing 1 changed file with 20 additions and 37 deletions.
57 changes: 20 additions & 37 deletions src/turnkeyml/common/build.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import logging
import sys
import shutil
import traceback
import platform
import subprocess
Expand Down Expand Up @@ -277,45 +278,27 @@ def get_system_info():
except Exception as e: # pylint: disable=broad-except
info_dict["Error OS Version"] = str(e)

if os_type == "Windows":
# Get Processor Information
def get_wmic_info(command):
try:
proc_info = (
subprocess.check_output("wmic cpu get name", shell=True)
.decode()
.split("\n")[1]
.strip()
)
info_dict["Processor"] = proc_info
except Exception as e: # pylint: disable=broad-except
info_dict["Error Processor"] = str(e)
output = subprocess.check_output(command, shell=True).decode()
return output.split("\n")[1].strip()
except Exception as e: # pylint: disable=broad-except
return str(e)

# Get OEM System Information
try:
oem_info = (
subprocess.check_output("wmic computersystem get model", shell=True)
.decode()
.split("\n")[1]
.strip()
)
info_dict["OEM System"] = oem_info
except Exception as e: # pylint: disable=broad-except
info_dict["Error OEM System"] = str(e)

# Get Physical Memory in GB
try:
mem_info_bytes = (
subprocess.check_output(
"wmic computersystem get TotalPhysicalMemory", shell=True
)
.decode()
.split("\n")[1]
.strip()
)
mem_info_gb = round(int(mem_info_bytes) / (1024**3), 2)
info_dict["Physical Memory"] = f"{mem_info_gb} GB"
except Exception as e: # pylint: disable=broad-except
info_dict["Error Physical Memory"] = str(e)
if os_type == "Windows":
if shutil.which("wmic") is not None:
info_dict["Processor"] = get_wmic_info("wmic cpu get name")
info_dict["OEM System"] = get_wmic_info("wmic computersystem get model")
mem_info_bytes = get_wmic_info("wmic computersystem get TotalPhysicalMemory")
try:
mem_info_gb = round(int(mem_info_bytes) / (1024**3), 2)
info_dict["Physical Memory"] = f"{mem_info_gb} GB"
except ValueError:
info_dict["Physical Memory"] = mem_info_bytes
else:
info_dict["Processor"] = "Install WMIC to get system info"
info_dict["OEM System"] = "Install WMIC to get system info"
info_dict["Physical Memory"] = "Install WMIC to get system info"

elif os_type == "Linux":
# WSL has to be handled differently compared to native Linux
Expand Down

0 comments on commit dbbea14

Please sign in to comment.