pyhw 0.1.0b0__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 -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
@@ -0,0 +1,36 @@
|
|
1
|
+
"""
|
2
|
+
In dev.
|
3
|
+
"""
|
4
|
+
from dataclasses import dataclass
|
5
|
+
|
6
|
+
|
7
|
+
@dataclass
|
8
|
+
class UptimeInfoLinux:
|
9
|
+
uptime = ""
|
10
|
+
|
11
|
+
|
12
|
+
class UptimeDetectLinux:
|
13
|
+
def __init__(self):
|
14
|
+
self.__uptimeInfo = UptimeInfoLinux()
|
15
|
+
|
16
|
+
def getUptimeInfo(self):
|
17
|
+
self.__getUptime()
|
18
|
+
return self.__uptimeInfo
|
19
|
+
|
20
|
+
def __getUptime(self):
|
21
|
+
with open("/proc/uptime", "r") as f:
|
22
|
+
uptime_seconds = float(f.readline().split(" ")[0])
|
23
|
+
hours, remainder = divmod(uptime_seconds, 3600)
|
24
|
+
minutes, seconds = divmod(remainder, 60)
|
25
|
+
days, hours = divmod(hours, 24)
|
26
|
+
days = int(days)
|
27
|
+
hours = int(hours)
|
28
|
+
minutes = int(minutes)
|
29
|
+
seconds = int(seconds)
|
30
|
+
if days == 0:
|
31
|
+
if hours == 0:
|
32
|
+
self.__uptimeInfo.uptime = f"{minutes} minutes {seconds} seconds"
|
33
|
+
else:
|
34
|
+
self.__uptimeInfo.uptime = f"{hours} hours {minutes} minutes {seconds} seconds"
|
35
|
+
else:
|
36
|
+
self.__uptimeInfo.uptime = f"{days} days {hours} hours {minutes} minutes {seconds} seconds"
|
@@ -0,0 +1,20 @@
|
|
1
|
+
from .linux import UptimeDetectLinux
|
2
|
+
from ...pyhwException import OSUnsupportedException
|
3
|
+
|
4
|
+
|
5
|
+
class UptimeDetect:
|
6
|
+
"""
|
7
|
+
Class for system uptime detection.
|
8
|
+
"""
|
9
|
+
def __init__(self, os):
|
10
|
+
self.OS = os
|
11
|
+
|
12
|
+
def getUptime(self):
|
13
|
+
"""
|
14
|
+
Detects the system uptime.
|
15
|
+
:return: dataclass UptimeInfo, direct attr: uptime
|
16
|
+
"""
|
17
|
+
if self.OS == "linux":
|
18
|
+
return UptimeDetectLinux().getUptimeInfo()
|
19
|
+
else:
|
20
|
+
raise OSUnsupportedException("Unsupported operating system")
|
@@ -0,0 +1,90 @@
|
|
1
|
+
from dataclasses import dataclass
|
2
|
+
from .colorSet import ColorSet
|
3
|
+
|
4
|
+
|
5
|
+
class ColorConfigSet:
|
6
|
+
def __init__(self, os_name):
|
7
|
+
self.__os_name = os_name
|
8
|
+
|
9
|
+
def getColorConfigSet(self):
|
10
|
+
if self.__os_name == "macOS":
|
11
|
+
return ColorConfigSetM.macOS
|
12
|
+
elif self.__os_name == "debian":
|
13
|
+
return ColorConfigSetD.debian
|
14
|
+
elif self.__os_name == "linux":
|
15
|
+
return ColorConfigSetL.linux
|
16
|
+
elif self.__os_name == "fedora":
|
17
|
+
return ColorConfigSetF.fedora
|
18
|
+
elif self.__os_name == "ubuntu":
|
19
|
+
return ColorConfigSetU.ubuntu
|
20
|
+
else:
|
21
|
+
return ColorConfigSetL.linux # default to Linux
|
22
|
+
|
23
|
+
|
24
|
+
@dataclass
|
25
|
+
class ColorConfigSetA:
|
26
|
+
pass
|
27
|
+
|
28
|
+
|
29
|
+
@dataclass
|
30
|
+
class ColorConfigSetD:
|
31
|
+
debian = {
|
32
|
+
"colors": [
|
33
|
+
ColorSet.COLOR_FG_RED,
|
34
|
+
ColorSet.COLOR_FG_LIGHT_BLACK
|
35
|
+
],
|
36
|
+
"colorKeys": ColorSet.COLOR_FG_RED,
|
37
|
+
"colorTitle": ColorSet.COLOR_FG_RED
|
38
|
+
}
|
39
|
+
|
40
|
+
|
41
|
+
@dataclass
|
42
|
+
class ColorConfigSetF:
|
43
|
+
fedora = {
|
44
|
+
"colors": [
|
45
|
+
ColorSet.COLOR_FG_BLUE,
|
46
|
+
ColorSet.COLOR_FG_WHITE
|
47
|
+
],
|
48
|
+
"colorKeys": ColorSet.COLOR_FG_BLUE,
|
49
|
+
"colorTitle": ColorSet.COLOR_FG_BLUE
|
50
|
+
}
|
51
|
+
|
52
|
+
|
53
|
+
@dataclass
|
54
|
+
class ColorConfigSetL:
|
55
|
+
linux = {
|
56
|
+
"colors": [
|
57
|
+
ColorSet.COLOR_FG_WHITE,
|
58
|
+
ColorSet.COLOR_FG_BLACK,
|
59
|
+
ColorSet.COLOR_FG_YELLOW
|
60
|
+
],
|
61
|
+
"colorKeys": ColorSet.COLOR_FG_YELLOW,
|
62
|
+
"colorTitle": ColorSet.COLOR_FG_YELLOW
|
63
|
+
}
|
64
|
+
|
65
|
+
|
66
|
+
@dataclass
|
67
|
+
class ColorConfigSetM:
|
68
|
+
macOS = {
|
69
|
+
"colors": [
|
70
|
+
ColorSet.COLOR_FG_GREEN,
|
71
|
+
ColorSet.COLOR_FG_YELLOW,
|
72
|
+
ColorSet.COLOR_FG_RED,
|
73
|
+
ColorSet.COLOR_FG_MAGENTA,
|
74
|
+
ColorSet.COLOR_FG_BLUE
|
75
|
+
],
|
76
|
+
"colorKeys": ColorSet.COLOR_FG_YELLOW,
|
77
|
+
"colorTitle": ColorSet.COLOR_FG_GREEN
|
78
|
+
}
|
79
|
+
|
80
|
+
|
81
|
+
@dataclass
|
82
|
+
class ColorConfigSetU:
|
83
|
+
ubuntu = {
|
84
|
+
"colors": [
|
85
|
+
ColorSet.COLOR_FG_RED,
|
86
|
+
ColorSet.COLOR_FG_WHITE
|
87
|
+
],
|
88
|
+
"colorKeys": ColorSet.COLOR_FG_RED,
|
89
|
+
"colorTitle": ColorSet.COLOR_FG_RED
|
90
|
+
}
|
@@ -0,0 +1,58 @@
|
|
1
|
+
from dataclasses import dataclass
|
2
|
+
|
3
|
+
|
4
|
+
@dataclass
|
5
|
+
class ColorSet:
|
6
|
+
COLOR_MODE_RESET = "0"
|
7
|
+
COLOR_MODE_BOLD = "1"
|
8
|
+
COLOR_MODE_DIM = "2"
|
9
|
+
COLOR_MODE_ITALIC = "3"
|
10
|
+
COLOR_MODE_UNDERLINE = "4"
|
11
|
+
COLOR_MODE_BLINK = "5"
|
12
|
+
COLOR_MODE_INVERSE = "7"
|
13
|
+
COLOR_MODE_HIDDEN = "8"
|
14
|
+
COLOR_MODE_STRIKETHROUGH = "9"
|
15
|
+
|
16
|
+
COLOR_FG_BLACK = "30"
|
17
|
+
COLOR_FG_RED = "31"
|
18
|
+
COLOR_FG_GREEN = "32"
|
19
|
+
COLOR_FG_YELLOW = "33"
|
20
|
+
COLOR_FG_BLUE = "34"
|
21
|
+
COLOR_FG_MAGENTA = "35"
|
22
|
+
COLOR_FG_CYAN = "36"
|
23
|
+
COLOR_FG_WHITE = "37"
|
24
|
+
COLOR_FG_DEFAULT = "39"
|
25
|
+
|
26
|
+
COLOR_FG_LIGHT_BLACK = "90"
|
27
|
+
COLOR_FG_LIGHT_RED = "91"
|
28
|
+
COLOR_FG_LIGHT_GREEN = "92"
|
29
|
+
COLOR_FG_LIGHT_YELLOW = "93"
|
30
|
+
COLOR_FG_LIGHT_BLUE = "94"
|
31
|
+
COLOR_FG_LIGHT_MAGENTA = "95"
|
32
|
+
COLOR_FG_LIGHT_CYAN = "96"
|
33
|
+
COLOR_FG_LIGHT_WHITE = "97"
|
34
|
+
|
35
|
+
COLOR_BG_BLACK = "40"
|
36
|
+
COLOR_BG_RED = "41"
|
37
|
+
COLOR_BG_GREEN = "42"
|
38
|
+
COLOR_BG_YELLOW = "43"
|
39
|
+
COLOR_BG_BLUE = "44"
|
40
|
+
COLOR_BG_MAGENTA = "45"
|
41
|
+
COLOR_BG_CYAN = "46"
|
42
|
+
COLOR_BG_WHITE = "47"
|
43
|
+
COLOR_BG_DEFAULT = "49"
|
44
|
+
|
45
|
+
COLOR_BG_LIGHT_BLACK = "100"
|
46
|
+
COLOR_BG_LIGHT_RED = "101"
|
47
|
+
COLOR_BG_LIGHT_GREEN = "102"
|
48
|
+
COLOR_BG_LIGHT_YELLOW = "103"
|
49
|
+
COLOR_BG_LIGHT_BLUE = "104"
|
50
|
+
COLOR_BG_LIGHT_MAGENTA = "105"
|
51
|
+
COLOR_BG_LIGHT_CYAN = "106"
|
52
|
+
COLOR_BG_LIGHT_WHITE = "107"
|
53
|
+
|
54
|
+
COLOR_FG_256 = "38;5;"
|
55
|
+
COLOR_BG_256 = "48;5;"
|
56
|
+
|
57
|
+
COLOR_FG_RGB = "38;2;"
|
58
|
+
COLOR_BG_RGB = "48;2;"
|
@@ -0,0 +1,69 @@
|
|
1
|
+
from .logo import Logo
|
2
|
+
from .color import ColorConfigSet, colorPrefix, colorSuffix, ColorSet
|
3
|
+
import re
|
4
|
+
|
5
|
+
|
6
|
+
class Printer:
|
7
|
+
def __init__(self, logo_os: str, data: str):
|
8
|
+
self.__logo = Logo(logo_os).getLogoContent()
|
9
|
+
self.__data = data
|
10
|
+
self.__config = ColorConfigSet(logo_os).getColorConfigSet()
|
11
|
+
self.__logo_lines = self.__logo.split("\n")
|
12
|
+
self.__data_lines = self.__data.strip().split("\n")
|
13
|
+
self.__line_length = []
|
14
|
+
self.__processed_logo_lines = []
|
15
|
+
self.__processed_data_lines = []
|
16
|
+
self.__combined_lines = []
|
17
|
+
self.__logo_color_indexes = {}
|
18
|
+
self.__reg = r'\$(\d)'
|
19
|
+
|
20
|
+
def cPrint(self):
|
21
|
+
self.__LogoPreprocess()
|
22
|
+
self.__DataPreprocess()
|
23
|
+
max_len_logo = max(self.__line_length)
|
24
|
+
for i, (logo_line, data_line) in enumerate(zip(self.__processed_logo_lines, self.__processed_data_lines)):
|
25
|
+
combined_line = logo_line + " " * (max_len_logo - self.__line_length[i] + 1) + data_line
|
26
|
+
self.__combined_lines.append(combined_line)
|
27
|
+
|
28
|
+
for i, logo_line in enumerate(self.__processed_logo_lines[len(self.__processed_data_lines):], start=len(self.__processed_data_lines)):
|
29
|
+
self.__combined_lines.append(logo_line)
|
30
|
+
|
31
|
+
for data_line in self.__processed_data_lines[len(self.__processed_logo_lines):]:
|
32
|
+
self.__combined_lines.append(" " * max_len_logo + data_line)
|
33
|
+
|
34
|
+
print("\n".join(self.__combined_lines))
|
35
|
+
|
36
|
+
def __LogoPreprocess(self):
|
37
|
+
global_color = self.__config.get("colors")[0]
|
38
|
+
for logo_line in self.__logo_lines:
|
39
|
+
matches = re.findall(pattern=self.__reg, string=logo_line)
|
40
|
+
color_numbers = len(matches)
|
41
|
+
line_length = len(logo_line)
|
42
|
+
if color_numbers > 0:
|
43
|
+
colors = [int(match) - 1 for match in matches] # color indexes
|
44
|
+
temp_line = colorPrefix(ColorSet.COLOR_MODE_BOLD) + colorPrefix(global_color) + logo_line + colorSuffix()
|
45
|
+
for color in colors:
|
46
|
+
temp_line = temp_line.replace(f"${color+1}", colorPrefix(self.__config.get("colors")[color]))
|
47
|
+
global_color = self.__config.get("colors")[colors[-1]] # set the global color to the last used color
|
48
|
+
else:
|
49
|
+
temp_line = colorPrefix(ColorSet.COLOR_MODE_BOLD) + colorPrefix(global_color) + logo_line + colorSuffix()
|
50
|
+
flags_number = len(re.findall(pattern=r'\$\$', string=logo_line)) + len(re.findall(pattern=r'\$\0', string=logo_line))
|
51
|
+
if flags_number > 0:
|
52
|
+
temp_line = temp_line.replace("$$", "$")
|
53
|
+
temp_line = temp_line.replace("$\0", "$")
|
54
|
+
self.__line_length.append(line_length - 2 * color_numbers - flags_number)
|
55
|
+
self.__processed_logo_lines.append(temp_line)
|
56
|
+
|
57
|
+
def __DataPreprocess(self):
|
58
|
+
header_color = self.__config.get("colorTitle")
|
59
|
+
keys_color = self.__config.get("colorKeys")
|
60
|
+
self.__processed_data_lines.append(" " + colorPrefix(ColorSet.COLOR_MODE_BOLD) + colorPrefix(header_color) +
|
61
|
+
self.__data_lines[0].split("@")[0] + colorSuffix() + colorPrefix(ColorSet.COLOR_MODE_BOLD) +
|
62
|
+
"@" + colorPrefix(header_color) +
|
63
|
+
self.__data_lines[0].split("@")[1] + colorSuffix())
|
64
|
+
self.__processed_data_lines.append(colorSuffix() + self.__data_lines[1])
|
65
|
+
for data_line in self.__data_lines[2:]:
|
66
|
+
name, value = data_line.split(": ")
|
67
|
+
self.__processed_data_lines.append(colorPrefix(ColorSet.COLOR_MODE_BOLD) + colorPrefix(keys_color) + name + ": " + colorSuffix() + value)
|
68
|
+
|
69
|
+
|
@@ -0,0 +1,17 @@
|
|
1
|
+
$2_,met$$$$$$$$$$gg.
|
2
|
+
,g$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$P.
|
3
|
+
,g$$$$P" """Y$$$$.".
|
4
|
+
,$$$$P' `$$$$$$.
|
5
|
+
',$$$$P ,ggs. `$$$$b:
|
6
|
+
`d$$$$' ,$P"' $1.$2 $$$$$$
|
7
|
+
$$$$P d$' $1,$2 $$$$$$P
|
8
|
+
$$$$: $$. $1-$2 ,d$$$$'
|
9
|
+
$$$$; Y$b._ _,d$P'
|
10
|
+
Y$$$$. $1`.$2`"Y$$$$$$$$P"'
|
11
|
+
`$$$$b $1"-.__
|
12
|
+
$2`Y$$$$
|
13
|
+
`Y$$$$.
|
14
|
+
`$$$$b.
|
15
|
+
`Y$$$$b.
|
16
|
+
`"Y$$b._
|
17
|
+
`"""
|
@@ -0,0 +1,19 @@
|
|
1
|
+
.',;::::;,'.
|
2
|
+
.';:cccccccccccc:;,.
|
3
|
+
.;cccccccccccccccccccccc;.
|
4
|
+
.:cccccccccccccccccccccccccc:.
|
5
|
+
.;ccccccccccccc;$2.:dddl:.$1;ccccccc;.
|
6
|
+
.:ccccccccccccc;$2OWMKOOXMWd$1;ccccccc:.
|
7
|
+
.:ccccccccccccc;$2KMMc$1;cc;$2xMMc$1;ccccccc:.
|
8
|
+
,cccccccccccccc;$2MMM.$1;cc;$2;WW:$1;cccccccc,
|
9
|
+
:cccccccccccccc;$2MMM.$1;cccccccccccccccc:
|
10
|
+
:ccccccc;$2oxOOOo$1;$2MMM000k.$1;cccccccccccc:
|
11
|
+
cccccc;$20MMKxdd:$1;$2MMMkddc.$1;cccccccccccc;
|
12
|
+
ccccc;$2XMO'$1;cccc;$2MMM.$1;cccccccccccccccc'
|
13
|
+
ccccc;$2MMo$1;ccccc;$2MMW.$1;ccccccccccccccc;
|
14
|
+
ccccc;$20MNc.$1ccc$2.xMMd$1;ccccccccccccccc;
|
15
|
+
cccccc;$2dNMWXXXWM0:$1;cccccccccccccc:,
|
16
|
+
cccccccc;$2.:odl:.$1;cccccccccccccc:,.
|
17
|
+
ccccccccccccccccccccccccccccc:'.
|
18
|
+
:ccccccccccccccccccccccc:;,..
|
19
|
+
':cccccccccccccccc::;,.
|
@@ -0,0 +1,12 @@
|
|
1
|
+
$2#####
|
2
|
+
$2#######
|
3
|
+
$2##$1O$2#$1O$2##
|
4
|
+
$2#$3#####$2#
|
5
|
+
$2##$1##$3###$1##$2##
|
6
|
+
$2#$1##########$2##
|
7
|
+
$2#$1############$2##
|
8
|
+
$2#$1############$2###
|
9
|
+
$3##$2#$1###########$2##$3#
|
10
|
+
$3######$2#$1#######$2#$3######
|
11
|
+
$3#######$2#$1#####$2#$3#######
|
12
|
+
$3#####$2#######$3#####
|
@@ -0,0 +1,17 @@
|
|
1
|
+
$1..'
|
2
|
+
,xNMM.
|
3
|
+
.OMMMMo
|
4
|
+
lMM"
|
5
|
+
.;loddo:. .olloddol;.
|
6
|
+
cKMMMMMMMMMMNWMMMMMMMMMM0:
|
7
|
+
$2.KMMMMMMMMMMMMMMMMMMMMMMMWd.
|
8
|
+
XMMMMMMMMMMMMMMMMMMMMMMMX.
|
9
|
+
$3;MMMMMMMMMMMMMMMMMMMMMMMM:
|
10
|
+
:MMMMMMMMMMMMMMMMMMMMMMMM:
|
11
|
+
.MMMMMMMMMMMMMMMMMMMMMMMMX.
|
12
|
+
kMMMMMMMMMMMMMMMMMMMMMMMMWd.
|
13
|
+
$4'XMMMMMMMMMMMMMMMMMMMMMMMMMMk
|
14
|
+
'XMMMMMMMMMMMMMMMMMMMMMMMMK.
|
15
|
+
$5kMMMMMMMMMMMMMMMMMMMMMMd
|
16
|
+
;KMMMMMMMWXXWMMMMMMMk.
|
17
|
+
"cooc*" "*coo'"
|
@@ -0,0 +1,20 @@
|
|
1
|
+
--+oossssssoo+--
|
2
|
+
.:+ssssssssssssssssss+:.
|
3
|
+
-+ssssssssssssssssssyyssss+-
|
4
|
+
.ossssssssssssssssssd$2MMMNy$1sssso.
|
5
|
+
/sssssssssss$2hdmmNNmmyNMMMMh$1ssssss/
|
6
|
+
+sssssssss$2hmydMMMMMMMNddddy$1ssssssss+
|
7
|
+
/ssssssss$2hNMMMyhhyyyyhmNMMMNh$1ssssssss/
|
8
|
+
.ssssssss$2dMMMNh$1ssssssssss$2hNMMMd$1ssssssss.
|
9
|
+
+ssss$2hhhyNMMNy$1ssssssssssss$2yNMMMy$1sssssss+
|
10
|
+
oss$2yNMMMNyMMh$1ssssssssssssss$2hmmmh$1ssssssso
|
11
|
+
oss$2yNMMMNyMMh$1ssssssssssssss$2hmmmh$1ssssssso
|
12
|
+
+ssss$2hhhyNMMNy$1ssssssssssss$2yNMMMy$1sssssss+
|
13
|
+
.ssssssss$2dMMMNh$1ssssssssss$2hNMMMd$1ssssssss.
|
14
|
+
/ssssssss$2hNMMMyhhyyyyhdNMMMNh$1ssssssss/
|
15
|
+
+sssssssss$2dmydMMMMMMMMddddy$1ssssssss+
|
16
|
+
/sssssssssss$2hdmNNNNmyNMMMMh$1ssssss/
|
17
|
+
.ossssssssssssssssss$2dMMMNy$1sssso.
|
18
|
+
-+sssssssssssssssss$2yyy$1ssss+-
|
19
|
+
`:+ssssssssssssssssss+:´
|
20
|
+
--+oossssssoo+--
|
@@ -0,0 +1,22 @@
|
|
1
|
+
from ...pyhwException import LogoNotFoundException
|
2
|
+
from pathlib import Path
|
3
|
+
import os
|
4
|
+
|
5
|
+
|
6
|
+
class Logo:
|
7
|
+
def __init__(self, logo_os):
|
8
|
+
self.__logo_os = logo_os
|
9
|
+
self.__logo_ascii = ""
|
10
|
+
|
11
|
+
def getLogoContent(self):
|
12
|
+
self.__loadLogoAscii()
|
13
|
+
return self.__logo_ascii
|
14
|
+
|
15
|
+
def __loadLogoAscii(self):
|
16
|
+
try:
|
17
|
+
file_path = os.path.join(Path(__file__).parent, f"ascii/{self.__logo_os}.pyhw")
|
18
|
+
with open(file_path, "r") as f:
|
19
|
+
self.__logo_ascii = f.read()
|
20
|
+
except FileNotFoundError:
|
21
|
+
raise LogoNotFoundException(f"Logo for {self.__logo_os} not found.")
|
22
|
+
|
pyhw/macos.py
ADDED
@@ -0,0 +1,146 @@
|
|
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
|
+
|
@@ -0,0 +1,50 @@
|
|
1
|
+
import platform
|
2
|
+
from ..backend import Data
|
3
|
+
|
4
|
+
def getOS():
|
5
|
+
"""
|
6
|
+
Get the os type in lower case.
|
7
|
+
:return: str, os type.
|
8
|
+
"""
|
9
|
+
system = platform.system()
|
10
|
+
if system == "Windows":
|
11
|
+
return "windows"
|
12
|
+
elif system == "Linux":
|
13
|
+
return "linux"
|
14
|
+
elif system == "Darwin":
|
15
|
+
return "macos"
|
16
|
+
else:
|
17
|
+
return "unknown"
|
18
|
+
|
19
|
+
def getArch():
|
20
|
+
"""
|
21
|
+
Get the machine architecture.
|
22
|
+
:return: str, value in [x86_64, x86, aarch64, arm32].
|
23
|
+
"""
|
24
|
+
arch = platform.machine()
|
25
|
+
if arch == "x86_64" or arch == "AMD64" or arch == "amd64":
|
26
|
+
return "x86_64"
|
27
|
+
elif arch == "i386" or arch == "i686" or arch == "x86":
|
28
|
+
return "x86"
|
29
|
+
elif arch == "aarch64":
|
30
|
+
return "aarch64"
|
31
|
+
elif arch.find("arm") != -1:
|
32
|
+
return "arm32"
|
33
|
+
else:
|
34
|
+
return "unknown"
|
35
|
+
|
36
|
+
|
37
|
+
def createDataString(data: Data):
|
38
|
+
data_string = f"""
|
39
|
+
{data.title}
|
40
|
+
{"-"*len(data.title)}
|
41
|
+
OS: {data.OS}
|
42
|
+
Host: {data.Host}
|
43
|
+
Kernel: {data.Kernel}
|
44
|
+
Uptime: {data.Uptime}
|
45
|
+
Shell: {data.Shell}
|
46
|
+
CPU: {data.CPU}
|
47
|
+
GPU: {data.GPU[0]}
|
48
|
+
Memory: {data.Memory}
|
49
|
+
"""
|
50
|
+
return data_string
|