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

New tool : System Informations #218

Open
simonaubertbd opened this issue Dec 17, 2024 · 2 comments
Open

New tool : System Informations #218

simonaubertbd opened this issue Dec 17, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@simonaubertbd
Copy link

Hello,

A useful input tool that exists in Easymorph (and as formula in Alteryx) :

image

Something like that

import os
import platform
import socket
import psutil
import datetime
import sys
import subprocess

def get_system_info():
    # Operating System
    os_name = platform.system()
    os_version = platform.version()
    os_release = platform.release()
    
    # User Account
    user_account = os.getlogin() if hasattr(os, 'getlogin') else 'N/A'
    
    # Machine and Domain Information
    machine_name = socket.gethostname()
    domain = socket.getfqdn()
    
    # RAM Info
    total_ram = round(psutil.virtual_memory().total / (1024 ** 3), 2)  # GB
    free_ram = round(psutil.virtual_memory().available / (1024 ** 3), 2)  # GB
    
    # CPU Info
    cpu_name = platform.processor() or "N/A"
    cpu_count = psutil.cpu_count(logical=True)

    # GPU Info (try different methods based on OS)
    gpu_info = get_gpu_info()

    # UTC Offset
    utc_offset = datetime.datetime.now(datetime.timezone.utc).astimezone().utcoffset()
    
    # Current Directory
    current_directory = os.getcwd()

    return {
        "Operating System": f"{os_name} {os_release} (Version: {os_version})",
        "User Account": user_account,
        "Machine Name": machine_name,
        "Domain": domain,
        "Total RAM (GB)": total_ram,
        "Free RAM (GB)": free_ram,
        "CPU Name": cpu_name,
        "CPU Cores": cpu_count,
        "GPU": gpu_info,
        "UTC Offset": str(utc_offset),
        "Current Directory": current_directory
    }

def get_gpu_info():
    """Attempt to fetch GPU information depending on the OS."""
    if platform.system() == "Windows":
        try:
            # Run systeminfo and parse for GPU (DXDIAG can also be used)
            output = subprocess.check_output("wmic path win32_VideoController get Name", shell=True).decode()
            gpus = [line.strip() for line in output.split('\n') if line.strip() and "Name" not in line]
            return ', '.join(gpus) if gpus else "N/A"
        except Exception:
            return "N/A"
    elif platform.system() == "Darwin":  # macOS
        try:
            output = subprocess.check_output("system_profiler SPDisplaysDataType | grep Chip", shell=True).decode()
            gpus = [line.split(":")[-1].strip() for line in output.split('\n') if "Chip" in line]
            return ', '.join(gpus) if gpus else "N/A"
        except Exception:
            return "N/A"
    elif platform.system() == "Linux":
        try:
            output = subprocess.check_output("lspci | grep VGA", shell=True).decode()
            gpus = [line.split(':')[-1].strip() for line in output.split('\n') if line.strip()]
            return ', '.join(gpus) if gpus else "N/A"
        except Exception:
            return "N/A"
    return "N/A"

def display_info(info):
    print("\n--- System Information ---")
    keys = list(info.keys())
    values = list(info.values())
    max_len = max(len(key) for key in keys) + 5

    print("{: <{width}}".format("Item", width=max_len), end="")
    for key in keys:
        print(key, end=" | ")
    print("\n" + "-" * (max_len + len(keys) * 10))

    print("{: <{width}}".format("Value", width=max_len), end="")
    for value in values:
        print(value, end=" | ")
    print("\n")

if __name__ == "__main__":
    try:
        system_info = get_system_info()
        display_info(system_info)
    except Exception as e:
        print(f"An error occurred: {e}")
@tgourdel
Copy link
Contributor

Interesting, what are the main uses of such tool?

@simonaubertbd
Copy link
Author

Hello @tgourdel I have two usages for such a tool :
-telemetry/audit
-conditional execution (like : if I don't have enough RAM, I won't do such step and display a warning.. If I'm on Windows, I can use some cmd but on linux, it will be something else, etc, etc)

Best regards,

Simon

@tgourdel tgourdel added the enhancement New feature or request label Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants