Skip to content

Commit ebec76b

Browse files
Merge pull request #2754 from avinashkranjan/deepsource-transform-d52de871
format code with autopep8
2 parents cd404a6 + e9cee2e commit ebec76b

File tree

1 file changed

+58
-19
lines changed

1 file changed

+58
-19
lines changed

Computer-Details/computer-details.py

Lines changed: 58 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import socket
55

66
# Function to get CPU information
7+
8+
79
def get_cpu_info():
810
cpu_info = {}
911
cpu_info['CPU'] = platform.processor()
@@ -13,16 +15,21 @@ def get_cpu_info():
1315
return cpu_info
1416

1517
# Function to get GPU information (for any brand)
18+
19+
1620
def get_gpu_info():
1721
gpu_info = {}
1822
try:
1923
gpus = psutil.virtual_memory().available
2024
if gpus:
21-
gpu_info['GPU Name'] = 'Integrated GPU' # If integrated graphics is available
25+
# If integrated graphics is available
26+
gpu_info['GPU Name'] = 'Integrated GPU'
2227
gpu_info['GPU Memory'] = f"{gpus / (1024 ** 3):.2f} GB"
23-
gpu_info['Driver Version'] = 'N/A' # For integrated GPUs, driver version may not be available
28+
# For integrated GPUs, driver version may not be available
29+
gpu_info['Driver Version'] = 'N/A'
2430
else:
25-
result = subprocess.check_output(["nvidia-smi", "--query-gpu=name,memory.total,driver_version", "--format=csv,noheader"], encoding="utf-8")
31+
result = subprocess.check_output(
32+
["nvidia-smi", "--query-gpu=name,memory.total,driver_version", "--format=csv,noheader"], encoding="utf-8")
2633
gpu_name, memory, driver_version = result.strip().split(',')
2734
gpu_info['GPU Name'] = gpu_name
2835
gpu_info['GPU Memory'] = f"{int(memory.strip().split()[0]) / 1024:.2f} GB"
@@ -34,20 +41,25 @@ def get_gpu_info():
3441
return gpu_info
3542

3643
# Function to get battery status (for laptops)
44+
45+
3746
def get_battery_status():
3847
battery_status = {}
3948
try:
4049
battery = psutil.sensors_battery()
4150
battery_status['Charge Percentage'] = f"{battery.percent}%"
4251
battery_status['Power Plugged'] = "Yes" if battery.power_plugged else "No"
43-
battery_status['Remaining Time'] = "Unknown" if battery.power_plugged else str(battery.secsleft // 60) + " minutes"
52+
battery_status['Remaining Time'] = "Unknown" if battery.power_plugged else str(
53+
battery.secsleft // 60) + " minutes"
4454
except AttributeError:
4555
battery_status['Charge Percentage'] = 'N/A'
4656
battery_status['Power Plugged'] = 'N/A'
4757
battery_status['Remaining Time'] = 'N/A'
4858
return battery_status
4959

5060
# Function to get network interface information
61+
62+
5163
def get_network_info():
5264
network_info = {}
5365
try:
@@ -63,25 +75,31 @@ def get_network_info():
6375
return network_info
6476

6577
# Function to get system temperature (Linux and Windows only)
78+
79+
6680
def get_system_temperature():
6781
temp_info = {}
6882
try:
6983
# sensors = psutil.sensors_temperatures()
7084
temp_info = psutil.sensors_temperatures()['coretemp'][0].current
7185
# for sensor, entries in sensors.items():
72-
# temp_info[sensor] = [f"{entry.current}°C" for entry in entries]
86+
# temp_info[sensor] = [f"{entry.current}°C" for entry in entries]
7387
except Exception as e:
7488
print(f"Error fetching system temperature: {e}")
7589
temp_info = {'Temperature': 'N/A'}
7690
return temp_info
7791

7892
# Function to list installed software (Windows only)
93+
94+
7995
def get_installed_software():
8096
software_list = {}
8197
try:
82-
process = subprocess.Popen(["wmic", "product", "get", "Name"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
98+
process = subprocess.Popen(["wmic", "product", "get", "Name"],
99+
stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
83100
stdout, stderr = process.communicate()
84-
software_list['Installed Software'] = [line.strip() for line in stdout.split('\n') if line.strip()]
101+
software_list['Installed Software'] = [line.strip()
102+
for line in stdout.split('\n') if line.strip()]
85103
except FileNotFoundError:
86104
software_list['Installed Software'] = 'N/A'
87105
except Exception as e:
@@ -90,6 +108,8 @@ def get_installed_software():
90108
return software_list
91109

92110
# Function to list connected USB devices
111+
112+
93113
def get_usb_devices():
94114
usb_devices = []
95115
try:
@@ -102,28 +122,31 @@ def get_usb_devices():
102122
return usb_devices
103123

104124
# Function to get display information (Windows only)
125+
126+
105127
def get_display_info():
106128
display_info = {}
107129
try:
108-
process = subprocess.Popen(["wmic", "desktopmonitor", "get", "ScreenHeight,ScreenWidth", "/format:list"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
130+
process = subprocess.Popen(["wmic", "desktopmonitor", "get", "ScreenHeight,ScreenWidth",
131+
"/format:list"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
109132
stdout, stderr = process.communicate()
110133
lines = [line.strip() for line in stdout.split('\n') if line.strip()]
111-
134+
112135
if len(lines) >= 2:
113136
display_info['Screen Resolution'] = f"{lines[0].split('=')[1]}x{lines[1].split('=')[1]} pixels"
114137
else:
115138
display_info['Screen Resolution'] = 'N/A'
116-
139+
117140
if len(lines) >= 3:
118141
display_info['Color Depth'] = f"{lines[2].split('=')[1]} bits"
119142
else:
120143
display_info['Color Depth'] = 'N/A'
121-
144+
122145
if len(lines) >= 4:
123146
display_info['Refresh Rate'] = f"{lines[3].split('=')[1]} Hz"
124147
else:
125148
display_info['Refresh Rate'] = 'N/A'
126-
149+
127150
except FileNotFoundError:
128151
display_info['Screen Resolution'] = 'N/A'
129152
display_info['Color Depth'] = 'N/A'
@@ -133,12 +156,16 @@ def get_display_info():
133156
return display_info
134157

135158
# Function to get audio devices information (Windows only)
159+
160+
136161
def get_audio_devices_info():
137162
audio_devices_info = {}
138163
try:
139-
process = subprocess.Popen(["powershell", "(Get-WmiObject -Class Win32_SoundDevice).Name"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
164+
process = subprocess.Popen(["powershell", "(Get-WmiObject -Class Win32_SoundDevice).Name"],
165+
stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
140166
stdout, stderr = process.communicate()
141-
audio_devices_info['Audio Devices'] = [line.strip() for line in stdout.split('\n') if line.strip()]
167+
audio_devices_info['Audio Devices'] = [line.strip()
168+
for line in stdout.split('\n') if line.strip()]
142169
except FileNotFoundError:
143170
audio_devices_info['Audio Devices'] = 'N/A'
144171
except Exception as e:
@@ -147,9 +174,12 @@ def get_audio_devices_info():
147174
return audio_devices_info
148175

149176
# Function to check internet connectivity
177+
178+
150179
def check_internet_connectivity():
151180
try:
152-
subprocess.check_call(["ping", "-c", "1", "www.google.com"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
181+
subprocess.check_call(["ping", "-c", "1", "www.google.com"],
182+
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
153183
return True
154184
except subprocess.CalledProcessError:
155185
return False
@@ -158,6 +188,8 @@ def check_internet_connectivity():
158188
return False
159189

160190
# Function to get current date and time
191+
192+
161193
def get_current_date_time():
162194
import datetime
163195
try:
@@ -167,6 +199,8 @@ def get_current_date_time():
167199
return 'N/A'
168200

169201
# Function to get total and available RAM and disk space
202+
203+
170204
def get_memory_disk_space_info():
171205
try:
172206
svmem = psutil.virtual_memory()
@@ -192,6 +226,7 @@ def get_memory_disk_space_info():
192226
'Available Disk Space': 'N/A'
193227
}
194228

229+
195230
if __name__ == "__main__":
196231
if platform.system() != 'Windows':
197232
print("Sorry, the script is currently available only for Windows Operating System")
@@ -231,7 +266,11 @@ def get_memory_disk_space_info():
231266

232267
print("\n---- RAM and Disk Space Information ----")
233268
memory_disk_info = get_memory_disk_space_info()
234-
print(f"Total Memory (RAM): {memory_disk_info['Total Memory (RAM)']:.2f} GB")
235-
print(f"Available Memory (RAM): {memory_disk_info['Available Memory (RAM)']:.2f} GB")
236-
print(f"Total Disk Space: {memory_disk_info['Total Disk Space']:.2f} GB")
237-
print(f"Available Disk Space: {memory_disk_info['Available Disk Space']:.2f} GB")
269+
print(
270+
f"Total Memory (RAM): {memory_disk_info['Total Memory (RAM)']:.2f} GB")
271+
print(
272+
f"Available Memory (RAM): {memory_disk_info['Available Memory (RAM)']:.2f} GB")
273+
print(
274+
f"Total Disk Space: {memory_disk_info['Total Disk Space']:.2f} GB")
275+
print(
276+
f"Available Disk Space: {memory_disk_info['Available Disk Space']:.2f} GB")

0 commit comments

Comments
 (0)