Skip to content

Commit

Permalink
Include CPU cores' information
Browse files Browse the repository at this point in the history
  • Loading branch information
vsivanandharao_expedia committed Jan 1, 2025
1 parent c455ec2 commit 48594a9
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 16 deletions.
40 changes: 28 additions & 12 deletions pyarchitecture/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,28 @@
import json
import pprint
import sys
import time
from typing import Any, Dict

from pyarchitecture import cpu, disks, gpu

version = "0.0.0-a0"


def all_components() -> Dict[str, Any]:
"""Get all the architectural components of the system.
Returns:
Dict[str, Any]:
Returns a dictionary of all the components' information.
"""
return {
"Disks": disks.get_all_disks(),
"CPU": cpu.get_cpu_info(),
"GPU": gpu.get_gpu_names(),
}


def commandline() -> None:
"""Starter function to invoke PyArchitecture via CLI commands.
Expand Down Expand Up @@ -67,34 +83,34 @@ def commandline() -> None:
sys.exit(0)

if disk_info and not save_info:
for disk in disks.get_all_disks():
print(disk)
pprint.pprint(disks.get_all_disks())
sys.exit(0)
if cpu_info and not save_info:
print(cpu.get_cpu_name())
pprint.pprint(cpu.get_cpu_info())
sys.exit(0)
if gpu_info and not save_info:
print(gpu.get_gpu_names())
pprint.pprint(gpu.get_gpu_names())
sys.exit(0)

if not any([disk_info, cpu_info, gpu_info]):
save_info = False

if save_info:
filename = filename or f"PyArchitecture_{int(time.time())}.json"
if all_info:
data = {
"Disks": disks.get_all_disks(),
"CPU": cpu.get_cpu_name(),
"GPU": gpu.get_gpu_names(),
}
data = all_components()
else:
data = {}
if cpu_info:
data["CPU"] = cpu.get_cpu_name()
data["CPU"] = cpu.get_cpu_info()
if gpu_info:
data["GPU"] = gpu.get_gpu_names()
if disk_info:
data["Disks"] = disks.get_all_disks()
with open(filename, "w") as file:
json.dump(data, file, indent=2)
import io

with open(filename, "w") as json_file:
json.dump(data, json_file, indent=2) # type: io.TextIOBase
print(f"Architecture information has been stored in {filename!r}")
sys.exit(0)
else:
Expand Down
11 changes: 9 additions & 2 deletions pyarchitecture/cpu/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
import os
from typing import Dict

from pyarchitecture import models
from pyarchitecture.cpu import main
Expand All @@ -23,7 +24,7 @@ def _get_cpu_lib(user_input: str | os.PathLike) -> str:
return cpu_lib


def get_cpu_name(cpu_lib: str | os.PathLike = None) -> str:
def get_cpu_info(cpu_lib: str | os.PathLike = None) -> Dict[str, int | str]:
"""OS-agnostic function to get all CPUs connected to the host system.
Args:
Expand All @@ -33,4 +34,10 @@ def get_cpu_name(cpu_lib: str | os.PathLike = None) -> str:
List[Dict[str, str]]:
Returns CPU name.
"""
return main.get_name(_get_cpu_lib(cpu_lib))
cpu_name = main.get_name(_get_cpu_lib(cpu_lib))
cpu_count = os.cpu_count()
return {
"name": cpu_name,
"logical_cores": cpu_count,
"physical_cores": int(cpu_count / 2) if cpu_count >= 2 else 1,
}
2 changes: 1 addition & 1 deletion pyarchitecture/disks/macOS.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from collections import defaultdict
from typing import Dict, List

from pyarchitecture import squire
from pyarchitecture.disks import squire

LOGGER = logging.getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion pyarchitecture/disks/windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import subprocess
from typing import Dict, List, Tuple

from pyarchitecture import squire
from pyarchitecture.disks import squire

LOGGER = logging.getLogger(__name__)

Expand Down

0 comments on commit 48594a9

Please sign in to comment.