quickspec 0.1.0__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.
quickspec/__init__.py ADDED
@@ -0,0 +1 @@
1
+ # quickspec 套件初始化檔案
quickspec/main.py ADDED
@@ -0,0 +1,177 @@
1
+ import sys
2
+ from datetime import datetime
3
+ def get_detail():
4
+ detail = {}
5
+ if wmi:
6
+ c = wmi.WMI()
7
+ # 主機板型號
8
+ try:
9
+ board = c.Win32_BaseBoard()[0]
10
+ detail['Motherboard'] = f"{board.Manufacturer} {board.Product}"
11
+ except Exception:
12
+ detail['Motherboard'] = 'Unknown'
13
+ # BIOS 版本
14
+ try:
15
+ bios = c.Win32_BIOS()[0]
16
+ detail['BIOS'] = f"{bios.Manufacturer} {bios.SMBIOSBIOSVersion} ({bios.ReleaseDate})"
17
+ except Exception:
18
+ detail['BIOS'] = 'Unknown'
19
+ # 網路卡資訊
20
+ try:
21
+ nics = c.Win32_NetworkAdapter()
22
+ nic_list = [nic.Name for nic in nics if nic.PhysicalAdapter]
23
+ detail['Network Adapters'] = ', '.join(nic_list) if nic_list else 'None'
24
+ except Exception:
25
+ detail['Network Adapters'] = 'Unknown'
26
+ # 顯示器解析度
27
+ try:
28
+ screens = c.Win32_DesktopMonitor()
29
+ res_list = [f"{s.ScreenWidth}x{s.ScreenHeight}" for s in screens if s.ScreenWidth and s.ScreenHeight]
30
+ detail['Display Resolution'] = ', '.join(res_list) if res_list else 'Unknown'
31
+ except Exception:
32
+ detail['Display Resolution'] = 'Unknown'
33
+ # 系統開機時間
34
+ try:
35
+ os = c.Win32_OperatingSystem()[0]
36
+ boot_time = datetime.strptime(os.LastBootUpTime.split('.')[0], "%Y%m%d%H%M%S")
37
+ uptime = datetime.now() - boot_time
38
+ detail['Boot Time'] = boot_time.strftime('%Y-%m-%d %H:%M:%S')
39
+ detail['Uptime'] = str(uptime).split('.')[0]
40
+ except Exception:
41
+ detail['Boot Time'] = 'Unknown'
42
+ detail['Uptime'] = 'Unknown'
43
+ # 處理器快取(L2/L3)
44
+ try:
45
+ cpu = c.Win32_Processor()[0]
46
+ detail['CPU Cache'] = f"L2: {cpu.L2CacheSize} KB, L3: {cpu.L3CacheSize} KB"
47
+ except Exception:
48
+ detail['CPU Cache'] = 'Unknown'
49
+ # 虛擬化支援
50
+ try:
51
+ cpu = c.Win32_Processor()[0]
52
+ detail['Virtualization'] = 'Enabled' if getattr(cpu, 'VirtualizationFirmwareEnabled', False) else 'Disabled'
53
+ except Exception:
54
+ detail['Virtualization'] = 'Unknown'
55
+ # 電池資訊(筆電)
56
+ try:
57
+ batteries = c.Win32_Battery()
58
+ if batteries:
59
+ bat = batteries[0]
60
+ detail['Battery'] = f"{bat.Name}, {bat.EstimatedChargeRemaining}%"
61
+ else:
62
+ detail['Battery'] = 'No Battery'
63
+ except Exception:
64
+ detail['Battery'] = 'Unknown'
65
+ else:
66
+ detail['Detail'] = 'WMI not available on this system.'
67
+ return detail
68
+ def print_detail():
69
+ detail = get_detail()
70
+ print("=== Computer Detail Information ===")
71
+ for k, v in detail.items():
72
+ print(f"{k}: {v}")
73
+ import platform
74
+ import psutil
75
+
76
+ try:
77
+ import cpuinfo
78
+ except ImportError:
79
+ cpuinfo = None
80
+ import importlib
81
+ GPUtil = None
82
+ gputil_import_error = None
83
+ try:
84
+ GPUtil = importlib.import_module('GPUtil')
85
+ except Exception as e:
86
+ gputil_import_error = str(e)
87
+
88
+ # WMI for Windows GPU detection
89
+ wmi = None
90
+ wmi_import_error = None
91
+ try:
92
+ wmi = importlib.import_module('wmi')
93
+ except Exception as e:
94
+ wmi_import_error = str(e)
95
+
96
+ def get_spec():
97
+ info = {}
98
+ info['OS'] = platform.platform()
99
+ if cpuinfo:
100
+ cpu = cpuinfo.get_cpu_info()
101
+ cpu_name = cpu.get('brand_raw', 'Unknown')
102
+ else:
103
+ cpu_name = platform.processor() or 'Unknown'
104
+ cpu_cores = psutil.cpu_count(logical=False)
105
+ cpu_threads = psutil.cpu_count(logical=True)
106
+ info['CPU'] = f"{cpu_name} ({cpu_cores} Cores + {cpu_threads} Threads)"
107
+ info['CPU Frequency'] = f"{psutil.cpu_freq().current:.2f} MHz" if psutil.cpu_freq() else 'Unknown'
108
+ mem = psutil.virtual_memory()
109
+ mem_used = mem.used / (1024**3)
110
+ mem_total = mem.total / (1024**3)
111
+ mem_percent = mem.percent
112
+ info['Memory'] = f"{mem_used:.2f} GB / {mem_total:.2f} GB ({mem_percent:.1f}%)"
113
+
114
+ disk = psutil.disk_usage('/')
115
+ disk_total = disk.total / (1024**3)
116
+ disk_free = disk.free / (1024**3)
117
+ disk_used = disk_total - disk_free
118
+ disk_percent = disk.percent
119
+ info['Disk'] = f"{disk_used:.2f} GB / {disk_total:.2f} GB ({disk_percent:.1f}%)"
120
+ # GPU 資訊(優先使用 wmi,支援所有 Windows 顯示卡)
121
+ gpu_list = []
122
+ if wmi:
123
+ try:
124
+ c = wmi.WMI()
125
+ for gpu in c.Win32_VideoController():
126
+ name = gpu.Name
127
+ ram = int(gpu.AdapterRAM) // (1024**2) if gpu.AdapterRAM else 'Unknown'
128
+ gpu_list.append(f"{name} ({ram}MB)")
129
+ except Exception as e:
130
+ gpu_list.append(f"WMI error: {e}")
131
+ elif wmi_import_error:
132
+ gpu_list.append(f"WMI import error: {wmi_import_error}")
133
+ # 若 wmi 無法使用,則用 GPUtil
134
+ elif GPUtil:
135
+ gpus = GPUtil.getGPUs()
136
+ if gpus:
137
+ for idx, gpu in enumerate(gpus):
138
+ gpu_list.append(f"{gpu.name} ({gpu.driver}) {gpu.memoryTotal}MB")
139
+ else:
140
+ gpu_list.append('No GPU detected')
141
+ elif gputil_import_error:
142
+ gpu_list.append(f'GPUtil import error: {gputil_import_error}')
143
+ else:
144
+ gpu_list.append('No GPU detected')
145
+ # 顯示所有 GPU
146
+ for idx, gpu_info in enumerate(gpu_list):
147
+ info[f'GPU {idx+1}'] = gpu_info
148
+ return info
149
+
150
+ def print_spec():
151
+ spec = get_spec()
152
+ print("=== Computer Specification ===")
153
+ # 顯示順序:OS, CPU, CPU Frequency, GPU, Memory, Disk
154
+ order = [
155
+ 'OS',
156
+ 'CPU',
157
+ 'CPU Frequency',
158
+ ]
159
+ # GPU 可能有多個
160
+ gpu_keys = [k for k in spec.keys() if k.startswith('GPU')]
161
+ order.extend(gpu_keys)
162
+ order.extend([
163
+ 'Memory',
164
+ 'Disk',
165
+ ])
166
+ for k in order:
167
+ if k in spec:
168
+ print(f"{k}: {spec[k]}")
169
+
170
+ if __name__ == "__main__":
171
+ if '--detail' in sys.argv:
172
+ print_spec()
173
+ print()
174
+ print_detail()
175
+ print()
176
+ else:
177
+ print_spec()
@@ -0,0 +1,14 @@
1
+ Metadata-Version: 2.4
2
+ Name: quickspec
3
+ Version: 0.1.0
4
+ Summary: 快速顯示電腦硬體規格的 CLI 工具
5
+ Author: HenryLok0
6
+ Requires-Python: >=3.7
7
+ License-File: LICENSE
8
+ Requires-Dist: psutil
9
+ Requires-Dist: py-cpuinfo
10
+ Dynamic: author
11
+ Dynamic: license-file
12
+ Dynamic: requires-dist
13
+ Dynamic: requires-python
14
+ Dynamic: summary
@@ -0,0 +1,8 @@
1
+ quickspec/__init__.py,sha256=3kOk4NjErMn2wLvoUPwNF3Va6Wb2fP3h5WU-FHiyNtY,35
2
+ quickspec/main.py,sha256=6Wrh4ap5WICetJpV2QFZN2iowpa0pm7YVernO-BEcvM,6231
3
+ quickspec-0.1.0.dist-info/licenses/LICENSE,sha256=JjrlcML_ynBnq0qnxmdqABoPn6by_-5_JiTWBromzU8,1087
4
+ quickspec-0.1.0.dist-info/METADATA,sha256=147ifN_WWYzSON573H3f1M1BcwS_vusN2nR_RuFc_MU,335
5
+ quickspec-0.1.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
6
+ quickspec-0.1.0.dist-info/entry_points.txt,sha256=eOrINN9p3O3ShWlqiKLUKKJ8cejVGDHlN_z9wsGgsIY,56
7
+ quickspec-0.1.0.dist-info/top_level.txt,sha256=BbZBddM48vcXgeggMXpDoVYKHPhvXzuKhAk_CeqO8Ps,10
8
+ quickspec-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (80.9.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ quickspec = quickspec.main:print_spec
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Henry Lok
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ quickspec