Skip to content

Commit

Permalink
Retain all keys as lower-case
Browse files Browse the repository at this point in the history
  • Loading branch information
dormant-user committed Jan 1, 2025
1 parent f0c7614 commit 53e13d0
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 26 deletions.
4 changes: 2 additions & 2 deletions pyarchitecture/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def commandline() -> None:
if cpu_info and not save_info:
pprint(cpu.get_cpu_info())
if gpu_info and not save_info:
pprint(gpu.get_gpu_names())
pprint(gpu.get_gpu_info())
if mem_info and not save_info:
pprint(memory.get_memory_info())
if all_info and not save_info:
Expand All @@ -114,7 +114,7 @@ def commandline() -> None:
if cpu_info:
data["CPU"] = cpu.get_cpu_info()
if gpu_info:
data["GPU"] = gpu.get_gpu_names()
data["GPU"] = gpu.get_gpu_info()
if disk_info:
data["Disks"] = disks.get_all_disks()
if mem_info:
Expand Down
2 changes: 1 addition & 1 deletion pyarchitecture/cpu/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os
import subprocess

from pyarchitecture import models
from pyarchitecture.cpu import models

LOGGER = logging.getLogger(__name__)

Expand Down
22 changes: 11 additions & 11 deletions pyarchitecture/disks/linux.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,23 @@ def drive_info(disk_lib: str | os.PathLike) -> List[Dict[str, str]]:
for device in data.get("blockdevices", []):
if device["type"] == "disk":
disk_info = {
"DeviceID": device["name"],
"Size": device["size"],
"Name": device.get("model", "Unknown"),
"Mountpoints": [],
"device_id": device["name"],
"size": device["size"],
"name": device.get("model", "Unknown"),
"mountpoints": [],
}
# Collect mount points from partitions
if "children" in device:
for partition in device["children"]:
if partition.get("mountpoint"):
disk_info["Mountpoints"].append(partition["mountpoint"])
if not disk_info["Mountpoints"] and device.get("mountpoint"):
disk_info["mountpoints"].append(partition["mountpoint"])
if not disk_info["mountpoints"] and device.get("mountpoint"):
if isinstance(device["mountpoint"], list):
disk_info["Mountpoints"] = device["mountpoint"]
disk_info["mountpoints"] = device["mountpoint"]
else:
disk_info["Mountpoints"] = [device["mountpoint"]]
elif not disk_info["Mountpoints"]:
disk_info["Mountpoints"] = ["Not Mounted"]
disk_info["Mountpoints"] = ", ".join(disk_info["Mountpoints"])
disk_info["mountpoints"] = [device["mountpoint"]]
elif not disk_info["mountpoints"]:
disk_info["mountpoints"] = ["Not Mounted"]
disk_info["mountpoints"] = ", ".join(disk_info["Mountpoints"])
disks.append(disk_info)
return disks
10 changes: 5 additions & 5 deletions pyarchitecture/disks/macOS.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,17 @@ def drive_info(disk_lib: str | os.PathLike) -> List[Dict[str, str]]:
if disk.get("Virtual") == "No":
physical_disks.append(
{
"Name": disk.get("Device / Media Name"),
"Size": squire.size_converter(
"name": disk.get("Device / Media Name"),
"size": squire.size_converter(
parse_size(disk.get("Disk Size", ""))
),
"DeviceID": disk.get("Device Identifier"),
"Node": disk.get("Device Node"),
"device_id": disk.get("Device Identifier"),
"node": disk.get("Device Node"),
}
)
# Instantiate default dict with keys as DeviceIDs and values as empty list
_ = device_ids[disk["Device Identifier"]]
mountpoints = update_mountpoints(disks, device_ids)
for disk in physical_disks:
disk["Mountpoints"] = ", ".join(mountpoints[disk["DeviceID"]])
disk["mountpoints"] = ", ".join(mountpoints[disk["device_id"]])
return physical_disks
6 changes: 3 additions & 3 deletions pyarchitecture/disks/windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ def reformat_windows(data: Dict[str, str | int | float]) -> Dict[str, str]:
Returns a dictionary of key-value pairs.
"""
data["ID"] = data["DeviceID"][-1]
data["Name"] = data["Model"]
data["DeviceID"] = data["DeviceID"].replace("\\", "").replace(".", "")
data["Size"] = squire.size_converter(data["Size"])
data["name"] = data["Model"]
data["device_id"] = data["DeviceID"].replace("\\", "").replace(".", "")
data["size"] = squire.size_converter(data["Size"])
del data["Caption"]
del data["Model"]
return data
Expand Down
12 changes: 9 additions & 3 deletions pyarchitecture/memory/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os
from typing import Dict

from pyarchitecture import models
from pyarchitecture import models, squire
from pyarchitecture.memory import linux, macOS, windows

LOGGER = logging.getLogger(__name__)
Expand All @@ -26,11 +26,14 @@ def _get_mem_lib(user_input: str | os.PathLike) -> str:
return mem_lib


def get_memory_info(mem_lib: str | os.PathLike = None) -> Dict[str, int]:
def get_memory_info(
mem_lib: str | os.PathLike = None, humanize: bool = True
) -> Dict[str, int | str]:
"""OS-agnostic function to get memory information.
Args:
mem_lib: Custom memory library path.
humanize: Flag to return humanized memory info.
Returns:
Dict[str, int]:
Expand All @@ -42,6 +45,9 @@ def get_memory_info(mem_lib: str | os.PathLike = None) -> Dict[str, int]:
models.OperatingSystem.windows: windows.get_memory_info,
}
try:
return os_map[models.OPERATING_SYSTEM](mem_lib)
raw_info = os_map[models.OPERATING_SYSTEM](_get_mem_lib(mem_lib))
if humanize:
return {k: squire.size_converter(v) for k, v in raw_info.items()}
return raw_info
except Exception as error:
LOGGER.error(error)
2 changes: 1 addition & 1 deletion pyarchitecture/memory/windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class MEMORYSTATUSEX(ctypes.Structure):
]


def get_memory_info(*args) -> Dict[str, int]:
def get_memory_info(_: str) -> Dict[str, int]:
"""Get memory information for Windows OS.
Returns:
Expand Down

0 comments on commit 53e13d0

Please sign in to comment.