pyhw 0.6.5__py3-none-any.whl → 0.6.7__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.
@@ -1,7 +1,7 @@
1
1
  """
2
2
  In dev.
3
3
  """
4
- from ...pyhwUtil import getArch
4
+ from ...pyhwUtil import getArch, getDocker
5
5
  from .hostInfo import HostInfo
6
6
  import os
7
7
 
@@ -10,47 +10,53 @@ class HostDetectLinux:
10
10
  def __init__(self):
11
11
  self.__hostInfo = HostInfo()
12
12
  self.__arch = getArch()
13
+ self.__docker = getDocker()
13
14
 
14
15
  def getHostInfo(self):
15
16
  self.__getModel()
16
17
  return self.__hostInfo
17
18
 
18
19
  def __getModel(self):
19
- if self.__arch in ["x86_64", "x86"]:
20
- try:
21
- with open("/sys/devices/virtual/dmi/id/product_name", "r") as f:
22
- product_name = f.read().strip()
23
- if product_name.startswith("To be filled by O.E.M."):
24
- self.__hostInfo.name = f"General {self.__arch} Host"
25
- else:
26
- self.__hostInfo.name = product_name
27
- with open("/sys/devices/virtual/dmi/id/product_version", "r") as f:
28
- version = f.read().strip()
29
- if version.startswith("To be filled by O.E.M."):
30
- self.__hostInfo.version = ""
31
- else:
32
- self.__hostInfo.version = version
33
- self.__hostInfo.model = self.__hostInfo.name + " " + self.__hostInfo.version
34
- except FileNotFoundError:
35
- pass
36
- elif self.__arch in ["aarch64", "arm32"]:
37
- # try to find dmi folder since some arm based desktops and servers may have same structure as x86_64 machines.
38
- if os.path.exists("/sys/devices/virtual/dmi/id"):
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
+ else:
25
+ if self.__arch in ["x86_64", "x86"]:
39
26
  try:
40
27
  with open("/sys/devices/virtual/dmi/id/product_name", "r") as f:
41
- self.__hostInfo.name = f.read().strip()
28
+ product_name = f.read().strip()
29
+ if product_name.startswith("To be filled by O.E.M."):
30
+ self.__hostInfo.name = f"General {self.__arch} Host"
31
+ else:
32
+ self.__hostInfo.name = product_name
42
33
  with open("/sys/devices/virtual/dmi/id/product_version", "r") as f:
43
- self.__hostInfo.version = f.read().strip()
34
+ version = f.read().strip()
35
+ if version.startswith("To be filled by O.E.M."):
36
+ self.__hostInfo.version = ""
37
+ else:
38
+ self.__hostInfo.version = version
44
39
  self.__hostInfo.model = self.__hostInfo.name + " " + self.__hostInfo.version
45
40
  except FileNotFoundError:
46
41
  pass
47
- else:
48
- # some single board computers may not have dmi folder, try to find model name in device tree.
49
- try:
50
- with open("/sys/firmware/devicetree/base/model", "r") as f:
51
- self.__hostInfo.model = f.read().strip()
52
- except FileNotFoundError:
53
- pass
42
+ elif self.__arch in ["aarch64", "arm32"]:
43
+ # try to find dmi folder since some arm based desktops and servers may have same structure as x86_64 machines.
44
+ if os.path.exists("/sys/devices/virtual/dmi/id"):
45
+ try:
46
+ with open("/sys/devices/virtual/dmi/id/product_name", "r") as f:
47
+ self.__hostInfo.name = f.read().strip()
48
+ with open("/sys/devices/virtual/dmi/id/product_version", "r") as f:
49
+ self.__hostInfo.version = f.read().strip()
50
+ self.__hostInfo.model = self.__hostInfo.name + " " + self.__hostInfo.version
51
+ except FileNotFoundError:
52
+ pass
53
+ else:
54
+ # some single board computers may not have dmi folder, try to find model name in device tree.
55
+ try:
56
+ with open("/sys/firmware/devicetree/base/model", "r") as f:
57
+ self.__hostInfo.model = f.read().strip()
58
+ except FileNotFoundError:
59
+ pass
54
60
 
55
61
  def __getHostFamily(self):
56
62
  pass
@@ -1,6 +1,7 @@
1
1
  """
2
2
  In dev.
3
3
  """
4
+ from ...pyhwUtil import getDocker
4
5
  from dataclasses import dataclass
5
6
  import os
6
7
  import subprocess
@@ -19,9 +20,13 @@ class ShellDetectUnix:
19
20
  self.__shellInfo = ShellInfoUnix()
20
21
 
21
22
  def getShellInfo(self):
22
- self.__getShell()
23
+ if getDocker():
24
+ self.__getShellDocker()
25
+ else:
26
+ self.__getShell()
23
27
  self.__getVersion()
24
28
  self.__shellInfo.info = self.__shellInfo.shell + " " + self.__shellInfo.version
29
+ print(self.__shellInfo.info)
25
30
  return self.__shellInfo
26
31
 
27
32
  def __getShell(self):
@@ -31,6 +36,19 @@ class ShellDetectUnix:
31
36
  self.__shellInfo.shell = shell_env.split("/")[-1]
32
37
  self.__shellInfo.path = shell_env
33
38
 
39
+ def __getShellDocker(self):
40
+ try:
41
+ with open("/etc/passwd", "r") as f:
42
+ for line in f:
43
+ if line.startswith("root:"):
44
+ root_shell = line.strip().split(":")[-1]
45
+ break
46
+ except:
47
+ root_shell = ""
48
+ if root_shell != "":
49
+ self.__shellInfo.shell = root_shell.split("/")[-1]
50
+ self.__shellInfo.path = root_shell
51
+
34
52
  def __getVersion(self):
35
53
  shell = self.__shellInfo.shell
36
54
  if shell != "":
@@ -39,7 +57,7 @@ class ShellDetectUnix:
39
57
  elif shell == "bash":
40
58
  try:
41
59
  result = subprocess.run(["bash", "-c", "echo $BASH_VERSION"], capture_output=True, text=True)
42
- self.__shellInfo.version = result.stdout.strip()
60
+ self.__shellInfo.version = result.stdout.strip().split("(")[0]
43
61
  except subprocess.SubprocessError:
44
62
  pass
45
63
  elif shell == "zsh":
@@ -54,3 +72,4 @@ class ShellDetectUnix:
54
72
 
55
73
 
56
74
 
75
+
@@ -1,5 +1,7 @@
1
1
  from .logo import Logo
2
2
  from .color import ColorConfigSet, colorPrefix, colorSuffix, ColorSet
3
+ from ..pyhwUtil import getOS
4
+ import os
3
5
  import re
4
6
 
5
7
 
@@ -16,6 +18,7 @@ class Printer:
16
18
  self.__combined_lines = []
17
19
  self.__logo_color_indexes = {}
18
20
  self.__reg = r'\$(\d)'
21
+ self.__columns = self.__getColumns()
19
22
 
20
23
  def cPrint(self):
21
24
  self.__LogoPreprocess()
@@ -31,8 +34,37 @@ class Printer:
31
34
  for data_line in self.__processed_data_lines[len(self.__processed_logo_lines):]:
32
35
  self.__combined_lines.append(" " * (max_len_logo + 1) + data_line)
33
36
 
37
+ self.__dropLongString()
38
+
34
39
  print("\n".join(self.__combined_lines))
35
40
 
41
+ def __dropLongString(self):
42
+ # Need more accurate way to drop long strings
43
+ if getOS() == "linux":
44
+ fixed_lines = list()
45
+ for line in self.__combined_lines:
46
+ if len(line) > self.__columns+20:
47
+ fixed_lines.append(line[:self.__columns+20])
48
+ else:
49
+ fixed_lines.append(line)
50
+ self.__combined_lines = fixed_lines
51
+ else:
52
+ pass
53
+
54
+
55
+ @staticmethod
56
+ def __getColumns() -> int:
57
+ if getOS() == "linux":
58
+ try:
59
+ _, columns_str = os.popen('stty size', 'r').read().split()
60
+ columns = int(columns_str)
61
+ except:
62
+ columns = 80 # default terminal size is 80 columns
63
+ else:
64
+ # macOS default terminal size is 80 columns
65
+ columns = 80
66
+ return columns
67
+
36
68
  def __LogoPreprocess(self):
37
69
  global_color = self.__config.get("colors")[0]
38
70
  for logo_line in self.__logo_lines:
pyhw/pyhwUtil/__init__.py CHANGED
@@ -1,4 +1,4 @@
1
- from .pyhwUtil import getOS, getArch, createDataString, selectOSLogo
1
+ from .pyhwUtil import getOS, getArch, getDocker, createDataString, selectOSLogo
2
2
  from .sysctlUtil import sysctlGetString, sysctlGetInt
3
3
 
4
- __all__ = ["getOS", "getArch", "createDataString", "selectOSLogo", "sysctlGetString", "sysctlGetInt"]
4
+ __all__ = ["getOS", "getArch", "getDocker", "createDataString", "selectOSLogo", "sysctlGetString", "sysctlGetInt"]
pyhw/pyhwUtil/pyhwUtil.py CHANGED
@@ -38,7 +38,115 @@ def getArch():
38
38
  return "unknown"
39
39
 
40
40
 
41
+ def getDocker() -> bool:
42
+ """
43
+ Check if the current environment is running in Docker.
44
+ :return: bool, True if running in Docker, False otherwise.
45
+ """
46
+ return os.path.exists("/.dockerenv")
47
+
48
+
49
+ class DataStringProcessor:
50
+ def __init__(self, data: Data):
51
+ self.data = data
52
+ self.columns = self.__getENV()
53
+
54
+ @staticmethod
55
+ def __getENV() -> int:
56
+ if getOS() == "linux":
57
+ _, columns_str = os.popen('stty size', 'r').read().split()
58
+ columns = int(columns_str)
59
+ else:
60
+ # macOS default terminal size is 80 columns
61
+ columns = 80
62
+ return columns
63
+
64
+ def __dropLongString(self, string: str) -> str:
65
+ """
66
+ Drop the string if it's too long to fit in the terminal.
67
+ :param string: str, the input string.
68
+ :return: str, the shortened string, do not include newline char.
69
+ """
70
+ if len(string) >= self.columns:
71
+ return f"{string[:self.columns-1]}"
72
+ else:
73
+ return f"{string}"
74
+
75
+ def getTitle(self) -> str:
76
+ return f" {self.data.title}\n"
77
+
78
+ def getLine(self) -> str:
79
+ return f" {'-'*len(self.data.title)}\n"
80
+
81
+ def getOS(self) -> str:
82
+ os_str = f" OS: {self.data.OS}"
83
+ return f"{self.__dropLongString(os_str)}\n"
84
+
85
+ def getHost(self) -> str:
86
+ host_str = f" Host: {self.data.Host}"
87
+ return f"{self.__dropLongString(host_str)}\n"
88
+
89
+ def getKernel(self) -> str:
90
+ kernel_str = f" Kernel: {self.data.Kernel}"
91
+ return f"{self.__dropLongString(kernel_str)}\n"
92
+
93
+ def getUptime(self) -> str:
94
+ uptime_str = f" Uptime: {self.data.Uptime}"
95
+ return f"{self.__dropLongString(uptime_str)}\n"
96
+
97
+ def getShell(self) -> str:
98
+ shell_str = f" Shell: {self.data.Shell}"
99
+ return f"{self.__dropLongString(shell_str)}\n"
100
+
101
+ def getCPU(self) -> str:
102
+ cpu_str = f" CPU: {self.data.CPU}"
103
+ return f"{self.__dropLongString(cpu_str)}\n"
104
+
105
+ def getGPU(self) -> str:
106
+ ret_str = ""
107
+ for gpu in self.data.GPU:
108
+ gpu_str = f" GPU: {gpu}"
109
+ ret_str += f"{self.__dropLongString(gpu_str)}\n"
110
+ return ret_str
111
+
112
+ def getMemory(self) -> str:
113
+ memory_str = f" Memory: {self.data.Memory}"
114
+ return f"{self.__dropLongString(memory_str)}\n"
115
+
116
+ def getNIC(self) -> str:
117
+ ret_str = ""
118
+ for nic in self.data.NIC:
119
+ nic_str = f" NIC: {nic}"
120
+ ret_str += f"{self.__dropLongString(nic_str)}\n"
121
+ return ret_str
122
+
123
+ def getNPU(self) -> str:
124
+ ret_str = ""
125
+ for npu in self.data.NPU:
126
+ npu_str = f" NPU: {npu}"
127
+ ret_str += f"{self.__dropLongString(npu_str)}\n"
128
+ return ret_str
129
+
130
+
41
131
  def createDataString(data: Data):
132
+ data_string_processor = DataStringProcessor(data)
133
+ data_string = ""
134
+ data_string += data_string_processor.getTitle()
135
+ data_string += data_string_processor.getLine()
136
+ data_string += data_string_processor.getOS()
137
+ data_string += data_string_processor.getHost()
138
+ data_string += data_string_processor.getKernel()
139
+ data_string += data_string_processor.getUptime()
140
+ data_string += data_string_processor.getShell()
141
+ data_string += data_string_processor.getCPU()
142
+ data_string += data_string_processor.getGPU()
143
+ data_string += data_string_processor.getMemory()
144
+ data_string += data_string_processor.getNIC()
145
+ data_string += data_string_processor.getNPU()
146
+ return data_string
147
+
148
+
149
+ def createDataStringOld(data: Data):
42
150
  data_string = ""
43
151
  data_string += f" {data.title}\n"
44
152
  data_string += f" {'-'*len(data.title)}\n"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pyhw
3
- Version: 0.6.5
3
+ Version: 0.6.7
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
@@ -16,7 +16,7 @@ pyhw/backend/gpu/macos.py,sha256=SmTqqTrIMRW-GVPmDs8xAiOX7HsCjrGh9qkxLQCdvO8,385
16
16
  pyhw/backend/host/__init__.py,sha256=Efaj7-Oya7H8HdpZHQCLrwn-mcfPb-d6yfh4dzsE_7I,58
17
17
  pyhw/backend/host/hostBase.py,sha256=POyDW3f5JSWtEKyCfrVSBEddSwoywe_OBgUExCEuje8,563
18
18
  pyhw/backend/host/hostInfo.py,sha256=Xvz0LugPiCSWMkcDsp4p2rrojYFZauL6Q-gCZ6NLz5k,184
19
- pyhw/backend/host/linux.py,sha256=wp65o_BJUxq-rkts_1UVP6IuK6U54Cl066G3QfZksiQ,2424
19
+ pyhw/backend/host/linux.py,sha256=5wfEbe4au4JqDazBuUTfWLC2sPPa_YuidSGKVwzyI-0,2853
20
20
  pyhw/backend/host/macos.py,sha256=KW-EJK9g1xHNrFsVxJv5GPLpc_ZevX0Zv1WjZUzRkzo,15369
21
21
  pyhw/backend/host/windows.py,sha256=rjDJaIs-5zspzFsNCMCh6m2yZXEXI0vccqeBpmAdEBk,53
22
22
  pyhw/backend/kernel/__init__.py,sha256=fGjwjpOhwA_PnsWbwoq102hwhTay2ufYKaTqxjSV2-I,65
@@ -47,7 +47,7 @@ pyhw/backend/os/osBase.py,sha256=AA17HIwmWy7E6nCtqbojTNsHKtcNuehf51FxGcfXu7A,462
47
47
  pyhw/backend/os/osInfo.py,sha256=iLPc7INFHH3izascwooj4JBVgvBsSgVPXWBlFXG47mQ,378
48
48
  pyhw/backend/shell/__init__.py,sha256=SeQ7OLNSl_V1JCCWnJGjLilAWiSe9e5kgsMEt63TMS0,62
49
49
  pyhw/backend/shell/shellBase.py,sha256=mylNazVtTbCSzus-IPe1QwnuIGSFNP-z5vYKwTIl_yg,377
50
- pyhw/backend/shell/unix.py,sha256=COPpSE_wnuuSWDckTvBT0nNwLzgh8iPLicY8XghTSYM,1530
50
+ pyhw/backend/shell/unix.py,sha256=Yradj6aj4nqc9CNQvVqzOgwO-p2IIJ_Jt_okL7cF4as,2146
51
51
  pyhw/backend/title/__init__.py,sha256=l6_WqreSBeK7krapCrbrr4ndnydrXB1aZ50Ve-beV_w,62
52
52
  pyhw/backend/title/titleBase.py,sha256=pcnkiNn9N69yc4iicAmpMpC6G7HUMyGCh0V1jjGIP_c,495
53
53
  pyhw/backend/title/unix.py,sha256=9B-zLE8yhlWBnJ-6Aa-DmFmgMV9KdvvNU40drJIaNck,837
@@ -58,7 +58,7 @@ pyhw/backend/uptime/macos.py,sha256=8lTlR0WUzgGqUNspqegg4dP_j5ySOCTyFlXpyRBJ-Jw,
58
58
  pyhw/backend/uptime/uptimeBase.py,sha256=cP6aTPnFe6XQHgBX7YcDuuGHARI11ctMlyrrtsU-Opc,657
59
59
  pyhw/backend/uptime/uptimeInfo.py,sha256=TobPEV3MBT3Fiv3W6TOzD3a4MNW-vz2Oi_Trlcihu7k,114
60
60
  pyhw/frontend/__init__.py,sha256=xgv_iVv9w4cLXklbdtFWXu7J7KJxBCUw-ZcUQb_abFc,57
61
- pyhw/frontend/frontendBase.py,sha256=RUh1s2yzU0iHaDmrFR5O4P64SHDO2007OTPsylDv0as,3714
61
+ pyhw/frontend/frontendBase.py,sha256=t_lq2mvBet3l8Kn7bvab1bvfwCaD7PZ6dzN8fMCzHOI,4713
62
62
  pyhw/frontend/color/__init__.py,sha256=xk511qWwdYWEVjk_zOaC4fs81HtwR4ELr3wi1tTL824,191
63
63
  pyhw/frontend/color/colorConfig.py,sha256=3k6aMoU7ymThG3yytzKqQDDxz8xL5wfZL_2cDiPusXI,4353
64
64
  pyhw/frontend/color/colorSet.py,sha256=spH8PlRu7capouf-yUgDHgoPCnM5aJ_ncascISZfz2g,1421
@@ -80,12 +80,12 @@ pyhw/frontend/logo/ascii/ubuntu_small.pyhw,sha256=Xf8LSZdZUu9aEG3efhb1FUlUEuJ-3U
80
80
  pyhw/library/lib/iokitGPULib.dylib,sha256=DcJ0GZY79gTFckLFYtZgeKn1T0NFvdO_k_ccCa7od5Y,154808
81
81
  pyhw/pyhwException/__init__.py,sha256=8JsFvtF13g0Y5t4z9fRndDXtfCzuBM59jDf6PhWSFSk,220
82
82
  pyhw/pyhwException/pyhwException.py,sha256=wxuzFQa9g7XB1q9TUKO_55lw7wMEJMpzG8w1GVTFVa0,197
83
- pyhw/pyhwUtil/__init__.py,sha256=PzeP9fXsIhvr3sUpJ4DxW9_H25DEIasBFfXd_NztfR4,226
84
- pyhw/pyhwUtil/pyhwUtil.py,sha256=CKXJrt6KGhZCV1J7MjsQ21c_jPmC1I3wZBPCKJfdqbM,2478
83
+ pyhw/pyhwUtil/__init__.py,sha256=diIqlNUBfuHu-2VAOJk5nipGLafnWxR3chAAOmX8QRo,250
84
+ pyhw/pyhwUtil/pyhwUtil.py,sha256=OY89sHr5LBjob7JMbCl-6x1AEPr-15UOE8UoQ04sLvI,5968
85
85
  pyhw/pyhwUtil/sysctlUtil.py,sha256=S-rUvqi7ZrMyMouIhxlyHEQ4agM7sCT1Y7uzs3Hu5-o,841
86
- pyhw-0.6.5.dist-info/LICENSE,sha256=hJs6RBqSVCexbTsalkMLNFI5t06kekQEsSVaOt_-yLs,1497
87
- pyhw-0.6.5.dist-info/METADATA,sha256=uVDEqgQ1fOLbwd9ydzgaKxs43MWavliFVm_z2avsg-k,5225
88
- pyhw-0.6.5.dist-info/WHEEL,sha256=R06PA3UVYHThwHvxuRWMqaGcr-PuniXahwjmQRFMEkY,91
89
- pyhw-0.6.5.dist-info/entry_points.txt,sha256=q-AB8im_QahpmNrmy4aPTJRGi0LlbNlnI3kF7s6pKss,44
90
- pyhw-0.6.5.dist-info/top_level.txt,sha256=7Inxvxt1TngEricKZEex9_WJZS3DbKYFUXDz4v5WHYU,5
91
- pyhw-0.6.5.dist-info/RECORD,,
86
+ pyhw-0.6.7.dist-info/LICENSE,sha256=hJs6RBqSVCexbTsalkMLNFI5t06kekQEsSVaOt_-yLs,1497
87
+ pyhw-0.6.7.dist-info/METADATA,sha256=NL0A7juUgOQRXCkDyg32z1NXzAFq8AF2drk4FSrkJi8,5225
88
+ pyhw-0.6.7.dist-info/WHEEL,sha256=R06PA3UVYHThwHvxuRWMqaGcr-PuniXahwjmQRFMEkY,91
89
+ pyhw-0.6.7.dist-info/entry_points.txt,sha256=q-AB8im_QahpmNrmy4aPTJRGi0LlbNlnI3kF7s6pKss,44
90
+ pyhw-0.6.7.dist-info/top_level.txt,sha256=7Inxvxt1TngEricKZEex9_WJZS3DbKYFUXDz4v5WHYU,5
91
+ pyhw-0.6.7.dist-info/RECORD,,
File without changes
File without changes