pyhw 0.6.5__py3-none-any.whl → 0.6.6__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,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/pyhwUtil.py CHANGED
@@ -38,7 +38,107 @@ def getArch():
38
38
  return "unknown"
39
39
 
40
40
 
41
+ class DataStringProcessor:
42
+ def __init__(self, data: Data):
43
+ self.data = data
44
+ self.columns = self.__getENV()
45
+
46
+ @staticmethod
47
+ def __getENV() -> int:
48
+ if getOS() == "linux":
49
+ _, columns_str = os.popen('stty size', 'r').read().split()
50
+ columns = int(columns_str)
51
+ else:
52
+ # macOS default terminal size is 80 columns
53
+ columns = 80
54
+ return columns
55
+
56
+ def __dropLongString(self, string: str) -> str:
57
+ """
58
+ Drop the string if it's too long to fit in the terminal.
59
+ :param string: str, the input string.
60
+ :return: str, the shortened string, do not include newline char.
61
+ """
62
+ if len(string) >= self.columns:
63
+ return f"{string[:self.columns-1]}"
64
+ else:
65
+ return f"{string}"
66
+
67
+ def getTitle(self) -> str:
68
+ return f" {self.data.title}\n"
69
+
70
+ def getLine(self) -> str:
71
+ return f" {'-'*len(self.data.title)}\n"
72
+
73
+ def getOS(self) -> str:
74
+ os_str = f" OS: {self.data.OS}"
75
+ return f"{self.__dropLongString(os_str)}\n"
76
+
77
+ def getHost(self) -> str:
78
+ host_str = f" Host: {self.data.Host}"
79
+ return f"{self.__dropLongString(host_str)}\n"
80
+
81
+ def getKernel(self) -> str:
82
+ kernel_str = f" Kernel: {self.data.Kernel}"
83
+ return f"{self.__dropLongString(kernel_str)}\n"
84
+
85
+ def getUptime(self) -> str:
86
+ uptime_str = f" Uptime: {self.data.Uptime}"
87
+ return f"{self.__dropLongString(uptime_str)}\n"
88
+
89
+ def getShell(self) -> str:
90
+ shell_str = f" Shell: {self.data.Shell}"
91
+ return f"{self.__dropLongString(shell_str)}\n"
92
+
93
+ def getCPU(self) -> str:
94
+ cpu_str = f" CPU: {self.data.CPU}"
95
+ return f"{self.__dropLongString(cpu_str)}\n"
96
+
97
+ def getGPU(self) -> str:
98
+ ret_str = ""
99
+ for gpu in self.data.GPU:
100
+ gpu_str = f" GPU: {gpu}"
101
+ ret_str += f"{self.__dropLongString(gpu_str)}\n"
102
+ return ret_str
103
+
104
+ def getMemory(self) -> str:
105
+ memory_str = f" Memory: {self.data.Memory}"
106
+ return f"{self.__dropLongString(memory_str)}\n"
107
+
108
+ def getNIC(self) -> str:
109
+ ret_str = ""
110
+ for nic in self.data.NIC:
111
+ nic_str = f" NIC: {nic}"
112
+ ret_str += f"{self.__dropLongString(nic_str)}\n"
113
+ return ret_str
114
+
115
+ def getNPU(self) -> str:
116
+ ret_str = ""
117
+ for npu in self.data.NPU:
118
+ npu_str = f" NPU: {npu}"
119
+ ret_str += f"{self.__dropLongString(npu_str)}\n"
120
+ return ret_str
121
+
122
+
41
123
  def createDataString(data: Data):
124
+ data_string_processor = DataStringProcessor(data)
125
+ data_string = ""
126
+ data_string += data_string_processor.getTitle()
127
+ data_string += data_string_processor.getLine()
128
+ data_string += data_string_processor.getOS()
129
+ data_string += data_string_processor.getHost()
130
+ data_string += data_string_processor.getKernel()
131
+ data_string += data_string_processor.getUptime()
132
+ data_string += data_string_processor.getShell()
133
+ data_string += data_string_processor.getCPU()
134
+ data_string += data_string_processor.getGPU()
135
+ data_string += data_string_processor.getMemory()
136
+ data_string += data_string_processor.getNIC()
137
+ data_string += data_string_processor.getNPU()
138
+ return data_string
139
+
140
+
141
+ def createDataStringOld(data: Data):
42
142
  data_string = ""
43
143
  data_string += f" {data.title}\n"
44
144
  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.6
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
@@ -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
@@ -81,11 +81,11 @@ pyhw/library/lib/iokitGPULib.dylib,sha256=DcJ0GZY79gTFckLFYtZgeKn1T0NFvdO_k_ccCa
81
81
  pyhw/pyhwException/__init__.py,sha256=8JsFvtF13g0Y5t4z9fRndDXtfCzuBM59jDf6PhWSFSk,220
82
82
  pyhw/pyhwException/pyhwException.py,sha256=wxuzFQa9g7XB1q9TUKO_55lw7wMEJMpzG8w1GVTFVa0,197
83
83
  pyhw/pyhwUtil/__init__.py,sha256=PzeP9fXsIhvr3sUpJ4DxW9_H25DEIasBFfXd_NztfR4,226
84
- pyhw/pyhwUtil/pyhwUtil.py,sha256=CKXJrt6KGhZCV1J7MjsQ21c_jPmC1I3wZBPCKJfdqbM,2478
84
+ pyhw/pyhwUtil/pyhwUtil.py,sha256=0Pn-0MqgloQV_p5HrM3HwrGsA_eB-P2eW2hLJrHWmhk,5762
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.6.dist-info/LICENSE,sha256=hJs6RBqSVCexbTsalkMLNFI5t06kekQEsSVaOt_-yLs,1497
87
+ pyhw-0.6.6.dist-info/METADATA,sha256=lDfujbVf0CPbvs5_n97qzeRBA5Y3xmjQ6hWAsuMIeV4,5225
88
+ pyhw-0.6.6.dist-info/WHEEL,sha256=R06PA3UVYHThwHvxuRWMqaGcr-PuniXahwjmQRFMEkY,91
89
+ pyhw-0.6.6.dist-info/entry_points.txt,sha256=q-AB8im_QahpmNrmy4aPTJRGi0LlbNlnI3kF7s6pKss,44
90
+ pyhw-0.6.6.dist-info/top_level.txt,sha256=7Inxvxt1TngEricKZEex9_WJZS3DbKYFUXDz4v5WHYU,5
91
+ pyhw-0.6.6.dist-info/RECORD,,
File without changes
File without changes