Repository navigation
Expand file tree
/
Copy pathmain.py
More file actions
196 lines (163 loc) · 7.4 KB
/
Copy pathmain.py
File metadata and controls
196 lines (163 loc) · 7.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
import sys
import os
import time
import subprocess
import platform
import psutil
# Safe import for pygame
try:
import pygame
HAS_PYGAME = True
except Exception as e:
HAS_PYGAME = False
print(f"⚠️ Pygame import failed: {e}")
def print_header(title):
print("\n" + "=" * 65)
print(f" {title}")
print("=" * 65)
# --- SYSTEM & HARDWARE SPECS REPORT ---
def test_specs():
print_header("1. SYSTEM & HARDWARE SPECIFICATIONS SUMMARY")
print(f"Operating System : {platform.system()} {platform.release()} ({platform.architecture()[0]})")
print(f"Computer Name : {platform.node()}")
if sys.platform == "win32":
try:
cmd_sys = "Get-CimInstance -ClassName Win32_ComputerSystem | Select-Object Manufacturer, Model | Format-List"
res_sys = subprocess.run(["powershell", "-Command", cmd_sys], capture_output=True, text=True, timeout=5)
print("\n[System Info]")
for line in res_sys.stdout.strip().split("\n"):
if line.strip():
print(f" {line.strip()}")
cmd_bios = "Get-CimInstance -ClassName Win32_BIOS | Select-Object SMBIOSBIOSVersion, ReleaseDate | Format-List"
res_bios = subprocess.run(["powershell", "-Command", cmd_bios], capture_output=True, text=True, timeout=5)
print("\n[BIOS Info]")
for line in res_bios.stdout.strip().split("\n"):
if line.strip():
print(f" {line.strip()}")
except Exception as e:
print(f" Unable to fetch system details: {e}")
print("\n[Processor (CPU)]")
print(f" Model : {platform.processor()}")
print(f" Physical Cores : {psutil.cpu_count(logical=False)}")
print(f" Logical Threads : {psutil.cpu_count(logical=True)}")
ram = psutil.virtual_memory()
total_ram_gb = ram.total / (1024 ** 3)
print("\n[Memory (RAM)]")
print(f" Total Capacity : {total_ram_gb:.2f} GB")
print(f" Available Memory : {ram.available / (1024 ** 3):.2f} GB")
print("\n[Graphics / Display Adapters (GPU)]")
if sys.platform == "win32":
try:
cmd_gpu = "Get-CimInstance -ClassName Win32_VideoController | Select-Object Name, AdapterRAM, DriverVersion, VideoProcessor | Format-Table -AutoSize"
res_gpu = subprocess.run(["powershell", "-Command", cmd_gpu], capture_output=True, text=True, timeout=5)
print(res_gpu.stdout)
except Exception as e:
print(f" Unable to fetch GPU details: {e}")
# --- BATTERY REPORT ---
def test_battery():
print_header("2. BATTERY HEALTH REPORT")
battery = psutil.sensors_battery()
if not battery:
print("❌ Battery information not found (Desktop or missing ACPI driver).")
return
print(f"Current Battery Percentage: {battery.percent}%")
print(f"Power Plugged In: {'Yes' if battery.power_plugged else 'No (Running on Battery)'}")
if sys.platform == "win32":
print("\nGenerating detailed Windows battery report (Powercfg)...")
try:
subprocess.run(["powercfg", "/batteryreport", "/output", "battery_report.html"], check=True, capture_output=True, timeout=10)
print("✅ Detailed battery report saved to 'battery_report.html'.")
except Exception as e:
print(f"❌ Failed to generate battery report: {e}")
# --- STORAGE & SSD HEALTH ---
def test_storage():
print_header("3. STORAGE AND SSD HEALTH CHECK")
print("Active Partitions:")
for part in psutil.disk_partitions():
try:
usage = psutil.disk_usage(part.mountpoint)
print(f" - Drive {part.device} [{part.fstype}]: Total {usage.total // (1024**3)} GB | Free {usage.free // (1024**3)} GB")
except PermissionError:
continue
if sys.platform == "win32":
print("\nQuerying SSD/HDD S.M.A.R.T status via PowerShell...")
try:
cmd = "Get-PhysicalDisk | Select-Object DeviceId, FriendlyName, MediaType, OperationalStatus, HealthStatus | Format-Table -AutoSize"
res_gpu = subprocess.run(["powershell", "-Command", cmd], capture_output=True, text=True, timeout=5)
print(res_gpu.stdout)
except Exception as e:
print(f"❌ Failed to query disk health status: {e}")
# --- DISPLAY / DEAD PIXEL TEST ---
def test_screen():
print_header("4. DISPLAY TEST (DEAD PIXELS & BLEEDING)")
if not HAS_PYGAME:
print("⚠️ Pygame is missing. Skipping screen test.")
return
print("Colors will cycle: Red, Green, Blue, White, Black.")
print("Press SPACE or Click to change color. Press ESC to exit.")
try:
pygame.init()
screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN)
colors = [(255, 0, 0), (0, 255, 0), (0, 0, 255), (255, 255, 255), (0, 0, 0)]
idx = 0
running = True
clock = pygame.time.Clock()
while running:
screen.fill(colors[idx])
pygame.display.flip()
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
running = False
elif event.key == pygame.K_SPACE:
idx = (idx + 1) % len(colors)
elif event.type == pygame.MOUSEBUTTONDOWN:
idx = (idx + 1) % len(colors)
clock.tick(60)
pygame.quit()
except Exception as e:
print(f"❌ Screen test encountered an error: {e}")
# --- KEYBOARD TEST ---
def test_keyboard():
print_header("5. KEYBOARD TEST")
if not HAS_PYGAME:
print("⚠️ Pygame is missing. Skipping keyboard test.")
return
print("Press any key to test its response. Press ESC to stop.")
try:
pygame.init()
pygame.display.set_mode((400, 200))
pygame.display.set_caption("Keyboard Test - Click window to focus")
running = True
pressed_keys = set()
clock = pygame.time.Clock()
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
running = False
else:
key_name = pygame.key.name(event.key)
if key_name not in pressed_keys:
pressed_keys.add(key_name)
print(f"Registered Key: [ {key_name.upper()} ]")
clock.tick(60)
pygame.quit()
print(f"\nTotal unique keys tested: {len(pressed_keys)}")
except Exception as e:
print(f"❌ Keyboard test encountered an error: {e}")
# --- ENTRY POINT ---
print(">>> Starting Laptop Diagnostics Script Execution...")
try:
test_specs()
test_battery()
test_storage()
test_screen()
test_keyboard()
print_header("LAPTOP DIAGNOSTICS COMPLETE")
except Exception as main_err:
print(f"\n❌ CRITICAL SCRIPT ERROR: {main_err}")