Rewrite of data saving and storing

Moved all the output formatting strings to the save method of class
SystemInformation. Now data stored in class members are the raw output of class
methods.
This commit is contained in:
Dionisio E Alonso 2015-04-09 16:47:04 -03:00
parent 8b3c471361
commit a9269dd622
1 changed files with 13 additions and 13 deletions

View File

@ -25,15 +25,11 @@ def get_registry_value(key, subkey, value):
class SystemInformation:
def __init__(self):
self.cpu = 'CPU:\t{}'.format(self._cpu().strip())
self.graphics = 'Video:\t{}'.format(self._graphics())
self.cpu = self._cpu().strip()
self.graphics = 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.os = 'OS:\t{}'.format(self._os_version())
self.hdFree = self._disk_c()
self.os = self._os_version()
def _cpu(self):
return get_registry_value(
@ -132,14 +128,18 @@ class SystemInformation:
return '{} {} (build {})'.format(os, sp, build)
def save(self):
hdd = []
for part in self.hdFree:
hdd.append('{} {:.2f}GB free'.format(part[0], part[1]/(1024**3)))
hdstring = ', '.join(hdd)
with open('system_information.txt', 'w') as f:
f.write('System Information\n'
'==================\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')
f.write('CPU:\t{}\n'.format(self.cpu))
f.write('Video:\t{}\n'.format(self.graphics))
f.write('RAM:\t{:.2f}GB total\n'.format(self.totalRam/(1024**3)))
f.write('HDD:\t{}\n'.format(hdstring))
f.write('OS:\t{}\n'.format(self.os))
if __name__ == '__main__':
sys = SystemInformation()