pyhw 0.6.7__py3-none-any.whl → 0.7.0__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- pyhw/__main__.py +2 -2
- pyhw/backend/cpu/bsd.py +12 -0
- pyhw/backend/cpu/cpuBase.py +3 -0
- pyhw/backend/gpu/bsd.py +7 -0
- pyhw/backend/gpu/gpuBase.py +3 -0
- pyhw/backend/host/bsd.py +13 -0
- pyhw/backend/host/hostBase.py +3 -0
- pyhw/backend/host/linux.py +21 -21
- pyhw/backend/kernel/kernelBase.py +1 -3
- pyhw/backend/memory/bsd.py +11 -0
- pyhw/backend/memory/linux.py +8 -8
- pyhw/backend/memory/memoryBase.py +3 -0
- pyhw/backend/nic/bsd.py +7 -0
- pyhw/backend/nic/linux.py +12 -12
- pyhw/backend/nic/nicBase.py +5 -0
- pyhw/backend/npu/bsd.py +6 -0
- pyhw/backend/npu/linux.py +14 -18
- pyhw/backend/npu/npuBase.py +3 -0
- pyhw/backend/os/bsd.py +7 -0
- pyhw/backend/os/linux.py +19 -19
- pyhw/backend/os/osBase.py +3 -0
- pyhw/backend/shell/shellBase.py +1 -1
- pyhw/backend/shell/unix.py +0 -1
- pyhw/backend/title/titleBase.py +1 -1
- pyhw/backend/uptime/bsd.py +7 -0
- pyhw/backend/uptime/macos.py +12 -12
- pyhw/backend/uptime/uptimeBase.py +3 -0
- pyhw/frontend/color/colorConfig.py +10 -0
- pyhw/frontend/frontendBase.py +8 -1
- pyhw/frontend/logo/ascii/freebsd.pyhw +15 -0
- pyhw/pyhwUtil/pyhwUtil.py +18 -8
- {pyhw-0.6.7.dist-info → pyhw-0.7.0.dist-info}/METADATA +15 -7
- {pyhw-0.6.7.dist-info → pyhw-0.7.0.dist-info}/RECORD +37 -29
- {pyhw-0.6.7.dist-info → pyhw-0.7.0.dist-info}/WHEEL +1 -1
- pyhw/macos.py +0 -146
- {pyhw-0.6.7.dist-info → pyhw-0.7.0.dist-info}/LICENSE +0 -0
- {pyhw-0.6.7.dist-info → pyhw-0.7.0.dist-info}/entry_points.txt +0 -0
- {pyhw-0.6.7.dist-info → pyhw-0.7.0.dist-info}/top_level.txt +0 -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
|
21
|
-
print(f"Only Linux and
|
20
|
+
if current_os not in ["linux", "macos", "freebsd"]:
|
21
|
+
print(f"Only Linux, macOS, and FreeBSD is 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/bsd.py
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
from .cpuInfo import CPUInfo
|
2
|
+
from ...pyhwUtil import sysctlGetString, sysctlGetInt, getArch
|
3
|
+
|
4
|
+
|
5
|
+
class CPUDetectBSD:
|
6
|
+
def __init__(self):
|
7
|
+
self.__cpuInfo = CPUInfo()
|
8
|
+
|
9
|
+
def getCPUInfo(self):
|
10
|
+
self.__cpuInfo.cpu = sysctlGetString("hw.model")
|
11
|
+
return self.__cpuInfo
|
12
|
+
|
pyhw/backend/cpu/cpuBase.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
from .linux import CPUDetectLinux
|
2
2
|
from .macos import CPUDetectMacOS
|
3
|
+
from .bsd import CPUDetectBSD
|
3
4
|
from ...pyhwException import OSUnsupportedException
|
4
5
|
|
5
6
|
|
@@ -12,5 +13,7 @@ class CPUDetect:
|
|
12
13
|
return CPUDetectLinux().getCPUInfo()
|
13
14
|
elif self.OS == "macos":
|
14
15
|
return CPUDetectMacOS().getCPUInfo()
|
16
|
+
elif self.OS == "freebsd":
|
17
|
+
return CPUDetectBSD().getCPUInfo()
|
15
18
|
else:
|
16
19
|
raise OSUnsupportedException("Unsupported operating system")
|
pyhw/backend/gpu/bsd.py
ADDED
pyhw/backend/gpu/gpuBase.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
from .linux import GPUDetectLinux
|
2
2
|
from .macos import GPUDetectMacOS
|
3
|
+
from .bsd import GPUDetectBSD
|
3
4
|
|
4
5
|
|
5
6
|
class GPUDetect:
|
@@ -11,5 +12,7 @@ class GPUDetect:
|
|
11
12
|
return GPUDetectLinux().getGPUInfo()
|
12
13
|
elif self.OS == "macos":
|
13
14
|
return GPUDetectMacOS().getGPUInfo()
|
15
|
+
elif self.OS == "freebsd":
|
16
|
+
return GPUDetectBSD().getGPUInfo()
|
14
17
|
else:
|
15
18
|
raise NotImplementedError("Unsupported operating system")
|
pyhw/backend/host/bsd.py
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
from .linux import HostDetectLinux
|
2
|
+
|
3
|
+
|
4
|
+
class HostDetectBSD(HostDetectLinux):
|
5
|
+
def __init__(self):
|
6
|
+
HostDetectLinux.__init__(self)
|
7
|
+
|
8
|
+
def getHostInfo(self):
|
9
|
+
self._hostInfo.name = f"General {self._arch} FreeBSD Host"
|
10
|
+
self._hostInfo.version = ""
|
11
|
+
self._hostInfo.model = self._hostInfo.name + " " + self._hostInfo.version
|
12
|
+
return self._hostInfo
|
13
|
+
|
pyhw/backend/host/hostBase.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
from .linux import HostDetectLinux
|
2
2
|
from .macos import HostDetectMacOS
|
3
3
|
from .windows import HostDetectWindows
|
4
|
+
from .bsd import HostDetectBSD
|
4
5
|
from ...pyhwException import OSUnsupportedException
|
5
6
|
|
6
7
|
|
@@ -13,6 +14,8 @@ class HostDetect:
|
|
13
14
|
return HostDetectLinux().getHostInfo()
|
14
15
|
elif self.OS == "macos":
|
15
16
|
return HostDetectMacOS().getHostInfo()
|
17
|
+
elif self.OS == "freebsd":
|
18
|
+
return HostDetectBSD().getHostInfo()
|
16
19
|
elif self.OS == "windows":
|
17
20
|
pass
|
18
21
|
else:
|
pyhw/backend/host/linux.py
CHANGED
@@ -8,53 +8,53 @@ import os
|
|
8
8
|
|
9
9
|
class HostDetectLinux:
|
10
10
|
def __init__(self):
|
11
|
-
self.
|
12
|
-
self.
|
13
|
-
self.
|
11
|
+
self._hostInfo = HostInfo()
|
12
|
+
self._arch = getArch()
|
13
|
+
self._docker = getDocker()
|
14
14
|
|
15
15
|
def getHostInfo(self):
|
16
|
-
self.
|
17
|
-
return self.
|
16
|
+
self._getModel()
|
17
|
+
return self._hostInfo
|
18
18
|
|
19
|
-
def
|
20
|
-
if self.
|
21
|
-
self.
|
22
|
-
self.
|
23
|
-
self.
|
19
|
+
def _getModel(self):
|
20
|
+
if self._docker:
|
21
|
+
self._hostInfo.name = f"General {self._arch} Docker Host"
|
22
|
+
self._hostInfo.version = ""
|
23
|
+
self._hostInfo.model = self._hostInfo.name + " " + self._hostInfo.version
|
24
24
|
else:
|
25
|
-
if self.
|
25
|
+
if self._arch in ["x86_64", "x86"]:
|
26
26
|
try:
|
27
27
|
with open("/sys/devices/virtual/dmi/id/product_name", "r") as f:
|
28
28
|
product_name = f.read().strip()
|
29
29
|
if product_name.startswith("To be filled by O.E.M."):
|
30
|
-
self.
|
30
|
+
self._hostInfo.name = f"General {self._arch} Host"
|
31
31
|
else:
|
32
|
-
self.
|
32
|
+
self._hostInfo.name = product_name
|
33
33
|
with open("/sys/devices/virtual/dmi/id/product_version", "r") as f:
|
34
34
|
version = f.read().strip()
|
35
35
|
if version.startswith("To be filled by O.E.M."):
|
36
|
-
self.
|
36
|
+
self._hostInfo.version = ""
|
37
37
|
else:
|
38
|
-
self.
|
39
|
-
self.
|
38
|
+
self._hostInfo.version = version
|
39
|
+
self._hostInfo.model = self._hostInfo.name + " " + self._hostInfo.version
|
40
40
|
except FileNotFoundError:
|
41
41
|
pass
|
42
|
-
elif self.
|
42
|
+
elif self._arch in ["aarch64", "arm32"]:
|
43
43
|
# try to find dmi folder since some arm based desktops and servers may have same structure as x86_64 machines.
|
44
44
|
if os.path.exists("/sys/devices/virtual/dmi/id"):
|
45
45
|
try:
|
46
46
|
with open("/sys/devices/virtual/dmi/id/product_name", "r") as f:
|
47
|
-
self.
|
47
|
+
self._hostInfo.name = f.read().strip()
|
48
48
|
with open("/sys/devices/virtual/dmi/id/product_version", "r") as f:
|
49
|
-
self.
|
50
|
-
self.
|
49
|
+
self._hostInfo.version = f.read().strip()
|
50
|
+
self._hostInfo.model = self._hostInfo.name + " " + self._hostInfo.version
|
51
51
|
except FileNotFoundError:
|
52
52
|
pass
|
53
53
|
else:
|
54
54
|
# some single board computers may not have dmi folder, try to find model name in device tree.
|
55
55
|
try:
|
56
56
|
with open("/sys/firmware/devicetree/base/model", "r") as f:
|
57
|
-
self.
|
57
|
+
self._hostInfo.model = f.read().strip()
|
58
58
|
except FileNotFoundError:
|
59
59
|
pass
|
60
60
|
|
@@ -7,9 +7,7 @@ class KernelDetect:
|
|
7
7
|
self.OS = os
|
8
8
|
|
9
9
|
def getKernelInfo(self):
|
10
|
-
if self.OS
|
11
|
-
return KernelDetectUnix().getKernelInfo()
|
12
|
-
elif self.OS == "macos":
|
10
|
+
if self.OS in ["linux", "macos", "freebsd"]:
|
13
11
|
return KernelDetectUnix().getKernelInfo()
|
14
12
|
elif self.OS == "windows":
|
15
13
|
raise OSUnsupportedException("Unsupported operating system")
|
pyhw/backend/memory/linux.py
CHANGED
@@ -3,22 +3,22 @@ from .memoryInfo import MemoryInfo
|
|
3
3
|
|
4
4
|
class MemoryDetectLinux:
|
5
5
|
def __init__(self):
|
6
|
-
self.
|
6
|
+
self._memoryInfo = MemoryInfo()
|
7
7
|
|
8
8
|
def getMemoryInfo(self):
|
9
|
-
self.
|
10
|
-
self.
|
11
|
-
return self.
|
9
|
+
self._getMemory()
|
10
|
+
self._memoryInfo.memory = f"{self._memoryInfo.used} MiB / {self._memoryInfo.total} MiB"
|
11
|
+
return self._memoryInfo
|
12
12
|
|
13
|
-
def
|
13
|
+
def _getMemory(self):
|
14
14
|
try:
|
15
15
|
with open("/proc/meminfo", "r") as file:
|
16
16
|
for line in file:
|
17
17
|
if line.startswith("MemTotal:"):
|
18
|
-
self.
|
18
|
+
self._memoryInfo.total = round(float(line.split(":")[1].strip()[:-3]) / 1024, 2)
|
19
19
|
elif line.startswith("MemAvailable:"):
|
20
|
-
self.
|
21
|
-
self.
|
20
|
+
self._memoryInfo.available = round(float(line.split(":")[1].strip()[:-3]) / 1024, 2)
|
21
|
+
self._memoryInfo.used = round(self._memoryInfo.total - self._memoryInfo.available, 2)
|
22
22
|
except FileNotFoundError:
|
23
23
|
pass
|
24
24
|
|
@@ -1,5 +1,6 @@
|
|
1
1
|
from .linux import MemoryDetectLinux
|
2
2
|
from .macos import MemoryDetectMacOS
|
3
|
+
from .bsd import MemoryDetectBSD
|
3
4
|
|
4
5
|
|
5
6
|
class MemoryDetect:
|
@@ -11,5 +12,7 @@ class MemoryDetect:
|
|
11
12
|
return MemoryDetectLinux().getMemoryInfo()
|
12
13
|
elif self.OS == "macos":
|
13
14
|
return MemoryDetectMacOS().getMemoryInfo()
|
15
|
+
elif self.OS == "freebsd":
|
16
|
+
return MemoryDetectBSD().getMemoryInfo()
|
14
17
|
else:
|
15
18
|
raise NotImplementedError("Unsupported operating system")
|
pyhw/backend/nic/bsd.py
ADDED
pyhw/backend/nic/linux.py
CHANGED
@@ -7,14 +7,14 @@ import pypci
|
|
7
7
|
|
8
8
|
class NICDetectLinux:
|
9
9
|
def __init__(self):
|
10
|
-
self.
|
10
|
+
self._nicInfo = NICInfo()
|
11
11
|
|
12
12
|
def getNICInfo(self):
|
13
|
-
self.
|
14
|
-
self.
|
15
|
-
return self.
|
13
|
+
self._getNICInfo()
|
14
|
+
self._sortNICList()
|
15
|
+
return self._nicInfo
|
16
16
|
|
17
|
-
def
|
17
|
+
def _getNICInfo(self):
|
18
18
|
nic_devices = pypci.PCI().FindAllNIC()
|
19
19
|
if len(nic_devices) == 0:
|
20
20
|
self.__handleNonePciDevices()
|
@@ -24,18 +24,18 @@ class NICDetectLinux:
|
|
24
24
|
device_name = f"{device.vendor_name} {device.device_name} ({device.subsystem_device_name})"
|
25
25
|
else:
|
26
26
|
device_name = f"{device.vendor_name} {device.device_name}"
|
27
|
-
self.
|
28
|
-
self.
|
27
|
+
self._nicInfo.nics.append(self._nicNameClean(device_name))
|
28
|
+
self._nicInfo.number += 1
|
29
29
|
|
30
30
|
def __handleNonePciDevices(self):
|
31
31
|
# placeholder for a more advanced method.
|
32
|
-
self.
|
33
|
-
self.
|
32
|
+
self._nicInfo.nics.append("Not found")
|
33
|
+
self._nicInfo.number = 1
|
34
34
|
|
35
35
|
@staticmethod
|
36
|
-
def
|
36
|
+
def _nicNameClean(nic_name: str):
|
37
37
|
nic_name_clean = nic_name.replace("Corporation ", "")
|
38
38
|
return nic_name_clean
|
39
39
|
|
40
|
-
def
|
41
|
-
return self.
|
40
|
+
def _sortNICList(self):
|
41
|
+
return self._nicInfo.nics.sort()
|
pyhw/backend/nic/nicBase.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
from .linux import NICDetectLinux
|
2
2
|
from .macos import NICDetectMacOS
|
3
|
+
from .bsd import NICDetectBSD
|
3
4
|
|
4
5
|
|
5
6
|
class NICDetect:
|
@@ -18,3 +19,7 @@ class NICDetect:
|
|
18
19
|
return NICDetectLinux().getNICInfo()
|
19
20
|
elif self.OS == "macos":
|
20
21
|
return NICDetectMacOS().getNICInfo()
|
22
|
+
elif self.OS == "freebsd":
|
23
|
+
return NICDetectBSD().getNICInfo()
|
24
|
+
else:
|
25
|
+
raise NotImplementedError("Unsupported operating system")
|
pyhw/backend/npu/bsd.py
ADDED
pyhw/backend/npu/linux.py
CHANGED
@@ -1,42 +1,38 @@
|
|
1
|
-
import subprocess
|
2
1
|
from .npuInfo import NPUInfo
|
3
|
-
from ..cpu import CPUDetect
|
4
|
-
from ...pyhwUtil import getArch
|
5
2
|
import pypci
|
6
3
|
|
7
4
|
|
8
5
|
class NPUDetectLinux:
|
9
6
|
def __init__(self):
|
10
|
-
self.
|
7
|
+
self._npuInfo = NPUInfo()
|
11
8
|
|
12
9
|
def getNPUInfo(self):
|
13
|
-
self.
|
14
|
-
self.
|
15
|
-
return self.
|
10
|
+
self._getNPUInfo()
|
11
|
+
self._sortNPUList()
|
12
|
+
return self._npuInfo
|
16
13
|
|
17
|
-
def
|
14
|
+
def _getNPUInfo(self):
|
18
15
|
npu_devices = pypci.PCI().FindAllNPU()
|
19
16
|
if len(npu_devices) == 0:
|
20
|
-
self.
|
17
|
+
self._handleNonePciDevices()
|
21
18
|
else:
|
22
19
|
for device in npu_devices:
|
23
20
|
if device.subsystem_device_name != "":
|
24
21
|
device_name = f"{device.vendor_name} {device.device_name} ({device.subsystem_device_name})"
|
25
22
|
else:
|
26
23
|
device_name = f"{device.vendor_name} {device.device_name}"
|
27
|
-
self.
|
28
|
-
self.
|
24
|
+
self._npuInfo.npus.append(self._npuNameClean(device_name))
|
25
|
+
self._npuInfo.number += 1
|
29
26
|
|
30
|
-
def
|
27
|
+
def _handleNonePciDevices(self):
|
31
28
|
# Place Holder for unknown NPU
|
32
|
-
self.
|
33
|
-
self.
|
29
|
+
self._npuInfo.number = 1
|
30
|
+
self._npuInfo.npus.append("Not found")
|
34
31
|
|
35
32
|
@staticmethod
|
36
|
-
def
|
33
|
+
def _npuNameClean(npu_name: str):
|
37
34
|
npu_name_clean = npu_name.replace("Corporation ", "")
|
38
35
|
return npu_name_clean
|
39
36
|
|
40
|
-
def
|
41
|
-
self.
|
42
|
-
|
37
|
+
def _sortNPUList(self):
|
38
|
+
self._npuInfo.npus.sort()
|
pyhw/backend/npu/npuBase.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
from .linux import NPUDetectLinux
|
2
2
|
from .macos import NPUDetectMacOS
|
3
|
+
from .bsd import NPUDetectBSD
|
3
4
|
|
4
5
|
|
5
6
|
class NPUDetect:
|
@@ -11,6 +12,8 @@ class NPUDetect:
|
|
11
12
|
return NPUDetectLinux().getNPUInfo()
|
12
13
|
elif self.OS == "macos":
|
13
14
|
return NPUDetectMacOS().getNPUInfo()
|
15
|
+
elif self.OS == "freebsd":
|
16
|
+
return NPUDetectBSD().getNPUInfo()
|
14
17
|
else:
|
15
18
|
raise NotImplementedError("Unsupported operating system")
|
16
19
|
|
pyhw/backend/os/bsd.py
ADDED
pyhw/backend/os/linux.py
CHANGED
@@ -6,47 +6,47 @@ from .osInfo import OSInfo
|
|
6
6
|
|
7
7
|
class OSDetectLinux:
|
8
8
|
def __init__(self):
|
9
|
-
self.
|
9
|
+
self._osInfo = OSInfo()
|
10
10
|
|
11
11
|
def getOSInfo(self):
|
12
12
|
"""
|
13
13
|
Detects the os distribution and its version.
|
14
14
|
:return: dataclass OSInfoLinux, direct attrs: prettyName
|
15
15
|
"""
|
16
|
-
self.
|
17
|
-
self.
|
18
|
-
return self.
|
16
|
+
self._getOSInfo()
|
17
|
+
self._handleArmbian()
|
18
|
+
return self._osInfo
|
19
19
|
|
20
|
-
def
|
20
|
+
def _getOSInfo(self):
|
21
21
|
try:
|
22
22
|
with open("/etc/os-release", "r") as f:
|
23
23
|
for line in f:
|
24
24
|
key, value = line.strip().split("=")
|
25
25
|
if key == "PRETTY_NAME":
|
26
|
-
self.
|
26
|
+
self._osInfo.prettyName = value.strip('"')
|
27
27
|
elif key == "NAME":
|
28
|
-
self.
|
28
|
+
self._osInfo.name = value.strip('"')
|
29
29
|
elif key == "ID":
|
30
|
-
self.
|
30
|
+
self._osInfo.id = value.strip('"')
|
31
31
|
elif key == "ID_LIKE":
|
32
|
-
self.
|
32
|
+
self._osInfo.idLike = value.strip('"')
|
33
33
|
elif key == "VARIANT":
|
34
|
-
self.
|
34
|
+
self._osInfo.variant = value.strip('"')
|
35
35
|
elif key == "VARIANT_ID":
|
36
|
-
self.
|
36
|
+
self._osInfo.variantID = value.strip('"')
|
37
37
|
elif key == "VERSION":
|
38
|
-
self.
|
38
|
+
self._osInfo.version = value.strip('"')
|
39
39
|
elif key == "VERSION_ID":
|
40
|
-
self.
|
40
|
+
self._osInfo.versionID = value.strip('"')
|
41
41
|
elif key == "VERSION_CODENAME":
|
42
|
-
self.
|
42
|
+
self._osInfo.versionCodename = value.strip('"')
|
43
43
|
elif key == "CODE_NAME":
|
44
|
-
self.
|
44
|
+
self._osInfo.codeName = value.strip('"')
|
45
45
|
elif key == "BUILD_ID":
|
46
|
-
self.
|
46
|
+
self._osInfo.buildID = value.strip('"')
|
47
47
|
except Exception:
|
48
48
|
pass
|
49
49
|
|
50
|
-
def
|
51
|
-
if "Armbian" in self.
|
52
|
-
self.
|
50
|
+
def _handleArmbian(self):
|
51
|
+
if "Armbian" in self._osInfo.prettyName or "armbian" in self._osInfo.prettyName:
|
52
|
+
self._osInfo.id = "armbian"
|
pyhw/backend/os/osBase.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
from .linux import OSDetectLinux
|
2
2
|
from .macos import OSDetectMacOS
|
3
|
+
from .bsd import OSDetectBSD
|
3
4
|
from ...pyhwException import OSUnsupportedException
|
4
5
|
|
5
6
|
|
@@ -12,5 +13,7 @@ class OSDetect:
|
|
12
13
|
return OSDetectLinux().getOSInfo()
|
13
14
|
elif self.__OS == "macos":
|
14
15
|
return OSDetectMacOS().getOSInfo()
|
16
|
+
elif self.__OS == "freebsd":
|
17
|
+
return OSDetectBSD().getOSInfo()
|
15
18
|
else:
|
16
19
|
raise OSUnsupportedException("Unsupported operating system")
|
pyhw/backend/shell/shellBase.py
CHANGED
@@ -7,7 +7,7 @@ class ShellDetect:
|
|
7
7
|
self.OS = os
|
8
8
|
|
9
9
|
def getShellInfo(self):
|
10
|
-
if self.OS
|
10
|
+
if self.OS in ["linux", "macos", "freebsd"]:
|
11
11
|
return ShellDetectUnix().getShellInfo()
|
12
12
|
else:
|
13
13
|
raise OSUnsupportedException("Unsupported operating system")
|
pyhw/backend/shell/unix.py
CHANGED
pyhw/backend/title/titleBase.py
CHANGED
@@ -8,7 +8,7 @@ class TitleDetect:
|
|
8
8
|
self.OS = os
|
9
9
|
|
10
10
|
def getTitle(self):
|
11
|
-
if self.OS
|
11
|
+
if self.OS in ["linux", "macos", "freebsd"]:
|
12
12
|
return TitleDetectUnix().getTitle()
|
13
13
|
elif self.OS == "windows":
|
14
14
|
return TitleDetectWindows().getTitle()
|
pyhw/backend/uptime/macos.py
CHANGED
@@ -6,13 +6,13 @@ import subprocess
|
|
6
6
|
|
7
7
|
class UptimeDetectMacOS:
|
8
8
|
def __init__(self):
|
9
|
-
self.
|
10
|
-
self.
|
11
|
-
self.
|
9
|
+
self._uptimeInfo = UptimeInfo()
|
10
|
+
self._boot_time = 0
|
11
|
+
self._now = 0
|
12
12
|
|
13
13
|
def getUptimeInfo(self):
|
14
|
-
self.
|
15
|
-
uptime_seconds = self.
|
14
|
+
self._getUptime()
|
15
|
+
uptime_seconds = self._now - self._boot_time
|
16
16
|
hours, remainder = divmod(uptime_seconds, 3600)
|
17
17
|
minutes, seconds = divmod(remainder, 60)
|
18
18
|
days, hours = divmod(hours, 24)
|
@@ -22,19 +22,19 @@ class UptimeDetectMacOS:
|
|
22
22
|
seconds = int(seconds)
|
23
23
|
if days == 0:
|
24
24
|
if hours == 0:
|
25
|
-
self.
|
25
|
+
self._uptimeInfo.uptime = f"{minutes} min {seconds} sec"
|
26
26
|
else:
|
27
|
-
self.
|
27
|
+
self._uptimeInfo.uptime = f"{hours} hours {minutes} min {seconds} sec"
|
28
28
|
else:
|
29
|
-
self.
|
30
|
-
return self.
|
29
|
+
self._uptimeInfo.uptime = f"{days} days {hours} hours {minutes} min {seconds} sec"
|
30
|
+
return self._uptimeInfo
|
31
31
|
|
32
|
-
def
|
32
|
+
def _getUptime(self):
|
33
33
|
result = sysctlGetString("kern.boottime")
|
34
34
|
match = re.search(r'sec = (\d+),', result)
|
35
35
|
if match:
|
36
|
-
self.
|
36
|
+
self._boot_time = int(match.group(1))
|
37
37
|
else:
|
38
38
|
return
|
39
|
-
self.
|
39
|
+
self._now = int(subprocess.check_output(["date", "+%s"]).decode().strip())
|
40
40
|
|
@@ -1,5 +1,6 @@
|
|
1
1
|
from .linux import UptimeDetectLinux
|
2
2
|
from .macos import UptimeDetectMacOS
|
3
|
+
from .bsd import UptimeDetectBSD
|
3
4
|
from ...pyhwException import OSUnsupportedException
|
4
5
|
|
5
6
|
|
@@ -19,5 +20,7 @@ class UptimeDetect:
|
|
19
20
|
return UptimeDetectLinux().getUptimeInfo()
|
20
21
|
elif self.OS == "macos":
|
21
22
|
return UptimeDetectMacOS().getUptimeInfo()
|
23
|
+
elif self.OS == "freebsd":
|
24
|
+
return UptimeDetectBSD().getUptimeInfo()
|
22
25
|
else:
|
23
26
|
raise OSUnsupportedException("Unsupported operating system")
|
@@ -31,6 +31,8 @@ class ColorConfigSet:
|
|
31
31
|
return ColorConfigSetA.arch
|
32
32
|
elif self.__os_name == "centos":
|
33
33
|
return ColorConfigSetC.centos
|
34
|
+
elif self.__os_name == "freebsd":
|
35
|
+
return ColorConfigSetF.freebsd
|
34
36
|
else:
|
35
37
|
return ColorConfigSetL.linux # default to Linux
|
36
38
|
|
@@ -107,6 +109,14 @@ class ColorConfigSetF:
|
|
107
109
|
"colorKeys": ColorSet.COLOR_FG_BLUE,
|
108
110
|
"colorTitle": ColorSet.COLOR_FG_BLUE
|
109
111
|
}
|
112
|
+
freebsd = {
|
113
|
+
"colors": [
|
114
|
+
ColorSet.COLOR_FG_WHITE,
|
115
|
+
ColorSet.COLOR_FG_RED
|
116
|
+
],
|
117
|
+
"colorKeys": ColorSet.COLOR_FG_RED,
|
118
|
+
"colorTitle": ColorSet.COLOR_FG_RED
|
119
|
+
}
|
110
120
|
|
111
121
|
|
112
122
|
@dataclass
|
pyhw/frontend/frontendBase.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
from .logo import Logo
|
2
2
|
from .color import ColorConfigSet, colorPrefix, colorSuffix, ColorSet
|
3
3
|
from ..pyhwUtil import getOS
|
4
|
+
from ..pyhwException import BackendException
|
4
5
|
import os
|
5
6
|
import re
|
6
7
|
|
@@ -95,7 +96,13 @@ class Printer:
|
|
95
96
|
self.__data_lines[0].split("@")[1] + colorSuffix())
|
96
97
|
self.__processed_data_lines.append(colorSuffix() + self.__data_lines[1])
|
97
98
|
for data_line in self.__data_lines[2:]:
|
98
|
-
|
99
|
+
try:
|
100
|
+
spl = data_line.split(": ")
|
101
|
+
name = spl[0]
|
102
|
+
value = "".join(spl[1:])
|
103
|
+
except:
|
104
|
+
print(data_line)
|
105
|
+
raise BackendException("Invalid data format")
|
99
106
|
self.__processed_data_lines.append(colorPrefix(ColorSet.COLOR_MODE_BOLD) + colorPrefix(keys_color) + name + ": " + colorSuffix() + value)
|
100
107
|
|
101
108
|
|
pyhw/pyhwUtil/pyhwUtil.py
CHANGED
@@ -7,7 +7,7 @@ from dataclasses import dataclass
|
|
7
7
|
def getOS():
|
8
8
|
"""
|
9
9
|
Get the os type in lower case.
|
10
|
-
:return: str, os type, value in [windows, linux, macos, unknown].
|
10
|
+
:return: str, os type, value in [windows, linux, macos, freebsd, unknown].
|
11
11
|
"""
|
12
12
|
system = platform.system()
|
13
13
|
if system == "Windows":
|
@@ -16,6 +16,8 @@ def getOS():
|
|
16
16
|
return "linux"
|
17
17
|
elif system == "Darwin":
|
18
18
|
return "macos"
|
19
|
+
elif system == "FreeBSD":
|
20
|
+
return "freebsd"
|
19
21
|
else:
|
20
22
|
return "unknown"
|
21
23
|
|
@@ -54,8 +56,11 @@ class DataStringProcessor:
|
|
54
56
|
@staticmethod
|
55
57
|
def __getENV() -> int:
|
56
58
|
if getOS() == "linux":
|
57
|
-
|
58
|
-
|
59
|
+
try:
|
60
|
+
_, columns_str = os.popen('stty size', 'r').read().split()
|
61
|
+
columns = int(columns_str)
|
62
|
+
except:
|
63
|
+
columns = 80 # default terminal size is 80 columns
|
59
64
|
else:
|
60
65
|
# macOS default terminal size is 80 columns
|
61
66
|
columns = 80
|
@@ -168,8 +173,8 @@ def createDataStringOld(data: Data):
|
|
168
173
|
|
169
174
|
@dataclass
|
170
175
|
class SupportedOS:
|
171
|
-
ColorConfig = ["armbian", "arch", "alpine", "centos", "debian", "fedora", "macOS", "raspbian", "ubuntu"]
|
172
|
-
AsciiLogo = ["armbian", "arch", "alpine", "centos", "debian", "fedora", "macOS", "raspbian", "ubuntu"]
|
176
|
+
ColorConfig = ["armbian", "arch", "alpine", "centos", "debian", "fedora", "macOS", "raspbian", "ubuntu", "freebsd"]
|
177
|
+
AsciiLogo = ["armbian", "arch", "alpine", "centos", "debian", "fedora", "macOS", "raspbian", "ubuntu", "freebsd"]
|
173
178
|
|
174
179
|
|
175
180
|
def selectOSLogo(os_id: str):
|
@@ -184,9 +189,14 @@ def selectOSLogo(os_id: str):
|
|
184
189
|
pass
|
185
190
|
else:
|
186
191
|
return "linux"
|
187
|
-
|
188
|
-
|
189
|
-
|
192
|
+
try:
|
193
|
+
rows_str, columns_str = os.popen('stty size', 'r').read().split()
|
194
|
+
rows = int(rows_str)
|
195
|
+
columns = int(columns_str)
|
196
|
+
except:
|
197
|
+
# Default terminal size is 24 rows and 80 columns
|
198
|
+
rows = 24
|
199
|
+
columns = 80
|
190
200
|
if columns <= 80:
|
191
201
|
if os_id in ["fedora", "ubuntu"]:
|
192
202
|
return f"{os_id}_small"
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: pyhw
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.7.0
|
4
4
|
Summary: PyHw, a neofetch-like command line tool for fetching system information but written mostly in python.
|
5
5
|
Author-email: Xiao Ran <xiaoran.007@icloud.com>
|
6
6
|
License: BSD-3-Clause
|
@@ -22,9 +22,10 @@ Requires-Dist: pypci-ng>=0.0.8
|
|
22
22
|

|
24
24
|

|
25
|
+

|
25
26
|
|
26
27
|
|
27
|
-
PyHw, a neofetch-like command line tool for fetching system information but written mostly in Python. **Currently, this project is still in the initial stage, only
|
28
|
+
PyHw, a neofetch-like command line tool for fetching system information but written mostly in Python. **Currently, this project is still in the initial stage, only Linux, macOS, and FreeBSD are supported.**
|
28
29
|
|
29
30
|
This project is a Python reimplementation of [neofetch](https://github.com/dylanaraps/neofetch) and references the [fastfetch](https://github.com/fastfetch-cli/fastfetch) project for logo style settings. Since this project is implemented in Python, it will be easier to maintain and extend than bash and c implementation. Also, this project only relies on the Python standard library, so you can run it on any device that has a Python environment (I hope so 🤔).
|
30
31
|
|
@@ -50,6 +51,8 @@ pip install pyhw --upgrade
|
|
50
51
|
You can then use this tool directly from the command line with the following command, just like neofetch.
|
51
52
|
```shell
|
52
53
|
pyhw
|
54
|
+
# or
|
55
|
+
python -m pyhw
|
53
56
|
```
|
54
57
|
Please note that the command line entry for __pyhw__ is created by pip, and depending on the user, this entry may not in the __system PATH__. If you encounter this problem, pip will give you a prompt, follow the prompts to add entry to the __system PATH__.
|
55
58
|
|
@@ -66,7 +69,7 @@ pyhw
|
|
66
69
|
```
|
67
70
|
|
68
71
|
### Important note about debian 12:
|
69
|
-
If you use system pip to install pyhw, you will encounter this problem on debian12 and some related distributions:
|
72
|
+
If you use system pip to install pyhw, you will encounter this problem on debian12 and some related distributions (like Ubuntu 24.04):
|
70
73
|
```text
|
71
74
|
error: externally-managed-environment
|
72
75
|
|
@@ -87,14 +90,14 @@ hint: See PEP 668 for the detailed specification.
|
|
87
90
|
```
|
88
91
|
This is due to the fact that system python is not supposed to be managed by pip. You can simply use **pipx** to install **pyhw**. Or you can use a virtual environment (venv) or force remove this restriction (not recommended).
|
89
92
|
|
90
|
-
##
|
93
|
+
## Tested OS
|
91
94
|
* macOS arm64, x86_64
|
92
|
-
*
|
93
|
-
*
|
95
|
+
* Linux arm64, x86_64
|
96
|
+
* FreeBSD arm64
|
94
97
|
|
95
98
|
|
96
99
|
## Build from source
|
97
|
-
Currently, build process relay on swiftc and macOS IOKit framework. To build package from source, you need a
|
100
|
+
Currently, build process relay on swiftc and macOS IOKit framework. To build package from source, you need a Mac machine with macOS 11 and newer.
|
98
101
|
|
99
102
|
### Dependencies
|
100
103
|
This package was originally implemented in pure python and only depends on the python standard library. However, in subsequent development, the code for the pci part was separated into a separate package **pypci-ng**, which can be obtained using pip (or check out [this](https://github.com/xiaoran007/pypci) GitHub repository).
|
@@ -119,3 +122,8 @@ Or simply type:
|
|
119
122
|
make build
|
120
123
|
make install
|
121
124
|
```
|
125
|
+
If you have docker installed, you can test this package through docker by type:
|
126
|
+
```shell
|
127
|
+
make test # local build
|
128
|
+
make test-pypi # release version
|
129
|
+
```
|
@@ -1,66 +1,73 @@
|
|
1
1
|
pyhw/__init__.py,sha256=IMjkMO3twhQzluVTo8Z6rE7Eg-9U79_LGKMcsWLKBkY,22
|
2
|
-
pyhw/__main__.py,sha256=
|
3
|
-
pyhw/macos.py,sha256=kF973QvtEFky4m8RnYTJ-HWPuJi3625tvnWqJAT_DHM,4598
|
2
|
+
pyhw/__main__.py,sha256=A0t0jkcwdTXd6ca7POUfm8krjCn2FQaXTIss5gNmNcI,1775
|
4
3
|
pyhw/backend/__init__.py,sha256=knn_3Yroow1h0dqdrozk3zyy3vz-kQyNBRjR6OLmVoY,50
|
5
4
|
pyhw/backend/backendBase.py,sha256=mloo8mPEbgbIdmyQ3I4vdEXMSSjxWi_wnwACmzvHbEo,506
|
6
5
|
pyhw/backend/cpu/__init__.py,sha256=5YfANJVRwNwTRodG0ENOgusrdN592aaSnfq5ok4dKTo,56
|
7
|
-
pyhw/backend/cpu/
|
6
|
+
pyhw/backend/cpu/bsd.py,sha256=Ls97NAsvZGVJj3_fBUcYXjY2gsZvFKhXYtkTHxVVXSs,288
|
7
|
+
pyhw/backend/cpu/cpuBase.py,sha256=u9kQORv8RJ9BLjG219wNTgBAivHy_lUll4Bkk6TBlXY,576
|
8
8
|
pyhw/backend/cpu/cpuInfo.py,sha256=A_nNGElq9W7oZ5DFJowLdFBE0ZvXKr5h29E6TGAvbRc,251
|
9
9
|
pyhw/backend/cpu/linux.py,sha256=zJ2cOwQHtolJrMMY1WXVbLLIRNPxeClUgzLAAkd7As4,3346
|
10
10
|
pyhw/backend/cpu/macos.py,sha256=pacU-yT7q-HKerkh2Q0BSdzSY6dKzHfSnRZBmimqqXk,2953
|
11
11
|
pyhw/backend/gpu/__init__.py,sha256=EpMjPvUaXt0LTNMvGmB8WgXbUB9keCxuOhu8NT3Re6o,56
|
12
|
-
pyhw/backend/gpu/
|
12
|
+
pyhw/backend/gpu/bsd.py,sha256=hNFiCek770CXOh3DK3I3-g272-a1S5D7LolGJBsLXaU,124
|
13
|
+
pyhw/backend/gpu/gpuBase.py,sha256=DyY1bVrsaWczkbrrN6J7kG-Kh9yic3Lqww8yLZNCet8,521
|
13
14
|
pyhw/backend/gpu/gpuInfo.py,sha256=d_z_z5DiZAg85wP0VOBQEU0QHdaK3qFqA2Tp9Eq8-Zs,133
|
14
15
|
pyhw/backend/gpu/linux.py,sha256=E-evoL-spQbHB8JvbZXSq5ypc2SeePVUPnhEQrSPQpg,1619
|
15
16
|
pyhw/backend/gpu/macos.py,sha256=SmTqqTrIMRW-GVPmDs8xAiOX7HsCjrGh9qkxLQCdvO8,3850
|
16
17
|
pyhw/backend/host/__init__.py,sha256=Efaj7-Oya7H8HdpZHQCLrwn-mcfPb-d6yfh4dzsE_7I,58
|
17
|
-
pyhw/backend/host/
|
18
|
+
pyhw/backend/host/bsd.py,sha256=9gKnM6yysHBKwS3EQvb0pCeylh3dzHvoEuPe14zo9wQ,382
|
19
|
+
pyhw/backend/host/hostBase.py,sha256=Dt3zZjkL6iUM9eOKkPUBAZ_2Lx-GQSIjsQhkLmjCUAk,678
|
18
20
|
pyhw/backend/host/hostInfo.py,sha256=Xvz0LugPiCSWMkcDsp4p2rrojYFZauL6Q-gCZ6NLz5k,184
|
19
|
-
pyhw/backend/host/linux.py,sha256=
|
21
|
+
pyhw/backend/host/linux.py,sha256=vGIl1b61vB-uilPk6awPOIWRaxnIsR43L20sNHeM5bI,2824
|
20
22
|
pyhw/backend/host/macos.py,sha256=KW-EJK9g1xHNrFsVxJv5GPLpc_ZevX0Zv1WjZUzRkzo,15369
|
21
23
|
pyhw/backend/host/windows.py,sha256=rjDJaIs-5zspzFsNCMCh6m2yZXEXI0vccqeBpmAdEBk,53
|
22
24
|
pyhw/backend/kernel/__init__.py,sha256=fGjwjpOhwA_PnsWbwoq102hwhTay2ufYKaTqxjSV2-I,65
|
23
|
-
pyhw/backend/kernel/kernelBase.py,sha256=
|
25
|
+
pyhw/backend/kernel/kernelBase.py,sha256=ZUj5wqar9mLUlIYrTDzyCWjrwzGtP6WJIIAXy5v1zhM,490
|
24
26
|
pyhw/backend/kernel/kernelInfo.py,sha256=QQYni0IVeFZ2IVNDC06U728Q01Rq3R6qRDYCxMjtJrY,189
|
25
27
|
pyhw/backend/kernel/unix.py,sha256=XDV2GIjamERcmlrQFaKFZY-OJO1xj76Im_7lmg2uFzo,1192
|
26
28
|
pyhw/backend/kernel/windows.py,sha256=lxZ7T9Ea0Qbq3pf_TjSAHSM2YTozC6ivv7dKdLOTl3s,58
|
27
29
|
pyhw/backend/memory/__init__.py,sha256=zGBWxfPAAk8ivCBWPLJIpuD-lB7wUJT3x8u2jHiAoCY,65
|
28
|
-
pyhw/backend/memory/
|
30
|
+
pyhw/backend/memory/bsd.py,sha256=GKTCs6RocdoWj-5ZZRMB4xAWGWljor6leuwX-L-7bW0,251
|
31
|
+
pyhw/backend/memory/linux.py,sha256=kxP0LxXdTWYRtu9nDyKqZeIzZrQI84kVOPMeN1GwSOo,917
|
29
32
|
pyhw/backend/memory/macos.py,sha256=ur2HxmmmVkXmaxEcw_otphifVp_csfNMJdgt-idCq7M,2770
|
30
|
-
pyhw/backend/memory/memoryBase.py,sha256=
|
33
|
+
pyhw/backend/memory/memoryBase.py,sha256=wl6zN3-U_jRNsaWM9szWPvWjiq3Ca8Rcm-aMRdAJge8,554
|
31
34
|
pyhw/backend/memory/memoryInfo.py,sha256=OQF165uEyuapAsi7cKacQYDRnKdrQHeldfyFwzS9N2g,186
|
32
35
|
pyhw/backend/metal/t.py,sha256=52yv-JoXNfaIOfcxEEidIg0MoyFtzWvTRm550kQKPZA,391
|
33
36
|
pyhw/backend/nic/__init__.py,sha256=eP4eOYIvMF3LcTf954hJa6TnB8R4Qahss2g-UcgypKY,57
|
34
|
-
pyhw/backend/nic/
|
37
|
+
pyhw/backend/nic/bsd.py,sha256=lIXnPqzSA2qexUt0P9OHMmxoI5c5XBi2V80RY9S0wsM,135
|
38
|
+
pyhw/backend/nic/linux.py,sha256=vS-bZSvPOjNaPLO6wyJHILVEsEVJJK2aQ4wUcXsgm74,1308
|
35
39
|
pyhw/backend/nic/macos.py,sha256=63gZjSmUGwGqfs41IWrEXmSz9O8eQy4G5oql3JLZmoo,855
|
36
|
-
pyhw/backend/nic/nicBase.py,sha256=
|
40
|
+
pyhw/backend/nic/nicBase.py,sha256=cT_rxqIEcvvKFsvjKlkCJ8RIfp7QHxDE9_SImXDae0s,735
|
37
41
|
pyhw/backend/nic/nicInfo.py,sha256=wuBuL-aIzD441IUDPGz5e0xctcZ-opdpgqkVxgbvZLg,133
|
38
42
|
pyhw/backend/npu/__init__.py,sha256=PgLKbwpgT5vw9xpa294Zxb94McyxNXW46_vMbT2Iqyc,58
|
39
|
-
pyhw/backend/npu/
|
43
|
+
pyhw/backend/npu/bsd.py,sha256=eKkOWZ4MBybR_KOGGcsWUpzCGgghhvuBy5VNsnEE8cI,134
|
44
|
+
pyhw/backend/npu/linux.py,sha256=mXHSYRION3pghwk6_4vgHxjSkNxI68ksGLkFZstR0mc,1192
|
40
45
|
pyhw/backend/npu/macos.py,sha256=mNnfvjjPQNlA-mViuhmfeb__uI1be93ZSZvv7PVD52s,1037
|
41
|
-
pyhw/backend/npu/npuBase.py,sha256=
|
46
|
+
pyhw/backend/npu/npuBase.py,sha256=qiioBmHDeh2Et1F7lwmNight-2W32C0VmMtx2DIOCz4,523
|
42
47
|
pyhw/backend/npu/npuInfo.py,sha256=82dK6XvW_XKw4O5-RfR4-qQRR7Plh8qqJLj0YDzISmU,135
|
43
48
|
pyhw/backend/os/__init__.py,sha256=rPHQYdQK3qU6ZwwodqVoEWeqBnKffXlJyi4k3-8ViPY,53
|
44
|
-
pyhw/backend/os/
|
49
|
+
pyhw/backend/os/bsd.py,sha256=5Q30mkFKdhuup1dRjTEVN58MEGcj7JzbUzh40ld6C14,131
|
50
|
+
pyhw/backend/os/linux.py,sha256=U7dIOKZaG5MSw0S65hAfDfFaBMvbwSCHFIHTwckU9iI,1957
|
45
51
|
pyhw/backend/os/macos.py,sha256=DwgpwRD1a2oTANR_XL3kkMzNawqrt23F79dqBw3ULK8,1906
|
46
|
-
pyhw/backend/os/osBase.py,sha256=
|
52
|
+
pyhw/backend/os/osBase.py,sha256=IiyrA5IEtlcaR-xigi8SxD70BimFKCBMjgF0MLihSOk,573
|
47
53
|
pyhw/backend/os/osInfo.py,sha256=iLPc7INFHH3izascwooj4JBVgvBsSgVPXWBlFXG47mQ,378
|
48
54
|
pyhw/backend/shell/__init__.py,sha256=SeQ7OLNSl_V1JCCWnJGjLilAWiSe9e5kgsMEt63TMS0,62
|
49
|
-
pyhw/backend/shell/shellBase.py,sha256=
|
50
|
-
pyhw/backend/shell/unix.py,sha256=
|
55
|
+
pyhw/backend/shell/shellBase.py,sha256=U4HPg_iWhAqaLceBnEVMHFj4A-FNYu7JjsQyi2seEU4,377
|
56
|
+
pyhw/backend/shell/unix.py,sha256=Vt2wSxAIrzN679v0MjJwBoK6L12OqZOichociFZ9lw8,2109
|
51
57
|
pyhw/backend/title/__init__.py,sha256=l6_WqreSBeK7krapCrbrr4ndnydrXB1aZ50Ve-beV_w,62
|
52
|
-
pyhw/backend/title/titleBase.py,sha256=
|
58
|
+
pyhw/backend/title/titleBase.py,sha256=nzHcVJqAMZqWJP101YWgRwilSiZ_hHiK-jiI90Pm3r8,495
|
53
59
|
pyhw/backend/title/unix.py,sha256=9B-zLE8yhlWBnJ-6Aa-DmFmgMV9KdvvNU40drJIaNck,837
|
54
60
|
pyhw/backend/title/windows.py,sha256=5bXR6yxHk3diVx92sjxPeD6fUVR5sKZJG3K4aM3CGn8,82
|
55
61
|
pyhw/backend/uptime/__init__.py,sha256=X8RVhHWmHpyey0C4gcmrt_u1cHKowhAQRDMAxY3i7p0,65
|
62
|
+
pyhw/backend/uptime/bsd.py,sha256=XdLIvivr78Pr8PqSwQG3eLvjjaM52nK5QcWrwtuNZlg,147
|
56
63
|
pyhw/backend/uptime/linux.py,sha256=Sh05CgUjAOzPM8LSoZf4fCU-Cl5pwhSJSC7XJ-jFaHU,1027
|
57
|
-
pyhw/backend/uptime/macos.py,sha256=
|
58
|
-
pyhw/backend/uptime/uptimeBase.py,sha256=
|
64
|
+
pyhw/backend/uptime/macos.py,sha256=Io-JrFjmRWHgB7uh4mBTV4rnfJuUvepGh2uiKNhUZcc,1293
|
65
|
+
pyhw/backend/uptime/uptimeBase.py,sha256=PB0SWpsZyNz5GL5n39rC7DDSpKVAlH2K2eKqOuiEfy0,778
|
59
66
|
pyhw/backend/uptime/uptimeInfo.py,sha256=TobPEV3MBT3Fiv3W6TOzD3a4MNW-vz2Oi_Trlcihu7k,114
|
60
67
|
pyhw/frontend/__init__.py,sha256=xgv_iVv9w4cLXklbdtFWXu7J7KJxBCUw-ZcUQb_abFc,57
|
61
|
-
pyhw/frontend/frontendBase.py,sha256=
|
68
|
+
pyhw/frontend/frontendBase.py,sha256=rPAf7tE1u8uGgZ-mDTOw_O2S2-YsevEzGJsq34eJlXQ,4957
|
62
69
|
pyhw/frontend/color/__init__.py,sha256=xk511qWwdYWEVjk_zOaC4fs81HtwR4ELr3wi1tTL824,191
|
63
|
-
pyhw/frontend/color/colorConfig.py,sha256=
|
70
|
+
pyhw/frontend/color/colorConfig.py,sha256=6VADbaM_xwlYF4Ds38xvmRgxVSDWBB71WWDFhiLrQaI,4650
|
64
71
|
pyhw/frontend/color/colorSet.py,sha256=spH8PlRu7capouf-yUgDHgoPCnM5aJ_ncascISZfz2g,1421
|
65
72
|
pyhw/frontend/color/colorUtil.py,sha256=VhcPmAJmXGIiRBfVZE2jg_iy-SfbxqwOSvkRz-nbUOQ,94
|
66
73
|
pyhw/frontend/logo/__init__.py,sha256=mozEarHueBUgtDHKSd-RDaFysMLUiW3VQ8KcBtlKGCI,47
|
@@ -72,6 +79,7 @@ pyhw/frontend/logo/ascii/centos.pyhw,sha256=t-pFKQslIAKN4Jl1ilKLzB79BHSi0_zaJUDG
|
|
72
79
|
pyhw/frontend/logo/ascii/debian.pyhw,sha256=ZmO1fg3Uc_ofF-CZSOP0Qo298luDASh2Zt50UmY6DBQ,437
|
73
80
|
pyhw/frontend/logo/ascii/fedora.pyhw,sha256=IuFE6BByaNfVgn1pn7rKH7QVlIJyEmgGopCAOpXa6oM,742
|
74
81
|
pyhw/frontend/logo/ascii/fedora_small.pyhw,sha256=_LSBzuCJjMa8pzmiJ3KN7Ndi-TryYPmtEfKqxxPAFfE,601
|
82
|
+
pyhw/frontend/logo/ascii/freebsd.pyhw,sha256=Socjz8LCxWDpIaFjfISHX5TjlmWLtXTYqci6-m6hzJY,514
|
75
83
|
pyhw/frontend/logo/ascii/linux.pyhw,sha256=IMe6YNElwCjLtv6kgSkERbATyyJAK531vcrT-otaLWE,300
|
76
84
|
pyhw/frontend/logo/ascii/macOS.pyhw,sha256=HBGROtBb7wrNtRqAQ9ND7zxK0l17BRsmpgc2dMo_m6s,474
|
77
85
|
pyhw/frontend/logo/ascii/raspbian.pyhw,sha256=jEl6WMKF-FGx359ipQ1kzweUJS-NuauYQCFaYime4PQ,159
|
@@ -81,11 +89,11 @@ pyhw/library/lib/iokitGPULib.dylib,sha256=DcJ0GZY79gTFckLFYtZgeKn1T0NFvdO_k_ccCa
|
|
81
89
|
pyhw/pyhwException/__init__.py,sha256=8JsFvtF13g0Y5t4z9fRndDXtfCzuBM59jDf6PhWSFSk,220
|
82
90
|
pyhw/pyhwException/pyhwException.py,sha256=wxuzFQa9g7XB1q9TUKO_55lw7wMEJMpzG8w1GVTFVa0,197
|
83
91
|
pyhw/pyhwUtil/__init__.py,sha256=diIqlNUBfuHu-2VAOJk5nipGLafnWxR3chAAOmX8QRo,250
|
84
|
-
pyhw/pyhwUtil/pyhwUtil.py,sha256=
|
92
|
+
pyhw/pyhwUtil/pyhwUtil.py,sha256=X8m49FHR56QLmkF2rJodH9wtpLZWYrRs9Hc7lBD3G_s,6297
|
85
93
|
pyhw/pyhwUtil/sysctlUtil.py,sha256=S-rUvqi7ZrMyMouIhxlyHEQ4agM7sCT1Y7uzs3Hu5-o,841
|
86
|
-
pyhw-0.
|
87
|
-
pyhw-0.
|
88
|
-
pyhw-0.
|
89
|
-
pyhw-0.
|
90
|
-
pyhw-0.
|
91
|
-
pyhw-0.
|
94
|
+
pyhw-0.7.0.dist-info/LICENSE,sha256=hJs6RBqSVCexbTsalkMLNFI5t06kekQEsSVaOt_-yLs,1497
|
95
|
+
pyhw-0.7.0.dist-info/METADATA,sha256=fI3DwfOv4xwuWSCuJSa_4yIb1gTGQ-VHyDA3Gq25TcM,5430
|
96
|
+
pyhw-0.7.0.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
|
97
|
+
pyhw-0.7.0.dist-info/entry_points.txt,sha256=q-AB8im_QahpmNrmy4aPTJRGi0LlbNlnI3kF7s6pKss,44
|
98
|
+
pyhw-0.7.0.dist-info/top_level.txt,sha256=7Inxvxt1TngEricKZEex9_WJZS3DbKYFUXDz4v5WHYU,5
|
99
|
+
pyhw-0.7.0.dist-info/RECORD,,
|
pyhw/macos.py
DELETED
@@ -1,146 +0,0 @@
|
|
1
|
-
import subprocess
|
2
|
-
import json
|
3
|
-
import platform
|
4
|
-
from pyhwException import GPUNotFoundException, BackendException
|
5
|
-
|
6
|
-
|
7
|
-
class GPUInfo:
|
8
|
-
def __init__(self, verbose=False):
|
9
|
-
self._gpus = list()
|
10
|
-
self._verbose = verbose
|
11
|
-
|
12
|
-
def init(self):
|
13
|
-
pass
|
14
|
-
|
15
|
-
def _get_gpu_info(self):
|
16
|
-
try:
|
17
|
-
gpus = json.loads(subprocess.check_output(["system_profiler", "SPDisplaysDataType", "-json"])).get('SPDisplaysDataType')
|
18
|
-
if gpus is not None:
|
19
|
-
if self._verbose:
|
20
|
-
print(f"Detected {len(gpus)} GPU(s).")
|
21
|
-
else:
|
22
|
-
raise GPUNotFoundException("No GPU information found.")
|
23
|
-
except Exception as e:
|
24
|
-
raise BackendException(f"An error occurred while getting GPU info: {e}")
|
25
|
-
|
26
|
-
gpu_info_list = list()
|
27
|
-
|
28
|
-
for i in range(len(gpus)):
|
29
|
-
gpu = gpus[i]
|
30
|
-
info = dict()
|
31
|
-
info["name"] = gpu.get("sppci_model")
|
32
|
-
if gpu.get("spdisplays_vendor") == "sppci_vendor_Apple":
|
33
|
-
info["vram"] = f"{get_mem_info()} (shared memory)"
|
34
|
-
else:
|
35
|
-
info["vram"] = gpu.get("spdisplays_vram")
|
36
|
-
info["vendor"] = gpu.get("spdisplays_vendor")
|
37
|
-
info["cores"] = gpu.get("sppci_cores")
|
38
|
-
info["metal"] = gpu.get("spdisplays_mtlgpufamilysupport")
|
39
|
-
info["bus"] = gpu.get("sppci_bus")
|
40
|
-
info["link"] = gpu.get("spdisplays_pcie_width")
|
41
|
-
gpu_info_list.append(info)
|
42
|
-
|
43
|
-
@staticmethod
|
44
|
-
def _handleVendor(vendor):
|
45
|
-
if vendor == "sppci_vendor_Apple":
|
46
|
-
return "Apple"
|
47
|
-
elif vendor == "sppci_vendor_intel":
|
48
|
-
return "Intel"
|
49
|
-
elif vendor == "sppci_vendor_amd":
|
50
|
-
return "AMD"
|
51
|
-
else:
|
52
|
-
return vendor
|
53
|
-
|
54
|
-
@staticmethod
|
55
|
-
def _handleVram(vram, vendor):
|
56
|
-
if vendor == "Apple":
|
57
|
-
return f"{get_mem_info()} (shared memory)"
|
58
|
-
else:
|
59
|
-
return vram
|
60
|
-
|
61
|
-
@staticmethod
|
62
|
-
def _getVramApple():
|
63
|
-
try:
|
64
|
-
return json.loads(subprocess.check_output(["system_profiler", "SPHardwareDataType", "-json"]))["SPHardwareDataType"][0]["physical_memory"]
|
65
|
-
except Exception as e:
|
66
|
-
raise BackendException(f"An error occurred while getting memory info: {e}")
|
67
|
-
|
68
|
-
|
69
|
-
class GPU:
|
70
|
-
def __init__(self):
|
71
|
-
self._name = str()
|
72
|
-
self._vram = str()
|
73
|
-
self._vendor = str()
|
74
|
-
self._cores = str()
|
75
|
-
self._metal = str()
|
76
|
-
self._bus = str()
|
77
|
-
self._bus_width = str()
|
78
|
-
self._id = int()
|
79
|
-
|
80
|
-
def init(self):
|
81
|
-
pass
|
82
|
-
|
83
|
-
def _get_gpu_info(self):
|
84
|
-
pass
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
def get_mem_info():
|
90
|
-
try:
|
91
|
-
mem_info_dict = json.loads(subprocess.check_output(["system_profiler", "SPHardwareDataType", "-json"]))
|
92
|
-
mem_info = mem_info_dict["SPHardwareDataType"][0]["physical_memory"]
|
93
|
-
return mem_info
|
94
|
-
except Exception as e:
|
95
|
-
print(f"An error occurred while getting memory info: {e}")
|
96
|
-
exit(-1)
|
97
|
-
|
98
|
-
|
99
|
-
def get_gpu_info():
|
100
|
-
gpus = list()
|
101
|
-
try:
|
102
|
-
gpu_info_dict = json.loads(subprocess.check_output(["system_profiler", "SPDisplaysDataType", "-json"]))
|
103
|
-
if 'SPDisplaysDataType' in gpu_info_dict:
|
104
|
-
gpus = gpu_info_dict['SPDisplaysDataType']
|
105
|
-
print(f"Detected {len(gpus)} GPU(s).")
|
106
|
-
else:
|
107
|
-
print("No GPU information found.")
|
108
|
-
except Exception as e:
|
109
|
-
print(f"An error occurred while getting GPU info: {e}")
|
110
|
-
exit(-1)
|
111
|
-
|
112
|
-
gpu_info_list = list()
|
113
|
-
|
114
|
-
for i in range(len(gpus)):
|
115
|
-
gpu = gpus[i]
|
116
|
-
info = dict()
|
117
|
-
info["name"] = gpu.get("sppci_model")
|
118
|
-
if gpu.get("spdisplays_vendor") == "sppci_vendor_Apple":
|
119
|
-
info["vram"] = f"{get_mem_info()} (shared memory)"
|
120
|
-
else:
|
121
|
-
info["vram"] = gpu.get("spdisplays_vram")
|
122
|
-
info["vendor"] = gpu.get("spdisplays_vendor")
|
123
|
-
info["cores"] = gpu.get("sppci_cores")
|
124
|
-
info["metal"] = gpu.get("spdisplays_mtlgpufamilysupport")
|
125
|
-
info["bus"] = gpu.get("sppci_bus")
|
126
|
-
info["link"] = gpu.get("spdisplays_pcie_width")
|
127
|
-
gpu_info_list.append(info)
|
128
|
-
return gpu_info_list
|
129
|
-
|
130
|
-
|
131
|
-
if __name__ == "__main__":
|
132
|
-
li = get_gpu_info()
|
133
|
-
for i in range(len(li)):
|
134
|
-
info = li[i]
|
135
|
-
print('----------')
|
136
|
-
print(f"GPU {i}:")
|
137
|
-
print(f'name: {info["name"]}')
|
138
|
-
print(f'vram: {info["vram"]}')
|
139
|
-
print(f'vendor: {info["vendor"]}')
|
140
|
-
print(f'cores: {info["cores"]}')
|
141
|
-
print(f'metal: {info["metal"]}')
|
142
|
-
print(f'bus: {info["bus"]}')
|
143
|
-
print(f'link: {info["link"]}')
|
144
|
-
|
145
|
-
print('----------')
|
146
|
-
|
File without changes
|
File without changes
|
File without changes
|