pyhw 0.6.5__tar.gz → 0.6.7__tar.gz

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) hide show
  1. {pyhw-0.6.5/src/pyhw.egg-info → pyhw-0.6.7}/PKG-INFO +1 -1
  2. {pyhw-0.6.5 → pyhw-0.6.7}/pyproject.toml +1 -1
  3. pyhw-0.6.7/src/pyhw/backend/host/linux.py +65 -0
  4. {pyhw-0.6.5 → pyhw-0.6.7}/src/pyhw/backend/shell/unix.py +21 -2
  5. {pyhw-0.6.5 → pyhw-0.6.7}/src/pyhw/frontend/frontendBase.py +32 -0
  6. pyhw-0.6.7/src/pyhw/pyhwUtil/__init__.py +4 -0
  7. pyhw-0.6.7/src/pyhw/pyhwUtil/pyhwUtil.py +197 -0
  8. {pyhw-0.6.5 → pyhw-0.6.7/src/pyhw.egg-info}/PKG-INFO +1 -1
  9. pyhw-0.6.5/src/pyhw/backend/host/linux.py +0 -59
  10. pyhw-0.6.5/src/pyhw/pyhwUtil/__init__.py +0 -4
  11. pyhw-0.6.5/src/pyhw/pyhwUtil/pyhwUtil.py +0 -89
  12. {pyhw-0.6.5 → pyhw-0.6.7}/LICENSE +0 -0
  13. {pyhw-0.6.5 → pyhw-0.6.7}/README.md +0 -0
  14. {pyhw-0.6.5 → pyhw-0.6.7}/setup.cfg +0 -0
  15. {pyhw-0.6.5 → pyhw-0.6.7}/src/pyhw/__init__.py +0 -0
  16. {pyhw-0.6.5 → pyhw-0.6.7}/src/pyhw/__main__.py +0 -0
  17. {pyhw-0.6.5 → pyhw-0.6.7}/src/pyhw/backend/__init__.py +0 -0
  18. {pyhw-0.6.5 → pyhw-0.6.7}/src/pyhw/backend/backendBase.py +0 -0
  19. {pyhw-0.6.5 → pyhw-0.6.7}/src/pyhw/backend/cpu/__init__.py +0 -0
  20. {pyhw-0.6.5 → pyhw-0.6.7}/src/pyhw/backend/cpu/cpuBase.py +0 -0
  21. {pyhw-0.6.5 → pyhw-0.6.7}/src/pyhw/backend/cpu/cpuInfo.py +0 -0
  22. {pyhw-0.6.5 → pyhw-0.6.7}/src/pyhw/backend/cpu/linux.py +0 -0
  23. {pyhw-0.6.5 → pyhw-0.6.7}/src/pyhw/backend/cpu/macos.py +0 -0
  24. {pyhw-0.6.5 → pyhw-0.6.7}/src/pyhw/backend/gpu/__init__.py +0 -0
  25. {pyhw-0.6.5 → pyhw-0.6.7}/src/pyhw/backend/gpu/gpuBase.py +0 -0
  26. {pyhw-0.6.5 → pyhw-0.6.7}/src/pyhw/backend/gpu/gpuInfo.py +0 -0
  27. {pyhw-0.6.5 → pyhw-0.6.7}/src/pyhw/backend/gpu/linux.py +0 -0
  28. {pyhw-0.6.5 → pyhw-0.6.7}/src/pyhw/backend/gpu/macos.py +0 -0
  29. {pyhw-0.6.5 → pyhw-0.6.7}/src/pyhw/backend/host/__init__.py +0 -0
  30. {pyhw-0.6.5 → pyhw-0.6.7}/src/pyhw/backend/host/hostBase.py +0 -0
  31. {pyhw-0.6.5 → pyhw-0.6.7}/src/pyhw/backend/host/hostInfo.py +0 -0
  32. {pyhw-0.6.5 → pyhw-0.6.7}/src/pyhw/backend/host/macos.py +0 -0
  33. {pyhw-0.6.5 → pyhw-0.6.7}/src/pyhw/backend/host/windows.py +0 -0
  34. {pyhw-0.6.5 → pyhw-0.6.7}/src/pyhw/backend/kernel/__init__.py +0 -0
  35. {pyhw-0.6.5 → pyhw-0.6.7}/src/pyhw/backend/kernel/kernelBase.py +0 -0
  36. {pyhw-0.6.5 → pyhw-0.6.7}/src/pyhw/backend/kernel/kernelInfo.py +0 -0
  37. {pyhw-0.6.5 → pyhw-0.6.7}/src/pyhw/backend/kernel/unix.py +0 -0
  38. {pyhw-0.6.5 → pyhw-0.6.7}/src/pyhw/backend/kernel/windows.py +0 -0
  39. {pyhw-0.6.5 → pyhw-0.6.7}/src/pyhw/backend/memory/__init__.py +0 -0
  40. {pyhw-0.6.5 → pyhw-0.6.7}/src/pyhw/backend/memory/linux.py +0 -0
  41. {pyhw-0.6.5 → pyhw-0.6.7}/src/pyhw/backend/memory/macos.py +0 -0
  42. {pyhw-0.6.5 → pyhw-0.6.7}/src/pyhw/backend/memory/memoryBase.py +0 -0
  43. {pyhw-0.6.5 → pyhw-0.6.7}/src/pyhw/backend/memory/memoryInfo.py +0 -0
  44. {pyhw-0.6.5 → pyhw-0.6.7}/src/pyhw/backend/metal/t.py +0 -0
  45. {pyhw-0.6.5 → pyhw-0.6.7}/src/pyhw/backend/nic/__init__.py +0 -0
  46. {pyhw-0.6.5 → pyhw-0.6.7}/src/pyhw/backend/nic/linux.py +0 -0
  47. {pyhw-0.6.5 → pyhw-0.6.7}/src/pyhw/backend/nic/macos.py +0 -0
  48. {pyhw-0.6.5 → pyhw-0.6.7}/src/pyhw/backend/nic/nicBase.py +0 -0
  49. {pyhw-0.6.5 → pyhw-0.6.7}/src/pyhw/backend/nic/nicInfo.py +0 -0
  50. {pyhw-0.6.5 → pyhw-0.6.7}/src/pyhw/backend/npu/__init__.py +0 -0
  51. {pyhw-0.6.5 → pyhw-0.6.7}/src/pyhw/backend/npu/linux.py +0 -0
  52. {pyhw-0.6.5 → pyhw-0.6.7}/src/pyhw/backend/npu/macos.py +0 -0
  53. {pyhw-0.6.5 → pyhw-0.6.7}/src/pyhw/backend/npu/npuBase.py +0 -0
  54. {pyhw-0.6.5 → pyhw-0.6.7}/src/pyhw/backend/npu/npuInfo.py +0 -0
  55. {pyhw-0.6.5 → pyhw-0.6.7}/src/pyhw/backend/os/__init__.py +0 -0
  56. {pyhw-0.6.5 → pyhw-0.6.7}/src/pyhw/backend/os/linux.py +0 -0
  57. {pyhw-0.6.5 → pyhw-0.6.7}/src/pyhw/backend/os/macos.py +0 -0
  58. {pyhw-0.6.5 → pyhw-0.6.7}/src/pyhw/backend/os/osBase.py +0 -0
  59. {pyhw-0.6.5 → pyhw-0.6.7}/src/pyhw/backend/os/osInfo.py +0 -0
  60. {pyhw-0.6.5 → pyhw-0.6.7}/src/pyhw/backend/shell/__init__.py +0 -0
  61. {pyhw-0.6.5 → pyhw-0.6.7}/src/pyhw/backend/shell/shellBase.py +0 -0
  62. {pyhw-0.6.5 → pyhw-0.6.7}/src/pyhw/backend/title/__init__.py +0 -0
  63. {pyhw-0.6.5 → pyhw-0.6.7}/src/pyhw/backend/title/titleBase.py +0 -0
  64. {pyhw-0.6.5 → pyhw-0.6.7}/src/pyhw/backend/title/unix.py +0 -0
  65. {pyhw-0.6.5 → pyhw-0.6.7}/src/pyhw/backend/title/windows.py +0 -0
  66. {pyhw-0.6.5 → pyhw-0.6.7}/src/pyhw/backend/uptime/__init__.py +0 -0
  67. {pyhw-0.6.5 → pyhw-0.6.7}/src/pyhw/backend/uptime/linux.py +0 -0
  68. {pyhw-0.6.5 → pyhw-0.6.7}/src/pyhw/backend/uptime/macos.py +0 -0
  69. {pyhw-0.6.5 → pyhw-0.6.7}/src/pyhw/backend/uptime/uptimeBase.py +0 -0
  70. {pyhw-0.6.5 → pyhw-0.6.7}/src/pyhw/backend/uptime/uptimeInfo.py +0 -0
  71. {pyhw-0.6.5 → pyhw-0.6.7}/src/pyhw/frontend/__init__.py +0 -0
  72. {pyhw-0.6.5 → pyhw-0.6.7}/src/pyhw/frontend/color/__init__.py +0 -0
  73. {pyhw-0.6.5 → pyhw-0.6.7}/src/pyhw/frontend/color/colorConfig.py +0 -0
  74. {pyhw-0.6.5 → pyhw-0.6.7}/src/pyhw/frontend/color/colorSet.py +0 -0
  75. {pyhw-0.6.5 → pyhw-0.6.7}/src/pyhw/frontend/color/colorUtil.py +0 -0
  76. {pyhw-0.6.5 → pyhw-0.6.7}/src/pyhw/frontend/logo/__init__.py +0 -0
  77. {pyhw-0.6.5 → pyhw-0.6.7}/src/pyhw/frontend/logo/ascii/alpine.pyhw +0 -0
  78. {pyhw-0.6.5 → pyhw-0.6.7}/src/pyhw/frontend/logo/ascii/arch.pyhw +0 -0
  79. {pyhw-0.6.5 → pyhw-0.6.7}/src/pyhw/frontend/logo/ascii/armbian.pyhw +0 -0
  80. {pyhw-0.6.5 → pyhw-0.6.7}/src/pyhw/frontend/logo/ascii/centos.pyhw +0 -0
  81. {pyhw-0.6.5 → pyhw-0.6.7}/src/pyhw/frontend/logo/ascii/debian.pyhw +0 -0
  82. {pyhw-0.6.5 → pyhw-0.6.7}/src/pyhw/frontend/logo/ascii/fedora.pyhw +0 -0
  83. {pyhw-0.6.5 → pyhw-0.6.7}/src/pyhw/frontend/logo/ascii/fedora_small.pyhw +0 -0
  84. {pyhw-0.6.5 → pyhw-0.6.7}/src/pyhw/frontend/logo/ascii/linux.pyhw +0 -0
  85. {pyhw-0.6.5 → pyhw-0.6.7}/src/pyhw/frontend/logo/ascii/macOS.pyhw +0 -0
  86. {pyhw-0.6.5 → pyhw-0.6.7}/src/pyhw/frontend/logo/ascii/raspbian.pyhw +0 -0
  87. {pyhw-0.6.5 → pyhw-0.6.7}/src/pyhw/frontend/logo/ascii/ubuntu.pyhw +0 -0
  88. {pyhw-0.6.5 → pyhw-0.6.7}/src/pyhw/frontend/logo/ascii/ubuntu_small.pyhw +0 -0
  89. {pyhw-0.6.5 → pyhw-0.6.7}/src/pyhw/frontend/logo/logoBase.py +0 -0
  90. {pyhw-0.6.5 → pyhw-0.6.7}/src/pyhw/library/lib/iokitGPULib.dylib +0 -0
  91. {pyhw-0.6.5 → pyhw-0.6.7}/src/pyhw/macos.py +0 -0
  92. {pyhw-0.6.5 → pyhw-0.6.7}/src/pyhw/pyhwException/__init__.py +0 -0
  93. {pyhw-0.6.5 → pyhw-0.6.7}/src/pyhw/pyhwException/pyhwException.py +0 -0
  94. {pyhw-0.6.5 → pyhw-0.6.7}/src/pyhw/pyhwUtil/sysctlUtil.py +0 -0
  95. {pyhw-0.6.5 → pyhw-0.6.7}/src/pyhw.egg-info/SOURCES.txt +0 -0
  96. {pyhw-0.6.5 → pyhw-0.6.7}/src/pyhw.egg-info/dependency_links.txt +0 -0
  97. {pyhw-0.6.5 → pyhw-0.6.7}/src/pyhw.egg-info/entry_points.txt +0 -0
  98. {pyhw-0.6.5 → pyhw-0.6.7}/src/pyhw.egg-info/requires.txt +0 -0
  99. {pyhw-0.6.5 → pyhw-0.6.7}/src/pyhw.egg-info/top_level.txt +0 -0
@@ -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
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "pyhw"
7
- version = "0.6.5"
7
+ version = "0.6.7"
8
8
  description = "PyHw, a neofetch-like command line tool for fetching system information but written mostly in python."
9
9
  keywords = ["neofetch", "system information", "command line tool", "python", "hardware information", "fastfetch", "fetching"]
10
10
  authors = [
@@ -0,0 +1,65 @@
1
+ """
2
+ In dev.
3
+ """
4
+ from ...pyhwUtil import getArch, getDocker
5
+ from .hostInfo import HostInfo
6
+ import os
7
+
8
+
9
+ class HostDetectLinux:
10
+ def __init__(self):
11
+ self.__hostInfo = HostInfo()
12
+ self.__arch = getArch()
13
+ self.__docker = getDocker()
14
+
15
+ def getHostInfo(self):
16
+ self.__getModel()
17
+ return self.__hostInfo
18
+
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
+ else:
25
+ if self.__arch in ["x86_64", "x86"]:
26
+ try:
27
+ with open("/sys/devices/virtual/dmi/id/product_name", "r") as f:
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
33
+ with open("/sys/devices/virtual/dmi/id/product_version", "r") as f:
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
39
+ self.__hostInfo.model = self.__hostInfo.name + " " + self.__hostInfo.version
40
+ except FileNotFoundError:
41
+ 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
60
+
61
+ def __getHostFamily(self):
62
+ pass
63
+
64
+ def __getHostProductName(self):
65
+ 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:
@@ -0,0 +1,4 @@
1
+ from .pyhwUtil import getOS, getArch, getDocker, createDataString, selectOSLogo
2
+ from .sysctlUtil import sysctlGetString, sysctlGetInt
3
+
4
+ __all__ = ["getOS", "getArch", "getDocker", "createDataString", "selectOSLogo", "sysctlGetString", "sysctlGetInt"]
@@ -0,0 +1,197 @@
1
+ import platform
2
+ from ..backend import Data
3
+ import os
4
+ from dataclasses import dataclass
5
+
6
+
7
+ def getOS():
8
+ """
9
+ Get the os type in lower case.
10
+ :return: str, os type, value in [windows, linux, macos, unknown].
11
+ """
12
+ system = platform.system()
13
+ if system == "Windows":
14
+ return "windows"
15
+ elif system == "Linux":
16
+ return "linux"
17
+ elif system == "Darwin":
18
+ return "macos"
19
+ else:
20
+ return "unknown"
21
+
22
+
23
+ def getArch():
24
+ """
25
+ Get the machine architecture.
26
+ :return: str, value in [x86_64, x86, aarch64, arm32].
27
+ """
28
+ arch = platform.machine()
29
+ if arch == "x86_64" or arch == "AMD64" or arch == "amd64":
30
+ return "x86_64"
31
+ elif arch == "i386" or arch == "i686" or arch == "x86":
32
+ return "x86"
33
+ elif arch == "aarch64" or arch == "arm64":
34
+ return "aarch64"
35
+ elif arch.find("arm") != -1:
36
+ return "arm32"
37
+ else:
38
+ return "unknown"
39
+
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
+
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):
150
+ data_string = ""
151
+ data_string += f" {data.title}\n"
152
+ data_string += f" {'-'*len(data.title)}\n"
153
+ data_string += f" OS: {data.OS}\n"
154
+ data_string += f" Host: {data.Host}\n"
155
+ data_string += f" Kernel: {data.Kernel}\n"
156
+ data_string += f" Uptime: {data.Uptime}\n"
157
+ data_string += f" Shell: {data.Shell}\n"
158
+ data_string += f" CPU: {data.CPU}\n"
159
+ for gpu in data.GPU:
160
+ data_string += f" GPU: {gpu}\n"
161
+ data_string += f" Memory: {data.Memory}\n"
162
+ for nic in data.NIC:
163
+ data_string += f" NIC: {nic}\n"
164
+ for npu in data.NPU:
165
+ data_string += f" NPU: {npu}\n"
166
+ return data_string
167
+
168
+
169
+ @dataclass
170
+ class SupportedOS:
171
+ ColorConfig = ["armbian", "arch", "alpine", "centos", "debian", "fedora", "macOS", "raspbian", "ubuntu"]
172
+ AsciiLogo = ["armbian", "arch", "alpine", "centos", "debian", "fedora", "macOS", "raspbian", "ubuntu"]
173
+
174
+
175
+ def selectOSLogo(os_id: str):
176
+ """
177
+ Select the logo based on the os id and terminal size.
178
+ :param os_id: str, os id.
179
+ :return: str, logo id.
180
+ """
181
+ if getOS() == "macos":
182
+ return os_id
183
+ if os_id in SupportedOS.ColorConfig and os_id in SupportedOS.AsciiLogo:
184
+ pass
185
+ else:
186
+ return "linux"
187
+ rows_str, columns_str = os.popen('stty size', 'r').read().split()
188
+ rows = int(rows_str)
189
+ columns = int(columns_str)
190
+ if columns <= 80:
191
+ if os_id in ["fedora", "ubuntu"]:
192
+ return f"{os_id}_small"
193
+ else:
194
+ return os_id
195
+ else:
196
+ return os_id
197
+
@@ -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
@@ -1,59 +0,0 @@
1
- """
2
- In dev.
3
- """
4
- from ...pyhwUtil import getArch
5
- from .hostInfo import HostInfo
6
- import os
7
-
8
-
9
- class HostDetectLinux:
10
- def __init__(self):
11
- self.__hostInfo = HostInfo()
12
- self.__arch = getArch()
13
-
14
- def getHostInfo(self):
15
- self.__getModel()
16
- return self.__hostInfo
17
-
18
- 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"):
39
- try:
40
- with open("/sys/devices/virtual/dmi/id/product_name", "r") as f:
41
- self.__hostInfo.name = f.read().strip()
42
- with open("/sys/devices/virtual/dmi/id/product_version", "r") as f:
43
- self.__hostInfo.version = f.read().strip()
44
- self.__hostInfo.model = self.__hostInfo.name + " " + self.__hostInfo.version
45
- except FileNotFoundError:
46
- 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
54
-
55
- def __getHostFamily(self):
56
- pass
57
-
58
- def __getHostProductName(self):
59
- pass
@@ -1,4 +0,0 @@
1
- from .pyhwUtil import getOS, getArch, createDataString, selectOSLogo
2
- from .sysctlUtil import sysctlGetString, sysctlGetInt
3
-
4
- __all__ = ["getOS", "getArch", "createDataString", "selectOSLogo", "sysctlGetString", "sysctlGetInt"]
@@ -1,89 +0,0 @@
1
- import platform
2
- from ..backend import Data
3
- import os
4
- from dataclasses import dataclass
5
-
6
-
7
- def getOS():
8
- """
9
- Get the os type in lower case.
10
- :return: str, os type, value in [windows, linux, macos, unknown].
11
- """
12
- system = platform.system()
13
- if system == "Windows":
14
- return "windows"
15
- elif system == "Linux":
16
- return "linux"
17
- elif system == "Darwin":
18
- return "macos"
19
- else:
20
- return "unknown"
21
-
22
-
23
- def getArch():
24
- """
25
- Get the machine architecture.
26
- :return: str, value in [x86_64, x86, aarch64, arm32].
27
- """
28
- arch = platform.machine()
29
- if arch == "x86_64" or arch == "AMD64" or arch == "amd64":
30
- return "x86_64"
31
- elif arch == "i386" or arch == "i686" or arch == "x86":
32
- return "x86"
33
- elif arch == "aarch64" or arch == "arm64":
34
- return "aarch64"
35
- elif arch.find("arm") != -1:
36
- return "arm32"
37
- else:
38
- return "unknown"
39
-
40
-
41
- def createDataString(data: Data):
42
- data_string = ""
43
- data_string += f" {data.title}\n"
44
- data_string += f" {'-'*len(data.title)}\n"
45
- data_string += f" OS: {data.OS}\n"
46
- data_string += f" Host: {data.Host}\n"
47
- data_string += f" Kernel: {data.Kernel}\n"
48
- data_string += f" Uptime: {data.Uptime}\n"
49
- data_string += f" Shell: {data.Shell}\n"
50
- data_string += f" CPU: {data.CPU}\n"
51
- for gpu in data.GPU:
52
- data_string += f" GPU: {gpu}\n"
53
- data_string += f" Memory: {data.Memory}\n"
54
- for nic in data.NIC:
55
- data_string += f" NIC: {nic}\n"
56
- for npu in data.NPU:
57
- data_string += f" NPU: {npu}\n"
58
- return data_string
59
-
60
-
61
- @dataclass
62
- class SupportedOS:
63
- ColorConfig = ["armbian", "arch", "alpine", "centos", "debian", "fedora", "macOS", "raspbian", "ubuntu"]
64
- AsciiLogo = ["armbian", "arch", "alpine", "centos", "debian", "fedora", "macOS", "raspbian", "ubuntu"]
65
-
66
-
67
- def selectOSLogo(os_id: str):
68
- """
69
- Select the logo based on the os id and terminal size.
70
- :param os_id: str, os id.
71
- :return: str, logo id.
72
- """
73
- if getOS() == "macos":
74
- return os_id
75
- if os_id in SupportedOS.ColorConfig and os_id in SupportedOS.AsciiLogo:
76
- pass
77
- else:
78
- return "linux"
79
- rows_str, columns_str = os.popen('stty size', 'r').read().split()
80
- rows = int(rows_str)
81
- columns = int(columns_str)
82
- if columns <= 80:
83
- if os_id in ["fedora", "ubuntu"]:
84
- return f"{os_id}_small"
85
- else:
86
- return os_id
87
- else:
88
- return os_id
89
-
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes