pyhw 0.7.3__py3-none-any.whl → 0.8.0__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- pyhw/__init__.py +1 -1
- pyhw/__main__.py +2 -2
- pyhw/backend/cpu/cpuBase.py +6 -3
- pyhw/backend/cpu/windows.py +48 -0
- pyhw/backend/gpu/gpuBase.py +8 -4
- pyhw/backend/gpu/windows.py +41 -0
- pyhw/backend/host/hostBase.py +5 -5
- pyhw/backend/host/hostInfo.py +17 -8
- pyhw/backend/host/windows.py +32 -1
- pyhw/backend/kernel/kernelBase.py +3 -2
- pyhw/backend/kernel/kernelInfo.py +6 -0
- pyhw/backend/kernel/windows.py +23 -1
- pyhw/backend/memory/memoryBase.py +8 -4
- pyhw/backend/memory/windows.py +36 -0
- pyhw/backend/nic/linux.py +20 -3
- pyhw/backend/nic/nicBase.py +8 -4
- pyhw/backend/nic/windows.py +44 -0
- pyhw/backend/npu/npuBase.py +8 -6
- pyhw/backend/npu/windows.py +40 -0
- pyhw/backend/os/osBase.py +6 -3
- pyhw/backend/os/osInfo.py +6 -0
- pyhw/backend/os/windows.py +35 -0
- pyhw/backend/shell/shellBase.py +4 -1
- pyhw/backend/shell/shellInfo.py +10 -0
- pyhw/backend/shell/unix.py +2 -10
- pyhw/backend/shell/windows.py +29 -0
- pyhw/backend/title/titleBase.py +2 -2
- pyhw/backend/title/titleInfo.py +9 -0
- pyhw/backend/title/unix.py +2 -9
- pyhw/backend/title/windows.py +10 -1
- pyhw/backend/uptime/linux.py +3 -3
- pyhw/backend/uptime/macos.py +3 -3
- pyhw/backend/uptime/uptimeBase.py +6 -3
- pyhw/backend/uptime/windows.py +49 -0
- pyhw/frontend/color/colorConfig.py +52 -0
- pyhw/frontend/logo/ascii/windows_10.pyhw +19 -0
- pyhw/frontend/logo/ascii/windows_11.pyhw +17 -0
- pyhw/frontend/logo/ascii/windows_2025.pyhw +17 -0
- pyhw/frontend/logo/ascii/windows_old.pyhw +16 -0
- pyhw/library/lib/iokitGPULib.dylib +0 -0
- pyhw/pyhwUtil/pyhwUtil.py +10 -3
- {pyhw-0.7.3.dist-info → pyhw-0.8.0.dist-info}/METADATA +12 -5
- {pyhw-0.7.3.dist-info → pyhw-0.8.0.dist-info}/RECORD +47 -34
- pyhw/library/lib/iokitHostLib.dylib +0 -0
- {pyhw-0.7.3.dist-info → pyhw-0.8.0.dist-info}/LICENSE +0 -0
- {pyhw-0.7.3.dist-info → pyhw-0.8.0.dist-info}/WHEEL +0 -0
- {pyhw-0.7.3.dist-info → pyhw-0.8.0.dist-info}/entry_points.txt +0 -0
- {pyhw-0.7.3.dist-info → pyhw-0.8.0.dist-info}/top_level.txt +0 -0
pyhw/__init__.py
CHANGED
@@ -1 +1 @@
|
|
1
|
-
__version__ = '0.
|
1
|
+
__version__ = '0.8.0'
|
pyhw/__main__.py
CHANGED
@@ -17,8 +17,8 @@ from .pyhwUtil import getOS, selectOSLogo
|
|
17
17
|
|
18
18
|
def main():
|
19
19
|
current_os = getOS()
|
20
|
-
if current_os not in ["linux", "macos", "freebsd"]:
|
21
|
-
print(f"Only Linux, macOS, and
|
20
|
+
if current_os not in ["linux", "macos", "freebsd", "windows"]:
|
21
|
+
print(f"Only Linux, macOS, FreeBSD and Windows are supported for now. Current OS: {current_os}")
|
22
22
|
return
|
23
23
|
data = Data()
|
24
24
|
data.title = TitleDetect(os=current_os).getTitle().title
|
pyhw/backend/cpu/cpuBase.py
CHANGED
@@ -1,6 +1,3 @@
|
|
1
|
-
from .linux import CPUDetectLinux
|
2
|
-
from .macos import CPUDetectMacOS
|
3
|
-
from .bsd import CPUDetectBSD
|
4
1
|
from ...pyhwException import OSUnsupportedException
|
5
2
|
|
6
3
|
|
@@ -10,10 +7,16 @@ class CPUDetect:
|
|
10
7
|
|
11
8
|
def getCPUInfo(self):
|
12
9
|
if self.OS == "linux":
|
10
|
+
from .linux import CPUDetectLinux
|
13
11
|
return CPUDetectLinux().getCPUInfo()
|
14
12
|
elif self.OS == "macos":
|
13
|
+
from .macos import CPUDetectMacOS
|
15
14
|
return CPUDetectMacOS().getCPUInfo()
|
16
15
|
elif self.OS == "freebsd":
|
16
|
+
from .bsd import CPUDetectBSD
|
17
17
|
return CPUDetectBSD().getCPUInfo()
|
18
|
+
elif self.OS == "windows":
|
19
|
+
from .windows import CPUDetectWindows
|
20
|
+
return CPUDetectWindows().getCPUInfo()
|
18
21
|
else:
|
19
22
|
raise OSUnsupportedException("Unsupported operating system")
|
@@ -0,0 +1,48 @@
|
|
1
|
+
import re
|
2
|
+
import os
|
3
|
+
import subprocess
|
4
|
+
from .cpuInfo import CPUInfo
|
5
|
+
import json
|
6
|
+
|
7
|
+
|
8
|
+
class CPUDetectWindows:
|
9
|
+
def __init__(self):
|
10
|
+
self.__cpuInfo = CPUInfo()
|
11
|
+
|
12
|
+
def getCPUInfo(self):
|
13
|
+
self.__getCPUInfo()
|
14
|
+
self.__modelClean()
|
15
|
+
if self.__cpuInfo.model == "":
|
16
|
+
self.__cpuInfo.model = "Unknown"
|
17
|
+
if self.__cpuInfo.model != "":
|
18
|
+
self.__cpuInfo.cpu = self.__cpuInfo.model
|
19
|
+
if self.__cpuInfo.cores != "":
|
20
|
+
self.__cpuInfo.cpu += f" ({self.__cpuInfo.cores})"
|
21
|
+
if self.__cpuInfo.frequency != "":
|
22
|
+
self.__cpuInfo.cpu += f" @ {self.__cpuInfo.frequency}"
|
23
|
+
return self.__cpuInfo
|
24
|
+
|
25
|
+
def __getCPUInfo(self):
|
26
|
+
COMMAND = "Get-CimInstance -ClassName Win32_Processor | Select-Object Name,NumberOfLogicalProcessors,MaxClockSpeed | ConvertTo-JSON"
|
27
|
+
|
28
|
+
try:
|
29
|
+
result = subprocess.run(["powershell", "-NoProfile", "-Command", COMMAND], capture_output=True, text=True)
|
30
|
+
except subprocess.SubprocessError:
|
31
|
+
exit(-1)
|
32
|
+
|
33
|
+
res = json.loads(result.stdout)
|
34
|
+
name = res["Name"]
|
35
|
+
cores = res["NumberOfLogicalProcessors"]
|
36
|
+
frequency = round(int(res["MaxClockSpeed"]) / 1000.0, 2) # GHz
|
37
|
+
if "@" in name:
|
38
|
+
self.__cpuInfo.model = name.split("@")[0].strip()
|
39
|
+
else:
|
40
|
+
self.__cpuInfo.model = name
|
41
|
+
self.__cpuInfo.cores = str(cores)
|
42
|
+
self.__cpuInfo.frequency = f"{frequency:.2f} GHz"
|
43
|
+
|
44
|
+
def __modelClean(self):
|
45
|
+
self.__cpuInfo.model = self.__cpuInfo.model.replace("(R)", "")
|
46
|
+
self.__cpuInfo.model = self.__cpuInfo.model.replace("(TM)", "")
|
47
|
+
self.__cpuInfo.model = self.__cpuInfo.model.replace("CPU ", "")
|
48
|
+
|
pyhw/backend/gpu/gpuBase.py
CHANGED
@@ -1,6 +1,4 @@
|
|
1
|
-
from
|
2
|
-
from .macos import GPUDetectMacOS
|
3
|
-
from .bsd import GPUDetectBSD
|
1
|
+
from ...pyhwException import OSUnsupportedException
|
4
2
|
|
5
3
|
|
6
4
|
class GPUDetect:
|
@@ -9,10 +7,16 @@ class GPUDetect:
|
|
9
7
|
|
10
8
|
def getGPUInfo(self):
|
11
9
|
if self.OS == "linux":
|
10
|
+
from .linux import GPUDetectLinux
|
12
11
|
return GPUDetectLinux().getGPUInfo()
|
13
12
|
elif self.OS == "macos":
|
13
|
+
from .macos import GPUDetectMacOS
|
14
14
|
return GPUDetectMacOS().getGPUInfo()
|
15
15
|
elif self.OS == "freebsd":
|
16
|
+
from .bsd import GPUDetectBSD
|
16
17
|
return GPUDetectBSD().getGPUInfo()
|
18
|
+
elif self.OS == "windows":
|
19
|
+
from .windows import GPUDetectWindows
|
20
|
+
return GPUDetectWindows().getGPUInfo()
|
17
21
|
else:
|
18
|
-
raise
|
22
|
+
raise OSUnsupportedException("Unsupported operating system")
|
@@ -0,0 +1,41 @@
|
|
1
|
+
import subprocess
|
2
|
+
from .gpuInfo import GPUInfo
|
3
|
+
from ..cpu import CPUDetect
|
4
|
+
from ...pyhwUtil import getArch
|
5
|
+
import pypci
|
6
|
+
|
7
|
+
|
8
|
+
class GPUDetectWindows:
|
9
|
+
def __init__(self):
|
10
|
+
self.__gpuInfo = GPUInfo()
|
11
|
+
|
12
|
+
def getGPUInfo(self):
|
13
|
+
self.__getGPUInfo()
|
14
|
+
self.__sortGPUList()
|
15
|
+
return self.__gpuInfo
|
16
|
+
|
17
|
+
def __getGPUInfo(self):
|
18
|
+
gpu_devices = pypci.PCI().FindAllVGA()
|
19
|
+
if len(gpu_devices) == 0:
|
20
|
+
self.__handleNonePciDevices()
|
21
|
+
else:
|
22
|
+
for device in gpu_devices:
|
23
|
+
if device.subsystem_device_name != "":
|
24
|
+
device_name = f"{device.vendor_name} {device.device_name} ({device.subsystem_device_name})"
|
25
|
+
else:
|
26
|
+
device_name = f"{device.vendor_name} {device.device_name}"
|
27
|
+
self.__gpuInfo.gpus.append(self.__gpuNameClean(device_name))
|
28
|
+
self.__gpuInfo.number += 1
|
29
|
+
|
30
|
+
def __handleNonePciDevices(self):
|
31
|
+
self.__gpuInfo.gpus.append("Not found")
|
32
|
+
self.__gpuInfo.number = 1
|
33
|
+
|
34
|
+
@staticmethod
|
35
|
+
def __gpuNameClean(gpu_name: str):
|
36
|
+
gpu_name_clean = gpu_name.replace("Corporation ", "")
|
37
|
+
return gpu_name_clean
|
38
|
+
|
39
|
+
def __sortGPUList(self):
|
40
|
+
self.__gpuInfo.gpus.sort()
|
41
|
+
|
pyhw/backend/host/hostBase.py
CHANGED
@@ -1,7 +1,3 @@
|
|
1
|
-
from .linux import HostDetectLinux
|
2
|
-
from .macos import HostDetectMacOS
|
3
|
-
from .windows import HostDetectWindows
|
4
|
-
from .bsd import HostDetectBSD
|
5
1
|
from ...pyhwException import OSUnsupportedException
|
6
2
|
|
7
3
|
|
@@ -11,12 +7,16 @@ class HostDetect:
|
|
11
7
|
|
12
8
|
def getHostInfo(self):
|
13
9
|
if self.OS == "linux":
|
10
|
+
from .linux import HostDetectLinux
|
14
11
|
return HostDetectLinux().getHostInfo()
|
15
12
|
elif self.OS == "macos":
|
13
|
+
from .macos import HostDetectMacOS
|
16
14
|
return HostDetectMacOS().getHostInfo()
|
17
15
|
elif self.OS == "freebsd":
|
16
|
+
from .bsd import HostDetectBSD
|
18
17
|
return HostDetectBSD().getHostInfo()
|
19
18
|
elif self.OS == "windows":
|
20
|
-
|
19
|
+
from .windows import HostDetectWindows
|
20
|
+
return HostDetectWindows().getHostInfo()
|
21
21
|
else:
|
22
22
|
raise OSUnsupportedException("Unsupported operating system")
|
pyhw/backend/host/hostInfo.py
CHANGED
@@ -3,11 +3,20 @@ from dataclasses import dataclass
|
|
3
3
|
|
4
4
|
@dataclass
|
5
5
|
class HostInfo:
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
6
|
+
"""
|
7
|
+
HostInfo class to store host information.
|
8
|
+
"""
|
9
|
+
def __init__(self):
|
10
|
+
"""
|
11
|
+
Initialize HostInfo class, model attribute is required.
|
12
|
+
"""
|
13
|
+
self.os = ""
|
14
|
+
self.model = ""
|
15
|
+
self.family = ""
|
16
|
+
self.name = ""
|
17
|
+
self.version = ""
|
18
|
+
self.sku = ""
|
19
|
+
self.serial = ""
|
20
|
+
self.uuid = ""
|
21
|
+
self.vendor = ""
|
22
|
+
|
pyhw/backend/host/windows.py
CHANGED
@@ -1,5 +1,36 @@
|
|
1
1
|
"""
|
2
2
|
In dev.
|
3
3
|
"""
|
4
|
+
from ...pyhwUtil import getArch
|
5
|
+
from ...pyhwException import BackendException
|
6
|
+
from .hostInfo import HostInfo
|
7
|
+
import winreg
|
8
|
+
|
9
|
+
|
4
10
|
class HostDetectWindows:
|
5
|
-
|
11
|
+
def __init__(self):
|
12
|
+
self._hostInfo = HostInfo()
|
13
|
+
self._arch = getArch()
|
14
|
+
|
15
|
+
def getHostInfo(self):
|
16
|
+
self._getModel()
|
17
|
+
return self._hostInfo
|
18
|
+
|
19
|
+
def _getModel(self):
|
20
|
+
try:
|
21
|
+
key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, r"HARDWARE\DESCRIPTION\System\BIOS")
|
22
|
+
manufacturer, _ = winreg.QueryValueEx(key, "SystemManufacturer")
|
23
|
+
name, _ = winreg.QueryValueEx(key, "SystemProductName")
|
24
|
+
version, _ = winreg.QueryValueEx(key, "SystemVersion")
|
25
|
+
winreg.CloseKey(key)
|
26
|
+
except FileNotFoundError:
|
27
|
+
raise BackendException("Unable to retrieve system information.")
|
28
|
+
self._hostInfo.name = name
|
29
|
+
self._hostInfo.version = version
|
30
|
+
self._hostInfo.vendor = manufacturer
|
31
|
+
self.__handleVM()
|
32
|
+
self._hostInfo.model = self._hostInfo.name + " " + self._hostInfo.version
|
33
|
+
|
34
|
+
def __handleVM(self):
|
35
|
+
if self._hostInfo.name.startswith("VMware"):
|
36
|
+
self._hostInfo.version = ""
|
@@ -1,4 +1,3 @@
|
|
1
|
-
from .unix import KernelDetectUnix
|
2
1
|
from ...pyhwException import OSUnsupportedException
|
3
2
|
|
4
3
|
|
@@ -8,8 +7,10 @@ class KernelDetect:
|
|
8
7
|
|
9
8
|
def getKernelInfo(self):
|
10
9
|
if self.OS in ["linux", "macos", "freebsd"]:
|
10
|
+
from .unix import KernelDetectUnix
|
11
11
|
return KernelDetectUnix().getKernelInfo()
|
12
12
|
elif self.OS == "windows":
|
13
|
-
|
13
|
+
from .windows import KernelDetectWindows
|
14
|
+
return KernelDetectWindows().getKernelInfo()
|
14
15
|
else:
|
15
16
|
raise OSUnsupportedException("Unsupported operating system")
|
@@ -3,7 +3,13 @@ from dataclasses import dataclass
|
|
3
3
|
|
4
4
|
@dataclass
|
5
5
|
class KernelInfo:
|
6
|
+
"""
|
7
|
+
Data class for storing kernel information.
|
8
|
+
"""
|
6
9
|
def __init__(self):
|
10
|
+
"""
|
11
|
+
Initialize the data class, kernel attribute is required.
|
12
|
+
"""
|
7
13
|
self.name = ""
|
8
14
|
self.version = ""
|
9
15
|
self.machine = ""
|
pyhw/backend/kernel/windows.py
CHANGED
@@ -1,7 +1,29 @@
|
|
1
1
|
"""
|
2
2
|
In dev.
|
3
3
|
"""
|
4
|
+
from .kernelInfo import KernelInfo
|
5
|
+
from ...pyhwException import BackendException
|
6
|
+
import platform
|
7
|
+
import winreg
|
4
8
|
|
5
9
|
|
6
10
|
class KernelDetectWindows:
|
7
|
-
|
11
|
+
def __init__(self):
|
12
|
+
self.__kernelInfo = KernelInfo()
|
13
|
+
|
14
|
+
def getKernelInfo(self):
|
15
|
+
version = platform.version()
|
16
|
+
machine = platform.machine()
|
17
|
+
display = self.__get_windows_version()
|
18
|
+
self.__kernelInfo.kernel = f"{version} ({display}) {machine}"
|
19
|
+
return self.__kernelInfo
|
20
|
+
|
21
|
+
@staticmethod
|
22
|
+
def __get_windows_version():
|
23
|
+
try:
|
24
|
+
key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, r"SOFTWARE\Microsoft\Windows NT\CurrentVersion")
|
25
|
+
display_version, _ = winreg.QueryValueEx(key, "DisplayVersion")
|
26
|
+
winreg.CloseKey(key)
|
27
|
+
return str(display_version)
|
28
|
+
except:
|
29
|
+
raise BackendException("Unable to determine Windows kernel version.")
|
@@ -1,6 +1,4 @@
|
|
1
|
-
from
|
2
|
-
from .macos import MemoryDetectMacOS
|
3
|
-
from .bsd import MemoryDetectBSD
|
1
|
+
from ...pyhwException import OSUnsupportedException
|
4
2
|
|
5
3
|
|
6
4
|
class MemoryDetect:
|
@@ -9,10 +7,16 @@ class MemoryDetect:
|
|
9
7
|
|
10
8
|
def getMemoryInfo(self):
|
11
9
|
if self.OS == "linux":
|
10
|
+
from .linux import MemoryDetectLinux
|
12
11
|
return MemoryDetectLinux().getMemoryInfo()
|
13
12
|
elif self.OS == "macos":
|
13
|
+
from .macos import MemoryDetectMacOS
|
14
14
|
return MemoryDetectMacOS().getMemoryInfo()
|
15
15
|
elif self.OS == "freebsd":
|
16
|
+
from .bsd import MemoryDetectBSD
|
16
17
|
return MemoryDetectBSD().getMemoryInfo()
|
18
|
+
elif self.OS == "windows":
|
19
|
+
from .windows import MemoryDetectWindows
|
20
|
+
return MemoryDetectWindows().getMemoryInfo()
|
17
21
|
else:
|
18
|
-
raise
|
22
|
+
raise OSUnsupportedException("Unsupported operating system")
|
@@ -0,0 +1,36 @@
|
|
1
|
+
from ...pyhwException import BackendException
|
2
|
+
from .memoryInfo import MemoryInfo
|
3
|
+
import subprocess
|
4
|
+
import json
|
5
|
+
|
6
|
+
|
7
|
+
class MemoryDetectWindows:
|
8
|
+
def __init__(self):
|
9
|
+
self._memoryInfo = MemoryInfo()
|
10
|
+
|
11
|
+
def getMemoryInfo(self):
|
12
|
+
self._getMemory()
|
13
|
+
self._memoryInfo.memory = f"{self._memoryInfo.used} MiB / {self._memoryInfo.total} MiB"
|
14
|
+
return self._memoryInfo
|
15
|
+
|
16
|
+
def _getMemory(self):
|
17
|
+
COMMAND = 'Get-CimInstance -ClassName Win32_OperatingSystem | Select-Object FreePhysicalMemory,TotalVisibleMemorySize | ConvertTo-JSON'
|
18
|
+
try:
|
19
|
+
result = subprocess.run(["powershell", "-NoProfile", "-Command", COMMAND], capture_output=True, text=True)
|
20
|
+
except subprocess.SubprocessError:
|
21
|
+
raise BackendException("Failed to get memory information on Windows.")
|
22
|
+
|
23
|
+
res = json.loads(result.stdout)
|
24
|
+
free_memory = int(res['FreePhysicalMemory']) / 1024
|
25
|
+
total_memory = int(res['TotalVisibleMemorySize']) / 1024
|
26
|
+
used_memory = total_memory - free_memory
|
27
|
+
self._memoryInfo.total = round(total_memory, 2)
|
28
|
+
self._memoryInfo.available = round(free_memory, 2)
|
29
|
+
self._memoryInfo.used = round(used_memory, 2)
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
|
36
|
+
|
pyhw/backend/nic/linux.py
CHANGED
@@ -3,6 +3,7 @@ from .nicInfo import NICInfo
|
|
3
3
|
from ...pyhwUtil import getArch
|
4
4
|
from ...pyhwException import BackendException
|
5
5
|
import pypci
|
6
|
+
import os
|
6
7
|
|
7
8
|
|
8
9
|
class NICDetectLinux:
|
@@ -28,9 +29,25 @@ class NICDetectLinux:
|
|
28
29
|
self._nicInfo.number += 1
|
29
30
|
|
30
31
|
def __handleNonePciDevices(self):
|
31
|
-
#
|
32
|
-
|
33
|
-
|
32
|
+
# need to update
|
33
|
+
interfaces = list()
|
34
|
+
for i in os.listdir('/sys/class/net/'):
|
35
|
+
if i == "lo":
|
36
|
+
continue
|
37
|
+
interfaces.append(i)
|
38
|
+
if len(interfaces) > 0:
|
39
|
+
for interface in interfaces:
|
40
|
+
try:
|
41
|
+
if_ip = subprocess.run(["bash", "-c", f"ip -4 addr show {interface} | grep inet | awk '{{print $2}}'"], capture_output=True, text=True).stdout.strip().split("/")[0]
|
42
|
+
self._nicInfo.nics.append(f"{interface} @ {if_ip}")
|
43
|
+
self._nicInfo.number += 1
|
44
|
+
except:
|
45
|
+
pass
|
46
|
+
else:
|
47
|
+
pass
|
48
|
+
if self._nicInfo.number == 0:
|
49
|
+
self._nicInfo.nics.append("Not found")
|
50
|
+
self._nicInfo.number = 1
|
34
51
|
|
35
52
|
@staticmethod
|
36
53
|
def _nicNameClean(nic_name: str):
|
pyhw/backend/nic/nicBase.py
CHANGED
@@ -1,6 +1,4 @@
|
|
1
|
-
from
|
2
|
-
from .macos import NICDetectMacOS
|
3
|
-
from .bsd import NICDetectBSD
|
1
|
+
from ...pyhwException import OSUnsupportedException
|
4
2
|
|
5
3
|
|
6
4
|
class NICDetect:
|
@@ -16,10 +14,16 @@ class NICDetect:
|
|
16
14
|
:return: dataclass NICInfo, direct attr: nics
|
17
15
|
"""
|
18
16
|
if self.OS == "linux":
|
17
|
+
from .linux import NICDetectLinux
|
19
18
|
return NICDetectLinux().getNICInfo()
|
20
19
|
elif self.OS == "macos":
|
20
|
+
from .macos import NICDetectMacOS
|
21
21
|
return NICDetectMacOS().getNICInfo()
|
22
22
|
elif self.OS == "freebsd":
|
23
|
+
from .bsd import NICDetectBSD
|
23
24
|
return NICDetectBSD().getNICInfo()
|
25
|
+
elif self.OS == "windows":
|
26
|
+
from .windows import NICDetectWindows
|
27
|
+
return NICDetectWindows().getNICInfo()
|
24
28
|
else:
|
25
|
-
raise
|
29
|
+
raise OSUnsupportedException("Unsupported operating system")
|
@@ -0,0 +1,44 @@
|
|
1
|
+
import subprocess
|
2
|
+
from .nicInfo import NICInfo
|
3
|
+
from ...pyhwUtil import getArch
|
4
|
+
from ...pyhwException import BackendException
|
5
|
+
import pypci
|
6
|
+
import os
|
7
|
+
|
8
|
+
|
9
|
+
class NICDetectWindows:
|
10
|
+
def __init__(self):
|
11
|
+
self._nicInfo = NICInfo()
|
12
|
+
|
13
|
+
def getNICInfo(self):
|
14
|
+
self._getNICInfo()
|
15
|
+
self._sortNICList()
|
16
|
+
return self._nicInfo
|
17
|
+
|
18
|
+
def _getNICInfo(self):
|
19
|
+
nic_devices = pypci.PCI().FindAllNIC()
|
20
|
+
if len(nic_devices) == 0:
|
21
|
+
self.__handleNonePciDevices()
|
22
|
+
else:
|
23
|
+
for device in nic_devices:
|
24
|
+
if device.subsystem_device_name != "":
|
25
|
+
device_name = f"{device.vendor_name} {device.device_name} ({device.subsystem_device_name})"
|
26
|
+
else:
|
27
|
+
device_name = f"{device.vendor_name} {device.device_name}"
|
28
|
+
self._nicInfo.nics.append(self._nicNameClean(device_name))
|
29
|
+
self._nicInfo.number += 1
|
30
|
+
|
31
|
+
def __handleNonePciDevices(self):
|
32
|
+
# need to update
|
33
|
+
self._nicInfo.nics.append("Not found")
|
34
|
+
self._nicInfo.number = 1
|
35
|
+
|
36
|
+
@staticmethod
|
37
|
+
def _nicNameClean(nic_name: str):
|
38
|
+
nic_name_clean = nic_name.replace("Corporation ", "")
|
39
|
+
return nic_name_clean
|
40
|
+
|
41
|
+
def _sortNICList(self):
|
42
|
+
return self._nicInfo.nics.sort()
|
43
|
+
|
44
|
+
|
pyhw/backend/npu/npuBase.py
CHANGED
@@ -1,6 +1,4 @@
|
|
1
|
-
from
|
2
|
-
from .macos import NPUDetectMacOS
|
3
|
-
from .bsd import NPUDetectBSD
|
1
|
+
from ...pyhwException import OSUnsupportedException
|
4
2
|
|
5
3
|
|
6
4
|
class NPUDetect:
|
@@ -9,12 +7,16 @@ class NPUDetect:
|
|
9
7
|
|
10
8
|
def getNPUInfo(self):
|
11
9
|
if self.OS == "linux":
|
10
|
+
from .linux import NPUDetectLinux
|
12
11
|
return NPUDetectLinux().getNPUInfo()
|
13
12
|
elif self.OS == "macos":
|
13
|
+
from .macos import NPUDetectMacOS
|
14
14
|
return NPUDetectMacOS().getNPUInfo()
|
15
15
|
elif self.OS == "freebsd":
|
16
|
+
from .bsd import NPUDetectBSD
|
16
17
|
return NPUDetectBSD().getNPUInfo()
|
18
|
+
elif self.OS == "windows":
|
19
|
+
from .windows import NPUDetectWindows
|
20
|
+
return NPUDetectWindows().getNPUInfo()
|
17
21
|
else:
|
18
|
-
raise
|
19
|
-
|
20
|
-
|
22
|
+
raise OSUnsupportedException("Unsupported operating system")
|
@@ -0,0 +1,40 @@
|
|
1
|
+
from .npuInfo import NPUInfo
|
2
|
+
import pypci
|
3
|
+
|
4
|
+
|
5
|
+
class NPUDetectWindows:
|
6
|
+
def __init__(self):
|
7
|
+
self._npuInfo = NPUInfo()
|
8
|
+
|
9
|
+
def getNPUInfo(self):
|
10
|
+
self._getNPUInfo()
|
11
|
+
self._sortNPUList()
|
12
|
+
return self._npuInfo
|
13
|
+
|
14
|
+
def _getNPUInfo(self):
|
15
|
+
npu_devices = pypci.PCI().FindAllNPU()
|
16
|
+
if len(npu_devices) == 0:
|
17
|
+
self._handleNonePciDevices()
|
18
|
+
else:
|
19
|
+
for device in npu_devices:
|
20
|
+
if device.subsystem_device_name != "":
|
21
|
+
device_name = f"{device.vendor_name} {device.device_name} ({device.subsystem_device_name})"
|
22
|
+
else:
|
23
|
+
device_name = f"{device.vendor_name} {device.device_name}"
|
24
|
+
self._npuInfo.npus.append(self._npuNameClean(device_name))
|
25
|
+
self._npuInfo.number += 1
|
26
|
+
|
27
|
+
def _handleNonePciDevices(self):
|
28
|
+
# Place Holder for unknown NPU
|
29
|
+
self._npuInfo.number = 1
|
30
|
+
self._npuInfo.npus.append("Not found")
|
31
|
+
|
32
|
+
@staticmethod
|
33
|
+
def _npuNameClean(npu_name: str):
|
34
|
+
npu_name_clean = npu_name.replace("Corporation ", "")
|
35
|
+
return npu_name_clean
|
36
|
+
|
37
|
+
def _sortNPUList(self):
|
38
|
+
self._npuInfo.npus.sort()
|
39
|
+
|
40
|
+
|
pyhw/backend/os/osBase.py
CHANGED
@@ -1,6 +1,3 @@
|
|
1
|
-
from .linux import OSDetectLinux
|
2
|
-
from .macos import OSDetectMacOS
|
3
|
-
from .bsd import OSDetectBSD
|
4
1
|
from ...pyhwException import OSUnsupportedException
|
5
2
|
|
6
3
|
|
@@ -10,10 +7,16 @@ class OSDetect:
|
|
10
7
|
|
11
8
|
def getOSInfo(self):
|
12
9
|
if self.__OS == "linux":
|
10
|
+
from .linux import OSDetectLinux
|
13
11
|
return OSDetectLinux().getOSInfo()
|
14
12
|
elif self.__OS == "macos":
|
13
|
+
from .macos import OSDetectMacOS
|
15
14
|
return OSDetectMacOS().getOSInfo()
|
16
15
|
elif self.__OS == "freebsd":
|
16
|
+
from .bsd import OSDetectBSD
|
17
17
|
return OSDetectBSD().getOSInfo()
|
18
|
+
elif self.__OS == "windows":
|
19
|
+
from .windows import OSDetectWindows
|
20
|
+
return OSDetectWindows().getOSInfo()
|
18
21
|
else:
|
19
22
|
raise OSUnsupportedException("Unsupported operating system")
|
pyhw/backend/os/osInfo.py
CHANGED
@@ -3,7 +3,13 @@ from dataclasses import dataclass
|
|
3
3
|
|
4
4
|
@dataclass
|
5
5
|
class OSInfo:
|
6
|
+
"""
|
7
|
+
Dataclass to hold the OS information
|
8
|
+
"""
|
6
9
|
def __init__(self):
|
10
|
+
"""
|
11
|
+
Initialize the dataclass, prettyName and id attributes are required.
|
12
|
+
"""
|
7
13
|
self.prettyName = ""
|
8
14
|
self.name = ""
|
9
15
|
self.id = ""
|
@@ -0,0 +1,35 @@
|
|
1
|
+
from .osInfo import OSInfo
|
2
|
+
from ...pyhwException import BackendException
|
3
|
+
import platform
|
4
|
+
import winreg
|
5
|
+
|
6
|
+
|
7
|
+
class OSDetectWindows:
|
8
|
+
def __init__(self):
|
9
|
+
self._osInfo = OSInfo()
|
10
|
+
|
11
|
+
def getOSInfo(self):
|
12
|
+
system = platform.system()
|
13
|
+
release = platform.release()
|
14
|
+
edition = platform.win32_edition()
|
15
|
+
machine = platform.machine()
|
16
|
+
display = self.__get_windows_version()
|
17
|
+
self._osInfo.prettyName = f"{system} {release} {display} ({edition}) {machine}"
|
18
|
+
if release == "10":
|
19
|
+
self._osInfo.id = "windows_10"
|
20
|
+
elif release == "11":
|
21
|
+
self._osInfo.id = "windows_11"
|
22
|
+
else:
|
23
|
+
self._osInfo.id = "windows_old"
|
24
|
+
return self._osInfo
|
25
|
+
|
26
|
+
@staticmethod
|
27
|
+
def __get_windows_version():
|
28
|
+
try:
|
29
|
+
key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, r"SOFTWARE\Microsoft\Windows NT\CurrentVersion")
|
30
|
+
display_version, _ = winreg.QueryValueEx(key, "DisplayVersion")
|
31
|
+
winreg.CloseKey(key)
|
32
|
+
return str(display_version)
|
33
|
+
except:
|
34
|
+
raise BackendException("Unable to determine Windows kernel version.")
|
35
|
+
|
pyhw/backend/shell/shellBase.py
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
from .unix import ShellDetectUnix
|
2
1
|
from ...pyhwException import OSUnsupportedException
|
3
2
|
|
4
3
|
|
@@ -8,6 +7,10 @@ class ShellDetect:
|
|
8
7
|
|
9
8
|
def getShellInfo(self):
|
10
9
|
if self.OS in ["linux", "macos", "freebsd"]:
|
10
|
+
from .unix import ShellDetectUnix
|
11
11
|
return ShellDetectUnix().getShellInfo()
|
12
|
+
elif self.OS == "windows":
|
13
|
+
from .windows import ShellDetectWindows
|
14
|
+
return ShellDetectWindows().getShellInfo()
|
12
15
|
else:
|
13
16
|
raise OSUnsupportedException("Unsupported operating system")
|