Skip to content

Commit

Permalink
Cast mountpoints as a list by default
Browse files Browse the repository at this point in the history
Release `v0.2.0`
  • Loading branch information
dormant-user committed Jan 2, 2025
1 parent 5f3c45b commit 2d6c58f
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 16 deletions.
2 changes: 1 addition & 1 deletion pyarchitecture/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from pyarchitecture import cpu, disks, gpu, memory

version = "0.1.1"
version = "0.2.0"


def all_components() -> Dict[str, Any]:
Expand Down
1 change: 0 additions & 1 deletion pyarchitecture/cpu/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import logging
import os
from typing import Dict

from pyarchitecture import config
from pyarchitecture.cpu import main
Expand Down
3 changes: 1 addition & 2 deletions pyarchitecture/disks/linux.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ def drive_info(disk_lib: str | os.PathLike) -> List[Dict[str, str]]:
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"] = []
disks.append(disk_info)
return disks
8 changes: 4 additions & 4 deletions pyarchitecture/disks/macOS.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def update_mountpoints(
device_ids[device_id].append(mount_point)
for device_id, mountpoints in device_ids.items():
if not mountpoints:
device_ids[device_id] = ["Not Mounted"]
device_ids[device_id] = []
return device_ids


Expand Down Expand Up @@ -80,11 +80,11 @@ def parse_diskutil_output(stdout: str) -> List[Dict[str, str]]:
return disks


def drive_info(disk_lib: str | os.PathLike) -> List[Dict[str, str]]:
def drive_info(disk_lib: str | os.PathLike) -> List[Dict[str, str | List[str]]]:
"""Get disks attached to macOS devices.
Returns:
List[Dict[str, str]]:
List[Dict[str, str | List[str]]]:
Returns disks information for macOS devices.
"""
result = subprocess.run([disk_lib, "info", "-all"], capture_output=True, text=True)
Expand All @@ -107,5 +107,5 @@ def drive_info(disk_lib: str | os.PathLike) -> List[Dict[str, str]]:
_ = device_ids[disk["Device Identifier"]]
mountpoints = update_mountpoints(disks, device_ids)
for disk in physical_disks:
disk["mountpoints"] = ", ".join(mountpoints[disk["device_id"]])
disk["mountpoints"] = mountpoints[disk["device_id"]]
return physical_disks
13 changes: 5 additions & 8 deletions pyarchitecture/disks/windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ def reformat_windows(data: Dict[str, str | int | float]) -> Dict[str, str]:
return data


def get_drives(disk_lib: str | os.PathLike) -> List[Dict[str, str]]:
def get_drives(disk_lib: str | os.PathLike) -> List[Dict[str, str | List[str]]]:
"""Get physical drives connected to a Windows machine.
Returns:
List[Dict[str, str]]:
List[Dict[str, str | List[str]]]:
Returns the formatted data for all the drives as a list of key-value pairs.
"""
# noinspection LongLine
Expand Down Expand Up @@ -147,20 +147,17 @@ def get_disk_usage(disk_lib: str | os.PathLike) -> Dict[str, List[str]]:
return output_data


def drive_info(disk_lib: str | os.PathLike) -> List[Dict[str, str]]:
def drive_info(disk_lib: str | os.PathLike) -> List[Dict[str, str | List[str]]]:
"""Get disks attached to Windows devices.
Returns:
List[Dict[str, str]]:
List[Dict[str, str | List[str]]]
Returns disks information for Windows machines.
"""
data = get_drives(disk_lib)
usage = get_disk_usage(disk_lib)
for item in data:
device_id = item["id"]
item.pop("id")
if device_id in usage:
item["mountpoints"] = ", ".join(usage[device_id])
else:
item["mountpoints"] = "Not Mounted"
item["mountpoints"] = usage.get(device_id, [])
return data

0 comments on commit 2d6c58f

Please sign in to comment.