mirror of https://gitlab.com/baco/winsysinfo.git
Initial commit
This commit is contained in:
commit
efea2b5161
|
@ -0,0 +1,134 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# SystemInformation.py
|
||||
#
|
||||
# "THE BEER-WARE LICENSE" (Revision 42):
|
||||
# Dionisio E Alonso <dealonso@gmail.com> wrote this file. As long as you
|
||||
# retain this notice you can do whatever you want with this stuff. If we
|
||||
# meet some day, and you think this stuff is worth it, you can buy me a
|
||||
# beer in return
|
||||
#
|
||||
# with by Baco
|
||||
#
|
||||
|
||||
import winreg
|
||||
import ctypes
|
||||
import string
|
||||
|
||||
|
||||
def get_registry_value(key, subkey, value):
|
||||
key = getattr(winreg, key)
|
||||
handle = winreg.OpenKey(key, subkey)
|
||||
(value, type) = winreg.QueryValueEx(handle, value)
|
||||
return value
|
||||
|
||||
|
||||
class SystemInformation:
|
||||
def __init__(self):
|
||||
self.cpu = 'CPU:\t{}'.format(self._cpu())
|
||||
self.graphics = 'Video:\t{}'.format(self._graphics())
|
||||
self.totalRam, self.availableRam = self._ram()
|
||||
self.ram = 'RAM:\t{:.2f}GB total'.format(self.totalRam/(1024**3))
|
||||
hdd = []
|
||||
for part in self._disk_c():
|
||||
hdd.append('{} {:.2f}GB free'.format(part[0], part[1]/(1024**3)))
|
||||
self.hdFree = 'HDD:\t{}'.format(', '.join(hdd))
|
||||
# self.hdFree = 'HDD:\t{:.2f}GB free'.format(self._disk_c()/(1024**3))
|
||||
self.os = 'OS:\t{}'.format(self._os_version())
|
||||
|
||||
def _cpu(self):
|
||||
return get_registry_value(
|
||||
'HKEY_LOCAL_MACHINE',
|
||||
'HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0',
|
||||
'ProcessorNameString')
|
||||
|
||||
def _graphics(self):
|
||||
reg_keys = []
|
||||
for device in range(16):
|
||||
try:
|
||||
video_card_string = get_registry_value(
|
||||
'HKEY_LOCAL_MACHINE',
|
||||
'HARDWARE\\DEVICEMAP\\VIDEO',
|
||||
'\Device\Video{}'.format(device))
|
||||
reg_key = video_card_string.split('\\')[-2]
|
||||
# Probe keys to avoid software devices
|
||||
get_registry_value(
|
||||
'HKEY_LOCAL_MACHINE',
|
||||
'SYSTEM\\CurrentControlSet\\Control\\Video\\'
|
||||
'{}\\0000'.format(reg_key),
|
||||
'HardwareInformation.AdapterString')
|
||||
reg_keys.append(reg_key)
|
||||
except:
|
||||
pass
|
||||
|
||||
video_cards = []
|
||||
for video_card in reg_keys:
|
||||
device_descrption = get_registry_value(
|
||||
'HKEY_LOCAL_MACHINE',
|
||||
'SYSTEM\\CurrentControlSet\\Control\\Video\\'
|
||||
'{}\\0000'.format(video_card),
|
||||
'Device Description')
|
||||
video_cards.append(device_descrption)
|
||||
return '\n\t'.join(video_cards)
|
||||
|
||||
def _ram(self):
|
||||
kernel32 = ctypes.windll.kernel32
|
||||
c_ulong = ctypes.c_ulong
|
||||
|
||||
class MemoryStatus(ctypes.Structure):
|
||||
_fields_ = [('dwLength', c_ulong),
|
||||
('dwMemoryLoad', c_ulong),
|
||||
('dwTotalPhys', c_ulong),
|
||||
('dwAvailPhys', c_ulong),
|
||||
('dwTotalPageFile', c_ulong),
|
||||
('dwAvailPageFile', c_ulong),
|
||||
('dwTotalVirtual', c_ulong),
|
||||
('dwAvailVirtual', c_ulong)]
|
||||
|
||||
mem_status = MemoryStatus()
|
||||
mem_status.dwLength = ctypes.sizeof(MemoryStatus)
|
||||
kernel32.GlobalMemoryStatus(ctypes.byref(mem_status))
|
||||
return (mem_status.dwTotalPhys, mem_status.dwAvailPhys)
|
||||
|
||||
def _disk_c(self):
|
||||
drives = [c + ':' for c in list(string.ascii_uppercase)]
|
||||
freeuser = ctypes.c_int64()
|
||||
total = ctypes.c_int64()
|
||||
free = ctypes.c_int64()
|
||||
free_values = []
|
||||
for drive in drives:
|
||||
ctypes.windll.kernel32.GetDiskFreeSpaceExW(drive,
|
||||
ctypes.byref(freeuser),
|
||||
ctypes.byref(total),
|
||||
ctypes.byref(free))
|
||||
if freeuser.value != 0:
|
||||
free_values.append((drive, freeuser.value))
|
||||
freeuser.value = 0
|
||||
return free_values
|
||||
|
||||
def _os_version(self):
|
||||
def get(key):
|
||||
return get_registry_value(
|
||||
'HKEY_LOCAL_MACHINE',
|
||||
'SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion', key)
|
||||
os = get('ProductName')
|
||||
try:
|
||||
sp = get('CSDVersion')
|
||||
except:
|
||||
sp = get('CSDBuildNumber')
|
||||
build = get('CurrentBuildNumber')
|
||||
return '{} {} (build {})'.format(os, sp, build)
|
||||
|
||||
def save(self):
|
||||
with open('system_information.txt', 'w') as f:
|
||||
f.write('System Information\n')
|
||||
f.write('==================\n\n')
|
||||
f.write(self.cpu + '\n')
|
||||
f.write(self.graphics + '\n')
|
||||
f.write(self.ram + '\n')
|
||||
f.write(self.hdFree + '\n')
|
||||
f.write(self.os + '\n')
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys = SystemInformation()
|
||||
sys.save()
|
Loading…
Reference in New Issue