diff --git a/pyarchitecture/__init__.py b/pyarchitecture/__init__.py index c010686..5af81f5 100644 --- a/pyarchitecture/__init__.py +++ b/pyarchitecture/__init__.py @@ -5,7 +5,7 @@ from pyarchitecture import cpu, disks, gpu, memory -version = "0.1.0a3" +version = "0.1.0a4" def all_components() -> Dict[str, Any]: diff --git a/pyarchitecture/disks/windows.py b/pyarchitecture/disks/windows.py index f698f65..dbe102d 100644 --- a/pyarchitecture/disks/windows.py +++ b/pyarchitecture/disks/windows.py @@ -27,6 +27,7 @@ def reformat_windows(data: Dict[str, str | int | float]) -> Dict[str, str]: data["size"] = squire.size_converter(data["Size"]) del data["Caption"] del data["Model"] + del data["DeviceID"] return data diff --git a/pyarchitecture/memory/linux.py b/pyarchitecture/memory/linux.py index 1ba3537..7a21e51 100644 --- a/pyarchitecture/memory/linux.py +++ b/pyarchitecture/memory/linux.py @@ -13,20 +13,37 @@ def get_memory_info(mem_lib: str | os.PathLike) -> Dict[str, int | str]: Returns the memory information as key-value pairs. """ memory_info = {} - with open(mem_lib) as f: - for line in f: + with open(mem_lib) as mem_file: + for line in mem_file: if line.startswith( - ("MemTotal", "MemFree", "MemAvailable", "Buffers", "Cached") + ( + "MemTotal", + "MemFree", + "MemAvailable", + "SwapTotal", + "SwapFree", + ) ): parts = line.split() - memory_info[parts[0][:-1]] = int( - parts[1] - ) # Convert the memory value to int (in kB) + # Convert the memory value to int (in kB) + memory_info[parts[0][:-1]] = int(parts[1]) - # Convert values to bytes (kB to bytes) + # Physical memory (kB to bytes) total = memory_info.get("MemTotal", 0) * 1024 free = memory_info.get("MemFree", 0) * 1024 available = memory_info.get("MemAvailable", 0) * 1024 used = total - free - available - return {"total": total, "free": free, "used": used} + # Swap memory (kB bytes) + swap_total = memory_info.get("SwapTotal", 0) * 1024 + swap_free = memory_info.get("SwapFree", 0) * 1024 + swap_used = swap_total - swap_free + + return { + "total": total, + "free": free, + "used": used, + "swap_total": swap_total, + "swap_used": swap_used, + "swap_free": swap_free, + }