Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix wmic warning #229

Merged
merged 4 commits into from
Sep 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading