pyhw 0.1.0b0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pyhw/__init__.py +1 -0
- pyhw/__main__.py +37 -0
- pyhw/backend/__init__.py +3 -0
- pyhw/backend/backendBase.py +21 -0
- pyhw/backend/cpu/__init__.py +3 -0
- pyhw/backend/cpu/cpuBase.py +13 -0
- pyhw/backend/cpu/linux.py +56 -0
- pyhw/backend/gpu/__init__.py +3 -0
- pyhw/backend/gpu/gpuBase.py +12 -0
- pyhw/backend/gpu/linux.py +43 -0
- pyhw/backend/host/__init__.py +3 -0
- pyhw/backend/host/hostBase.py +19 -0
- pyhw/backend/host/linux.py +50 -0
- pyhw/backend/host/macos.py +5 -0
- pyhw/backend/host/windows.py +5 -0
- pyhw/backend/kernel/__init__.py +3 -0
- pyhw/backend/kernel/kernelBase.py +17 -0
- pyhw/backend/kernel/linux.py +47 -0
- pyhw/backend/kernel/macos.py +7 -0
- pyhw/backend/kernel/windows.py +7 -0
- pyhw/backend/memory/__init__.py +3 -0
- pyhw/backend/memory/linux.py +32 -0
- pyhw/backend/memory/memoryBase.py +12 -0
- pyhw/backend/metal/t.py +19 -0
- pyhw/backend/os/__init__.py +3 -0
- pyhw/backend/os/linux.py +62 -0
- pyhw/backend/os/osBase.py +13 -0
- pyhw/backend/shell/__init__.py +3 -0
- pyhw/backend/shell/shellBase.py +13 -0
- pyhw/backend/shell/unix.py +56 -0
- pyhw/backend/title/__init__.py +3 -0
- pyhw/backend/title/titleBase.py +16 -0
- pyhw/backend/title/unix.py +33 -0
- pyhw/backend/title/windows.py +8 -0
- pyhw/backend/uptime/__init__.py +3 -0
- pyhw/backend/uptime/linux.py +36 -0
- pyhw/backend/uptime/uptimeBase.py +20 -0
- pyhw/frontend/__init__.py +3 -0
- pyhw/frontend/color/__init__.py +5 -0
- pyhw/frontend/color/colorConfig.py +90 -0
- pyhw/frontend/color/colorSet.py +58 -0
- pyhw/frontend/color/colorUtil.py +6 -0
- pyhw/frontend/frontendBase.py +69 -0
- pyhw/frontend/logo/__init__.py +3 -0
- pyhw/frontend/logo/ascii/debian.pyhw +17 -0
- pyhw/frontend/logo/ascii/fedora.pyhw +19 -0
- pyhw/frontend/logo/ascii/linux.pyhw +12 -0
- pyhw/frontend/logo/ascii/macOS.pyhw +17 -0
- pyhw/frontend/logo/ascii/ubuntu.pyhw +20 -0
- pyhw/frontend/logo/logoBase.py +22 -0
- pyhw/macos.py +146 -0
- pyhw/pyhwException/__init__.py +3 -0
- pyhw/pyhwException/pyhwException.py +14 -0
- pyhw/pyhwUtil/__init__.py +3 -0
- pyhw/pyhwUtil/pyhwUtil.py +50 -0
- pyhw-0.1.0b0.dist-info/LICENSE +28 -0
- pyhw-0.1.0b0.dist-info/METADATA +42 -0
- pyhw-0.1.0b0.dist-info/RECORD +61 -0
- pyhw-0.1.0b0.dist-info/WHEEL +5 -0
- pyhw-0.1.0b0.dist-info/entry_points.txt +2 -0
- pyhw-0.1.0b0.dist-info/top_level.txt +1 -0
pyhw/__init__.py
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
__version__ = '0.1.0'
|
pyhw/__main__.py
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
from .frontend import Printer
|
2
|
+
from .backend import Data
|
3
|
+
from .backend.title import TitleDetect
|
4
|
+
from .backend.host import HostDetect
|
5
|
+
from .backend.kernel import KernelDetect
|
6
|
+
from .backend.shell import ShellDetect
|
7
|
+
from .backend.uptime import UptimeDetect
|
8
|
+
from .backend.os import OSDetect
|
9
|
+
from .backend.cpu import CPUDetect
|
10
|
+
from .backend.gpu import GPUDetect
|
11
|
+
from .backend.memory import MemoryDetect
|
12
|
+
from .pyhwUtil import createDataString
|
13
|
+
from .pyhwUtil import getOS
|
14
|
+
|
15
|
+
|
16
|
+
def main():
|
17
|
+
print("This is a test version of PyHw. Currently, it only supports Linux.")
|
18
|
+
if getOS() != "linux":
|
19
|
+
print(f"Only Linux is supported for now. Current os: {getOS()}")
|
20
|
+
return
|
21
|
+
data = Data()
|
22
|
+
data.title = TitleDetect(os="linux").getTitle().title
|
23
|
+
data.Host = HostDetect(os="linux").getHostInfo().model
|
24
|
+
data.Kernel = KernelDetect(os="linux").getKernelInfo().kernel
|
25
|
+
data.Shell = ShellDetect(os="linux").getShellInfo().info
|
26
|
+
data.Uptime = UptimeDetect(os="linux").getUptime().uptime
|
27
|
+
data.OS = OSDetect(os="linux").getOSInfo().prettyName
|
28
|
+
data.CPU = CPUDetect(os="linux").getCPUInfo().cpu
|
29
|
+
if GPUDetect(os="linux").getGPUInfo().number > 0:
|
30
|
+
data.GPU = GPUDetect(os="linux").getGPUInfo().gpus
|
31
|
+
data.Memory = MemoryDetect(os="linux").getMemoryInfo().memory
|
32
|
+
|
33
|
+
Printer(logo_os=OSDetect(os="linux").getOSInfo().id, data=createDataString(data)).cPrint()
|
34
|
+
|
35
|
+
|
36
|
+
if __name__ == "__main__":
|
37
|
+
main()
|
pyhw/backend/__init__.py
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
from dataclasses import dataclass
|
2
|
+
|
3
|
+
|
4
|
+
@dataclass
|
5
|
+
class Data:
|
6
|
+
title = "Default Value"
|
7
|
+
underline = "Default Value"
|
8
|
+
OS = "Default Value"
|
9
|
+
Host = "Default Value"
|
10
|
+
Kernel = "Default Value"
|
11
|
+
Uptime = "Default Value"
|
12
|
+
# Packages = ""
|
13
|
+
Shell = "Default Value"
|
14
|
+
# Resolution = ""
|
15
|
+
# DE = ""
|
16
|
+
# WM = ""
|
17
|
+
# WM_Theme = ""
|
18
|
+
# Terminal = ""
|
19
|
+
CPU = "Default Value"
|
20
|
+
GPU = ["Default Value"]
|
21
|
+
Memory = "Default Value"
|
@@ -0,0 +1,13 @@
|
|
1
|
+
from .linux import CPUDetectLinux
|
2
|
+
from ...pyhwException import OSUnsupportedException
|
3
|
+
|
4
|
+
|
5
|
+
class CPUDetect:
|
6
|
+
def __init__(self, os):
|
7
|
+
self.OS = os
|
8
|
+
|
9
|
+
def getCPUInfo(self):
|
10
|
+
if self.OS == "linux":
|
11
|
+
return CPUDetectLinux().getCPUInfo()
|
12
|
+
else:
|
13
|
+
raise OSUnsupportedException("Unsupported operating system")
|
@@ -0,0 +1,56 @@
|
|
1
|
+
from dataclasses import dataclass
|
2
|
+
import re
|
3
|
+
import os
|
4
|
+
|
5
|
+
|
6
|
+
@dataclass
|
7
|
+
class CPUInfoLinux:
|
8
|
+
cpu = ""
|
9
|
+
model = ""
|
10
|
+
cores = ""
|
11
|
+
frequency = ""
|
12
|
+
|
13
|
+
|
14
|
+
class CPUDetectLinux:
|
15
|
+
def __init__(self):
|
16
|
+
self.__cpuInfo = CPUInfoLinux()
|
17
|
+
|
18
|
+
def getCPUInfo(self):
|
19
|
+
self.__getCPUInfo()
|
20
|
+
if self.__cpuInfo.model != "":
|
21
|
+
self.__cpuInfo.cpu = self.__cpuInfo.model
|
22
|
+
if self.__cpuInfo.cores != "":
|
23
|
+
self.__cpuInfo.cpu += f" ({self.__cpuInfo.cores})"
|
24
|
+
if self.__cpuInfo.frequency != "":
|
25
|
+
self.__cpuInfo.cpu += f" @ {self.__cpuInfo.frequency}"
|
26
|
+
return self.__cpuInfo
|
27
|
+
|
28
|
+
def __getCPUInfo(self):
|
29
|
+
try:
|
30
|
+
with open("/proc/cpuinfo", "r") as f:
|
31
|
+
cpu_info = f.read()
|
32
|
+
except FileNotFoundError:
|
33
|
+
return
|
34
|
+
for line in cpu_info.split("\n"):
|
35
|
+
if (line.startswith("model name") or line.startswith("Hardware") or line.startswith("Processor") or
|
36
|
+
line.startswith("cpu model") or line.startswith("chip type") or line.startswith("cpu type")):
|
37
|
+
model = line.split(":")[1].strip()
|
38
|
+
if "@" in model:
|
39
|
+
self.__cpuInfo.model = model.split("@")[0].strip()
|
40
|
+
self.__cpuInfo.frequency = model.split("@")[1].strip()
|
41
|
+
else:
|
42
|
+
self.__cpuInfo.model = model
|
43
|
+
break
|
44
|
+
self.__cpuInfo.cores = len(re.findall(r"processor", cpu_info))
|
45
|
+
if self.__cpuInfo.frequency == "":
|
46
|
+
if os.path.exists("/sys/devices/system/cpu/cpu0/cpufreq"):
|
47
|
+
try:
|
48
|
+
with open("/sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq", "r") as f:
|
49
|
+
self.__cpuInfo.frequency = f"{int(f.read()) / 1000 / 1000} Ghz" # Ghz
|
50
|
+
except FileNotFoundError:
|
51
|
+
pass
|
52
|
+
else:
|
53
|
+
for line in cpu_info.split("\n"):
|
54
|
+
if line.startswith("cpu MHz") or line.startswith("clock"):
|
55
|
+
self.__cpuInfo.frequency = float(line.split(":")[1].strip()) / 1000 # Ghz
|
56
|
+
break
|
@@ -0,0 +1,12 @@
|
|
1
|
+
from .linux import GPUDetectLinux
|
2
|
+
|
3
|
+
|
4
|
+
class GPUDetect:
|
5
|
+
def __init__(self, os):
|
6
|
+
self.OS = os
|
7
|
+
|
8
|
+
def getGPUInfo(self):
|
9
|
+
if self.OS == "linux":
|
10
|
+
return GPUDetectLinux().getGPUInfo()
|
11
|
+
else:
|
12
|
+
raise NotImplementedError("Unsupported operating system")
|
@@ -0,0 +1,43 @@
|
|
1
|
+
import subprocess
|
2
|
+
from dataclasses import dataclass
|
3
|
+
from ..cpu import CPUDetect
|
4
|
+
from ...pyhwUtil import getArch
|
5
|
+
|
6
|
+
|
7
|
+
@dataclass
|
8
|
+
class GPUInfoLinux:
|
9
|
+
number = 0
|
10
|
+
gpus = []
|
11
|
+
|
12
|
+
|
13
|
+
class GPUDetectLinux:
|
14
|
+
def __init__(self):
|
15
|
+
self.__gpuInfo = GPUInfoLinux()
|
16
|
+
|
17
|
+
def getGPUInfo(self):
|
18
|
+
self.__getGPUInfo()
|
19
|
+
return self.__gpuInfo
|
20
|
+
|
21
|
+
def __getGPUInfo(self):
|
22
|
+
try:
|
23
|
+
pci_info = subprocess.run(["bash", "-c", "lspci"], capture_output=True, text=True).stdout.strip()
|
24
|
+
except subprocess.SubprocessError:
|
25
|
+
return
|
26
|
+
if len(pci_info) == 0: # no pcie devices found
|
27
|
+
self.__handleNonePciDevices()
|
28
|
+
for line in pci_info.split("\n"):
|
29
|
+
if "VGA" in line or "Display" in line or "3D" in line:
|
30
|
+
gpu = line.split(": ")[1]
|
31
|
+
self.__gpuInfo.gpus.append(gpu)
|
32
|
+
self.__gpuInfo.number += 1
|
33
|
+
if self.__gpuInfo.number == 0:
|
34
|
+
self.__handleNonePciDevices() # fallback to a sbc device detection method
|
35
|
+
|
36
|
+
def __handleNonePciDevices(self):
|
37
|
+
# if detector can't find any VGA/Display/3D GPUs, assume the host is a sbc device, this function is a placeholder for a more advanced method.
|
38
|
+
if getArch() == "aarch64" or getArch() == "arm32":
|
39
|
+
self.__gpuInfo.number = 1
|
40
|
+
self.__gpuInfo.gpus.append(f"{CPUDetect(os='linux').getCPUInfo().model} (SOC Integrated Graphics)")
|
41
|
+
else:
|
42
|
+
self.__gpuInfo.number = 1
|
43
|
+
self.__gpuInfo.gpus.append("Not found")
|
@@ -0,0 +1,19 @@
|
|
1
|
+
from .linux import HostDetectLinux
|
2
|
+
from .macos import HostDetectMacOS
|
3
|
+
from .windows import HostDetectWindows
|
4
|
+
from ...pyhwException import OSUnsupportedException
|
5
|
+
|
6
|
+
|
7
|
+
class HostDetect:
|
8
|
+
def __init__(self, os):
|
9
|
+
self.OS = os
|
10
|
+
|
11
|
+
def getHostInfo(self):
|
12
|
+
if self.OS == "linux":
|
13
|
+
return HostDetectLinux().getHostInfo()
|
14
|
+
elif self.OS == "macos":
|
15
|
+
pass
|
16
|
+
elif self.OS == "windows":
|
17
|
+
pass
|
18
|
+
else:
|
19
|
+
raise OSUnsupportedException("Unsupported operating system")
|
@@ -0,0 +1,50 @@
|
|
1
|
+
"""
|
2
|
+
In dev.
|
3
|
+
"""
|
4
|
+
from ...pyhwUtil import getArch
|
5
|
+
from dataclasses import dataclass
|
6
|
+
|
7
|
+
|
8
|
+
@dataclass
|
9
|
+
class HostInfoLinux:
|
10
|
+
model = ""
|
11
|
+
family = ""
|
12
|
+
name = ""
|
13
|
+
version = ""
|
14
|
+
sku = ""
|
15
|
+
serial = ""
|
16
|
+
uuid = ""
|
17
|
+
vendor = ""
|
18
|
+
|
19
|
+
|
20
|
+
class HostDetectLinux:
|
21
|
+
def __init__(self):
|
22
|
+
self.__hostInfo = HostInfoLinux()
|
23
|
+
self.__arch = getArch()
|
24
|
+
|
25
|
+
def getHostInfo(self):
|
26
|
+
self.__getModel()
|
27
|
+
return self.__hostInfo
|
28
|
+
|
29
|
+
def __getModel(self):
|
30
|
+
if self.__arch in ["x86_64", "x86"]:
|
31
|
+
try:
|
32
|
+
with open("/sys/devices/virtual/dmi/id/product_name", "r") as f:
|
33
|
+
self.__hostInfo.name = f.read().strip()
|
34
|
+
with open("/sys/devices/virtual/dmi/id/product_version", "r") as f:
|
35
|
+
self.__hostInfo.version = f.read().strip()
|
36
|
+
self.__hostInfo.model = self.__hostInfo.name + " " + self.__hostInfo.version
|
37
|
+
except FileNotFoundError:
|
38
|
+
pass
|
39
|
+
elif self.__arch in ["aarch64", "arm32"]:
|
40
|
+
try:
|
41
|
+
with open("/sys/firmware/devicetree/base/model", "r") as f:
|
42
|
+
self.__hostInfo.model = f.read().strip()
|
43
|
+
except FileNotFoundError:
|
44
|
+
pass
|
45
|
+
|
46
|
+
def __getHostFamily(self):
|
47
|
+
pass
|
48
|
+
|
49
|
+
def __getHostProductName(self):
|
50
|
+
pass
|
@@ -0,0 +1,17 @@
|
|
1
|
+
from .linux import KernelDetectLinux
|
2
|
+
from ...pyhwException import OSUnsupportedException
|
3
|
+
|
4
|
+
|
5
|
+
class KernelDetect:
|
6
|
+
def __init__(self, os):
|
7
|
+
self.OS = os
|
8
|
+
|
9
|
+
def getKernelInfo(self):
|
10
|
+
if self.OS == "linux":
|
11
|
+
return KernelDetectLinux().getKernelInfo()
|
12
|
+
elif self.OS == "macos":
|
13
|
+
pass
|
14
|
+
elif self.OS == "windows":
|
15
|
+
pass
|
16
|
+
else:
|
17
|
+
raise OSUnsupportedException("Unsupported operating system")
|
@@ -0,0 +1,47 @@
|
|
1
|
+
"""
|
2
|
+
In dev.
|
3
|
+
"""
|
4
|
+
from dataclasses import dataclass
|
5
|
+
import subprocess
|
6
|
+
|
7
|
+
|
8
|
+
@dataclass
|
9
|
+
class KernelInfoLinux:
|
10
|
+
name = ""
|
11
|
+
version = ""
|
12
|
+
machine = ""
|
13
|
+
kernel = ""
|
14
|
+
|
15
|
+
|
16
|
+
class KernelDetectLinux:
|
17
|
+
def __init__(self):
|
18
|
+
self.__kernelInfo = KernelInfoLinux()
|
19
|
+
|
20
|
+
def getKernelInfo(self):
|
21
|
+
self.__getKernelName()
|
22
|
+
self.__getKernelVersion()
|
23
|
+
self.__getKernelMachine()
|
24
|
+
self.__kernelInfo.kernel = self.__kernelInfo.name + " " + self.__kernelInfo.version + " " + self.__kernelInfo.machine
|
25
|
+
return self.__kernelInfo
|
26
|
+
|
27
|
+
def __getKernelName(self):
|
28
|
+
try:
|
29
|
+
result = subprocess.run(['uname', '-s'], capture_output=True, text=True)
|
30
|
+
self.__kernelInfo.name = result.stdout.strip()
|
31
|
+
except subprocess.SubprocessError:
|
32
|
+
pass
|
33
|
+
|
34
|
+
def __getKernelVersion(self):
|
35
|
+
try:
|
36
|
+
result = subprocess.run(['uname', '-r'], capture_output=True, text=True)
|
37
|
+
self.__kernelInfo.version = result.stdout.strip()
|
38
|
+
except subprocess.SubprocessError:
|
39
|
+
pass
|
40
|
+
|
41
|
+
def __getKernelMachine(self):
|
42
|
+
try:
|
43
|
+
result = subprocess.run(['uname', '-m'], capture_output=True, text=True)
|
44
|
+
self.__kernelInfo.machine = result.stdout.strip()
|
45
|
+
except subprocess.SubprocessError:
|
46
|
+
pass
|
47
|
+
|
@@ -0,0 +1,32 @@
|
|
1
|
+
from dataclasses import dataclass
|
2
|
+
|
3
|
+
|
4
|
+
@dataclass
|
5
|
+
class MemoryInfoLinux:
|
6
|
+
memory = ""
|
7
|
+
total = 0
|
8
|
+
available = 0
|
9
|
+
used = 0
|
10
|
+
|
11
|
+
|
12
|
+
class MemoryDetectLinux:
|
13
|
+
def __init__(self):
|
14
|
+
self.__memoryInfo = MemoryInfoLinux()
|
15
|
+
|
16
|
+
def getMemoryInfo(self):
|
17
|
+
self.__getMemory()
|
18
|
+
self.__memoryInfo.memory = f"{self.__memoryInfo.used} MiB / {self.__memoryInfo.total} MiB"
|
19
|
+
return self.__memoryInfo
|
20
|
+
|
21
|
+
def __getMemory(self):
|
22
|
+
try:
|
23
|
+
with open("/proc/meminfo", "r") as file:
|
24
|
+
for line in file:
|
25
|
+
if line.startswith("MemTotal:"):
|
26
|
+
self.__memoryInfo.total = round(float(line.split(":")[1].strip()[:-3]) / 1024, 2)
|
27
|
+
elif line.startswith("MemAvailable:"):
|
28
|
+
self.__memoryInfo.available = round(float(line.split(":")[1].strip()[:-3]) / 1024, 2)
|
29
|
+
self.__memoryInfo.used = round(self.__memoryInfo.total - self.__memoryInfo.available, 2)
|
30
|
+
except FileNotFoundError:
|
31
|
+
pass
|
32
|
+
|
@@ -0,0 +1,12 @@
|
|
1
|
+
from .linux import MemoryDetectLinux
|
2
|
+
|
3
|
+
|
4
|
+
class MemoryDetect:
|
5
|
+
def __init__(self, os):
|
6
|
+
self.OS = os
|
7
|
+
|
8
|
+
def getMemoryInfo(self):
|
9
|
+
if self.OS == "linux":
|
10
|
+
return MemoryDetectLinux().getMemoryInfo()
|
11
|
+
else:
|
12
|
+
raise NotImplementedError("Unsupported operating system")
|
pyhw/backend/metal/t.py
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
import ctypes
|
2
|
+
|
3
|
+
|
4
|
+
mylib = ctypes.CDLL('./metalGPULib.dylib')
|
5
|
+
|
6
|
+
mylib.backend_init.argtypes = []
|
7
|
+
mylib.backend_init.restype = None
|
8
|
+
|
9
|
+
mylib.get_default_device_name.argtypes = []
|
10
|
+
mylib.get_default_device_name.restype = ctypes.c_char_p
|
11
|
+
|
12
|
+
|
13
|
+
# Call the function
|
14
|
+
mylib.backend_init()
|
15
|
+
device_name = mylib.get_default_device_name()
|
16
|
+
|
17
|
+
# Print the result
|
18
|
+
print(f"Device Name: {device_name.decode('utf-8')}")
|
19
|
+
|
pyhw/backend/os/linux.py
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
"""
|
2
|
+
In dev.
|
3
|
+
"""
|
4
|
+
from dataclasses import dataclass
|
5
|
+
|
6
|
+
|
7
|
+
@dataclass
|
8
|
+
class OSInfoLinux:
|
9
|
+
prettyName = ""
|
10
|
+
name = ""
|
11
|
+
id = ""
|
12
|
+
idLike = ""
|
13
|
+
variant = ""
|
14
|
+
variantID = ""
|
15
|
+
version = ""
|
16
|
+
versionID = ""
|
17
|
+
versionCodename = ""
|
18
|
+
codeName = ""
|
19
|
+
buildID = ""
|
20
|
+
|
21
|
+
|
22
|
+
class OSDetectLinux:
|
23
|
+
def __init__(self):
|
24
|
+
self.__osInfo = OSInfoLinux()
|
25
|
+
|
26
|
+
def getOSInfo(self):
|
27
|
+
"""
|
28
|
+
Detects the os distribution and its version.
|
29
|
+
:return: dataclass OSInfoLinux, direct attrs: prettyName
|
30
|
+
"""
|
31
|
+
self.__getOSInfo()
|
32
|
+
return self.__osInfo
|
33
|
+
|
34
|
+
def __getOSInfo(self):
|
35
|
+
try:
|
36
|
+
with open("/etc/os-release", "r") as f:
|
37
|
+
for line in f:
|
38
|
+
key, value = line.strip().split("=")
|
39
|
+
if key == "PRETTY_NAME":
|
40
|
+
self.__osInfo.prettyName = value.strip('"')
|
41
|
+
elif key == "NAME":
|
42
|
+
self.__osInfo.name = value.strip('"')
|
43
|
+
elif key == "ID":
|
44
|
+
self.__osInfo.id = value.strip('"')
|
45
|
+
elif key == "ID_LIKE":
|
46
|
+
self.__osInfo.idLike = value.strip('"')
|
47
|
+
elif key == "VARIANT":
|
48
|
+
self.__osInfo.variant = value.strip('"')
|
49
|
+
elif key == "VARIANT_ID":
|
50
|
+
self.__osInfo.variantID = value.strip('"')
|
51
|
+
elif key == "VERSION":
|
52
|
+
self.__osInfo.version = value.strip('"')
|
53
|
+
elif key == "VERSION_ID":
|
54
|
+
self.__osInfo.versionID = value.strip('"')
|
55
|
+
elif key == "VERSION_CODENAME":
|
56
|
+
self.__osInfo.versionCodename = value.strip('"')
|
57
|
+
elif key == "CODE_NAME":
|
58
|
+
self.__osInfo.codeName = value.strip('"')
|
59
|
+
elif key == "BUILD_ID":
|
60
|
+
self.__osInfo.buildID = value.strip('"')
|
61
|
+
except Exception:
|
62
|
+
pass
|
@@ -0,0 +1,13 @@
|
|
1
|
+
from .linux import OSDetectLinux
|
2
|
+
from ...pyhwException import OSUnsupportedException
|
3
|
+
|
4
|
+
|
5
|
+
class OSDetect:
|
6
|
+
def __init__(self, os):
|
7
|
+
self.__OS = os
|
8
|
+
|
9
|
+
def getOSInfo(self):
|
10
|
+
if self.__OS == "linux":
|
11
|
+
return OSDetectLinux().getOSInfo()
|
12
|
+
else:
|
13
|
+
raise OSUnsupportedException("Unsupported operating system")
|
@@ -0,0 +1,13 @@
|
|
1
|
+
from .unix import ShellDetectUnix
|
2
|
+
from ...pyhwException import OSUnsupportedException
|
3
|
+
|
4
|
+
|
5
|
+
class ShellDetect:
|
6
|
+
def __init__(self, os):
|
7
|
+
self.OS = os
|
8
|
+
|
9
|
+
def getShellInfo(self):
|
10
|
+
if self.OS == "linux" or self.OS == "macos":
|
11
|
+
return ShellDetectUnix().getShellInfo()
|
12
|
+
else:
|
13
|
+
raise OSUnsupportedException("Unsupported operating system")
|
@@ -0,0 +1,56 @@
|
|
1
|
+
"""
|
2
|
+
In dev.
|
3
|
+
"""
|
4
|
+
from dataclasses import dataclass
|
5
|
+
import os
|
6
|
+
import subprocess
|
7
|
+
|
8
|
+
|
9
|
+
@dataclass
|
10
|
+
class ShellInfoUnix:
|
11
|
+
shell = ""
|
12
|
+
version = ""
|
13
|
+
path = ""
|
14
|
+
info = ""
|
15
|
+
|
16
|
+
|
17
|
+
class ShellDetectUnix:
|
18
|
+
def __init__(self):
|
19
|
+
self.__shellInfo = ShellInfoUnix()
|
20
|
+
|
21
|
+
def getShellInfo(self):
|
22
|
+
self.__getShell()
|
23
|
+
self.__getVersion()
|
24
|
+
self.__shellInfo.info = self.__shellInfo.shell + " " + self.__shellInfo.version
|
25
|
+
return self.__shellInfo
|
26
|
+
|
27
|
+
def __getShell(self):
|
28
|
+
# Get the default shell, not the current shell.
|
29
|
+
shell_env = os.getenv("SHELL", "")
|
30
|
+
if shell_env != "":
|
31
|
+
self.__shellInfo.shell = shell_env.split("/")[-1]
|
32
|
+
self.__shellInfo.path = shell_env
|
33
|
+
|
34
|
+
def __getVersion(self):
|
35
|
+
shell = self.__shellInfo.shell
|
36
|
+
if shell != "":
|
37
|
+
if shell in ["sh", "ash", "dash", "es"]:
|
38
|
+
pass
|
39
|
+
elif shell == "bash":
|
40
|
+
try:
|
41
|
+
result = subprocess.run(["bash", "-c", "echo $BASH_VERSION"], capture_output=True, text=True)
|
42
|
+
self.__shellInfo.version = result.stdout.strip()
|
43
|
+
except subprocess.SubprocessError:
|
44
|
+
pass
|
45
|
+
elif shell == "zsh":
|
46
|
+
try:
|
47
|
+
result = subprocess.run(["zsh", "-c", "echo $ZSH_VERSION"], capture_output=True, text=True)
|
48
|
+
self.__shellInfo.version = result.stdout.strip()
|
49
|
+
except subprocess.SubprocessError:
|
50
|
+
pass
|
51
|
+
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
|
56
|
+
|
@@ -0,0 +1,16 @@
|
|
1
|
+
from .unix import TitleDetectUnix
|
2
|
+
from .windows import TitleDetectWindows
|
3
|
+
from ...pyhwException import OSUnsupportedException
|
4
|
+
|
5
|
+
|
6
|
+
class TitleDetect:
|
7
|
+
def __init__(self, os):
|
8
|
+
self.OS = os
|
9
|
+
|
10
|
+
def getTitle(self):
|
11
|
+
if self.OS == "linux" or self.OS == "macos":
|
12
|
+
return TitleDetectUnix().getTitle()
|
13
|
+
elif self.OS == "windows":
|
14
|
+
return TitleDetectWindows().getTitle()
|
15
|
+
else:
|
16
|
+
raise OSUnsupportedException("Unsupported operating system")
|
@@ -0,0 +1,33 @@
|
|
1
|
+
"""
|
2
|
+
In dev.
|
3
|
+
"""
|
4
|
+
import subprocess
|
5
|
+
from dataclasses import dataclass
|
6
|
+
|
7
|
+
|
8
|
+
@dataclass
|
9
|
+
class TitleInfoUnix:
|
10
|
+
username = ""
|
11
|
+
hostname = ""
|
12
|
+
title = ""
|
13
|
+
|
14
|
+
|
15
|
+
class TitleDetectUnix:
|
16
|
+
def __init__(self):
|
17
|
+
self.__titleInfo = TitleInfoUnix()
|
18
|
+
|
19
|
+
def getTitle(self):
|
20
|
+
self.__getTitle()
|
21
|
+
return self.__titleInfo
|
22
|
+
|
23
|
+
def __getTitle(self):
|
24
|
+
try:
|
25
|
+
username_result = subprocess.run(['whoami'], capture_output=True, text=True)
|
26
|
+
self.__titleInfo.username = username_result.stdout.strip()
|
27
|
+
hostname_result = subprocess.run(['hostname'], capture_output=True, text=True)
|
28
|
+
self.__titleInfo.hostname = hostname_result.stdout.strip()
|
29
|
+
self.__titleInfo.title = f"{self.__titleInfo.username}@{self.__titleInfo.hostname}"
|
30
|
+
except Exception as e:
|
31
|
+
pass
|
32
|
+
|
33
|
+
|