Skip to content

Instantly share code, notes, and snippets.

@dnlsrl
Created December 4, 2017 23:16
Show Gist options
  • Save dnlsrl/a286d202481f24e4652ad29899fefb5c to your computer and use it in GitHub Desktop.
Save dnlsrl/a286d202481f24e4652ad29899fefb5c to your computer and use it in GitHub Desktop.
Specschecker. A python script to query the detailed specs for your computer (only Windows - for now)
Specschecker - A python script to check a computer's most basic specifications.
Changelog:
# v1
Creation!
#v1.1
- Fixed an error causing the program to crash on systems below Windows 10
* SystemSKUNumber property of Win32_ComputerSystem WMI Class is not supported in other systems
- Fixed an error causing the program to show wrong numbers in RAM and HDD specs
* Ditched psutil
- Added an exception for Lenovo machines which Model comes in the Version property of Win32_ComputerSystemProduct
instead of the Name property
#v1.2
- Ability to name the output file added, default name set as the system name
(example: "Home-PC.txt")
- Fixed an error that didn't show the part numbers on Windows 10
#v1.3
- Fixed an screw up in my code.
#v1.4
- Another screw-up fixed: If several disks are in the computer, display only the largest one.
#v1.5
- Better HDD disks storage space display both in screen and text/csv files
#v1.6
- Another screw up fixed, sorry
- Removed unnecessary code (apparently)
- USB disk identifier
#v1.7
- Remove changelog to a separate file.
- Fixed a mistake that displayed the full list of disk capacities under de 'HDD1' entry of the csv file instead of only
the HDD1 capacity.
- Better display for several storage disks (not labeling them as 'HDD' for one)
#v1.8
- Fixed a bug that made the program stop in computers with only one storage device.
- Added feature to check for proper filename
#v1.9
- Added ability to check HDD(s)' model and serial and RAM(s)' part number and serial
- Best stable(?) version ever!
#!/usr/bin/env python
# -*- coding: utf-8 -*-
u'''This is a personal programming project. It's also a rookie practice. You can tell because of the mess in my code.
I googled a lot and some code is not really mine. I didn't copy-paste of course, though. I rewrote it myself to understand it.
Some code was made with the help of MS Scriptomatic V2, which I found really handy. You should use it as well.
Use, change, and improve at your will.
Created by dnlsrl (https://github.com/dnlsrl)
dnlsrl dot kaiser at gmail dot com
'''
# To-dos:
# Add confusing help command
# Add command-line usability (parameters)
from __future__ import with_statement
from __future__ import division
from __future__ import absolute_import
import os
import sys
import platform
import win32com.client
import csv
from io import open
overall = {u'OS':u'', u'usr':u'', u'pc':u'', u'internal': [{u'RAM':0, u'Storage':[[], []], u'HDDStat':[], u'Platform':u''}], u'phys': []}
forExportation = [{}]
heads = []
name = u''
def isvalidname(string):
other = u"#%&\{\}<>*?/$!¡\"«»:\@;+`|='() "
error = 0
erlen = 0
if len(string) > 0:
for n in string:
if n.isspace():
error += 1
elif n in other:
error += 1
if len(string) <= 30 and error == 0:
return True
elif len(string) > 30:
erlen = -1
return erlen
else:
return unicode(error)
else:
return False
def main():
u'''Start here'''
# To-dos:
# Add some menu for the user to interact with
# Agh
# What a hassle
print u'=== Welcome to Specschecker v1.8 ==='
print u'This program checks for the basic local PC technical specifications\n'
# usrMenu()
start()
#def usrMenu():
# '''Menu for the user to interact with'''
# print('Please enter a command. Use the command \'start\' to run the program. Use the command \'help\' for assistance')
# usrchoice = input('> ')
# if usrchoice.lower == 'start':
# start()
# elif usrchoice.lower == 'help':
# halp()
#def halp():
# '''Write help documentation. Make as confusing as possible.'''
# To-dos:
# Everything
def start():
u'''This is where the magic happens'''
getOS()
getUSR()
getPCNAME()
getINTERNAL()
getPHYSICAL()
print u'== Showing details for %s ==' % (platform.node())
print u'System name: %s' % (overall[u'pc'])
forExportation[0][u'System Name'] = overall[u'pc']
heads.append(u'System Name')
print u'Manufacturer/Vendor: %s' % (overall[u'phys'][2])
forExportation[0][u'Vendor'] = overall[u'phys'][2]
heads.append(u'Vendor')
print u"Model: %s" % (overall[u'phys'][1])
forExportation[0][u'Model'] = overall[u'phys'][1]
heads.append(u'Model')
print u"Serial Number: %s" % (overall[u'phys'][0])
forExportation[0][u'SN'] = overall[u'phys'][0]
heads.append(u'SN')
print u'Part Number: %s' % (overall[u'phys'][3])
forExportation[0][u'PN'] = overall[u'phys'][3]
heads.append(u'PN')
print u'OS: %s' % (overall[u'OS'])
forExportation[0][u'OS'] = overall[u'OS']
heads.append(u'OS')
forExportation[0][u'Platform'] = overall[u'internal'][0][u'Platform']
heads.append(u'Platform')
print u'RAM: %iGB' % (overall[u'internal'][0][u'RAM'])
forExportation[0][u'RAM'] = overall[u'internal'][0][u'RAM']
heads.append(u'RAM')
if len(overall[u'internal'][0][u'Storage'][0]) > 1:
for x in xrange(0, len(overall[u'internal'][0][u'Storage'][0])):
head = u'Disk%i' % (x+1)
forExportation[0][u'Disk%i' % (x+1)] = 0
heads.append(head)
if overall[u'internal'][0][u'Storage'][1][x] != u'USB':
print u'Disk %i: %.2fGB / Status: %s' % (x+1, overall[u'internal'][0][u'Storage'][0][x], overall[u'internal'][0][u'HDDStat'][x])
forExportation[0][u'Disk%i' % (x+1)] = overall[u'internal'][0][u'Storage'][0][x]
forExportation[0][u'HDDStat'] = overall[u'internal'][0][u'HDDStat'][x]
heads.append(u'HDDStat')
else:
print u'Disk %i: %.2fGB (USB)' % (x+1, overall[u'internal'][0][u'Storage'][0][x])
forExportation[0][u'Disk%i' % (x+1)] = overall[u'internal'][0][u'Storage'][0][x]
else:
print u'Disk: %.2fGB / Status: %s' % (overall[u'internal'][0][u'Storage'][0][0], overall[u'internal'][0][u'HDDStat'][0])
forExportation[0][u'Disk'] = max(overall[u'internal'][0][u'Storage'][0])
forExportation[0][u'HDDStat'] = overall[u'internal'][0][u'HDDStat'][0]
heads.append(u'HDDStat')
heads.append(u'Disk')
print u'Current user: %s\n' % (overall[u'usr'])
forExportation[0][u'User'] = overall[u'usr']
heads.append(u'User')
toFile()
def getOS():
# It works with Windows 8, 8.1, 10 for now, add other operative systems
sysm = sys.platform
pltform = u''
if sysm == u'win32':
# I don't really know if there are other platforms aside i386 and x86_64 / AMD64
# Probably need to dig into that
strComputer = u"."
objWMIService = win32com.client.Dispatch(u"WbemScripting.SWbemLocator")
objSWbemServices = objWMIService.ConnectServer(strComputer,u"root\cimv2")
colItems = objSWbemServices.ExecQuery(u"SELECT * FROM Win32_OperatingSystem")
for objItem in colItems:
if objItem.Caption != None:
overall[u'OS'] = objItem.Caption
#Machine platform overall[internal][0]
if platform.machine() == u'i386':
pltform = u'x86'
overall[u'internal'][0][u'Platform'] = pltform
else:
pltform = u'x64'
overall[u'internal'][0][u'Platform'] = pltform
def getUSR():
usr = os.environ[u'USERNAME']
overall[u'usr'] = usr
def getPCNAME():
pc = platform.node()
overall[u'pc'] = pc
def getINTERNAL():
# I don't know how to do this, halp
# Code taken form Scriptomatic V2, I'M SORRY
strComputer = u"."
objWMIService = win32com.client.Dispatch(u"WbemScripting.SWbemLocator")
objSWbemServices = objWMIService.ConnectServer(strComputer,u"root\cimv2")
colItems = objSWbemServices.ExecQuery(u"SELECT * FROM Win32_DiskDrive")
for objItem in colItems:
# Disk size [1]
if objItem.Size != None:
overall[u'internal'][0][u'Storage'][0].append(int(objItem.Size) / (1024 ** 3))
if objItem.InterfaceType != None:
overall[u'internal'][0][u'Storage'][1].append(objItem.InterfaceType)
if objItem.Status != None:
overall[u'internal'][0][u'HDDStat'].append(objItem.Status)
# Number of partitions (might be of use)
#if objItem.Partitions != None:
# print ("Partitions:" + str(objItem.Partitions))
# RAM capacity [3]
colItems1 = objSWbemServices.ExecQuery(u"SELECT * FROM Win32_ComputerSystem")
for objItem in colItems1:
if objItem.TotalPhysicalMemory != None:
overall[u'internal'][0][u'RAM'] = round(int(objItem.TotalPhysicalMemory) / (1024 ** 3))
def getPHYSICAL():
# Code taken from Scriptomatic V2
ver = u''
strComputer = u'.'
objWMIService = win32com.client.Dispatch(u'WbemScripting.SWbemLocator')
objSWbemServices = objWMIService.ConnectServer(strComputer,u'root\cimv2')
colItems0 = objSWbemServices.ExecQuery(u'SELECT * FROM Win32_ComputerSystemProduct')
colItems1 = objSWbemServices.ExecQuery(u"SELECT * FROM Win32_ComputerSystem")
colItems2 = objSWbemServices.ExecQuery(u"SELECT * FROM Win32_OperatingSystem")
for objItem in colItems0:
# Serial Number [0]
if objItem.IdentifyingNumber != None:
overall[u'phys'].append(objItem.IdentifyingNumber)
# Model [1] / Doesn't get *real* model, FIX!
if objItem.Name != None and objItem.Vendor != u'LENOVO':
overall[u'phys'].append(objItem.Name)
else:
overall[u'phys'].append(objItem.Version + u' Machine Type ' + objItem.Name)
# Vendor/Manufacturer[2]
if objItem.Vendor != None:
overall[u'phys'].append(objItem.Vendor)
# UUID, might be useful someday, maybe?
#if objItem.UUID != None:
# print ("UUID:" + str(objItem.UUID))
for objItem in colItems2:
if objItem.Version != None:
ver = objItem.Version[0:2]
if ver == u'10':
for objItem in colItems1:
# Part Number [3]
if objItem.SystemSKUNumber != None:
overall[u'phys'].append(objItem.SystemSKUNumber)
else:
overall[u'phys'].append(u'N/A')
def nameFile():
global name
x = u''
choice = raw_input(u'Do you wish to name your file? (Y/n) ')
if choice.lower() == u'y':
x = raw_input(u'Input a name: ')
y = isvalidname(x)
if y == True:
name = x
elif y == -1:
print u'The name you inputted is too long, please make it shorter than 31 characters'
nameFile()
elif y == False:
print u'There was no input, try again'
nameFile()
else:
print u'There were %s invalid characters in your input, remember to only use alphanumerical values, dashes and underscores. Try again.' % (y)
nameFile()
elif choice.lower() == u'n':
name = overall[u'pc']
else:
print u'You didn\'t select a choice. Try again.'
nameFile()
def toFile():
u'''Prompt the user to indicate whether to save collected data to a file'''
# I don't know what I'm doing (http://i3.kym-cdn.com/photos/images/original/000/234/765/b7e.jpg)
ask = raw_input(u'Do you want to save this information to a file? (Y/n) ')
if ask.lower() == u'' or ask.lower() == u'y':
print u'\nSelect a format:'
print u'1) CSV'
print u'2) Plain Text'
again = raw_input(u'> ')
if again == u'1':
nameFile()
createCSV(name)
kill()
elif again == u'2':
nameFile()
createTEXT(name)
kill()
# Add more file formats
else:
print u'Sorry, try again'
toFile()
elif ask.lower() == u'n':
kill()
else:
print u'Sorry, try again'
toFile()
def cleanup():
while len(forExportation[0]) != 0:
for x in heads:
if x in forExportation[0]:
forExportation[0].pop(x)
overall[u'internal'][0][u'Storage'][0].clear()
overall[u'internal'][0][u'Storage'][1].clear()
overall[u'internal'][0][u'HDDStat'].clear()
overall[u'phys'].clear()
heads.clear()
def kill():
u'''Terminates de program'''
# Is this even necessary?
global heads
ask = raw_input(u'Exit the program? (Y/n) ')
if ask.lower() == u'' or ask.lower() == u'y':
print u'Closing...'
return 0
elif ask.lower() == u'n':
print u'\n'
cleanup()
start()
else:
kill()
def createCSV(filename):
u'''Creates a csv file with the collected data'''
# Here goes nothing
# EDIT: Success!!!
with open(u'%s.csv' % (filename), u'w', newline = u'') as specsfile:
spec = csv.DictWriter(specsfile, delimiter = ',', fieldnames = heads)
spec.writeheader()
for row in forExportation:
spec.writerow(row)
print u'File created and saved as "%s.csv"' % filename
def createTEXT(filename):
u'''Creates a plain text file with the collected data'''
# Here goes nothing
# EDIT: IT WORKS!! YAY!
with open(u'%s.txt' % (filename), u'w') as specstxt:
specstxt.write(u'== Showing details for %s ==\n' % (platform.node()))
specstxt.write(u'System name: %s\n' % (overall[u'pc']))
specstxt.write(u'Vendor: %s\n' % (overall[u'phys'][2]))
specstxt.write(u'Model: %s\n' % (overall[u'phys'][1]))
specstxt.write(u'Serial Number: %s\n' % (overall[u'phys'][0]))
specstxt.write(u'Part Number: %s\n' % (overall[u'phys'][3]))
specstxt.write(u'OS: %s\n' % (overall[u'OS']))
specstxt.write(u'RAM: %iGB\n' % (overall[u'internal'][0][u'RAM']))
if len(overall[u'internal'][0][u'Storage'][0]) > 1:
for x in xrange(0, len(overall[u'internal'][0][u'Storage'][0])):
if overall[u'internal'][0][u'Storage'][1][x] != u'USB':
specstxt.write(u'Disk %i: %.2fGB / Status: %s\n' % (x+1, overall[u'internal'][0][u'Storage'][0][x], overall[u'internal'][0][u'HDDStat'][x]))
else:
specstxt.write(u'Disk %i: %.2fGB (USB)\n' % (x+1, overall[u'internal'][0][u'Storage'][0][x]))
else:
specstxt.write(u'Disk: %.2fGB / Status: %s\n' % (overall[u'internal'][0][u'Storage'][0][0], overall[u'internal'][0][u'HDDStat'][0]))
specstxt.write(u'Current user: %s\n' % (overall[u'usr']))
print u'File created and saved as "%s.txt"' % (filename)
main()
#!/usr/bin/env python
'''
This is a personal programming project. It's also a rookie practice. You can tell because of the mess in my code.
I googled a lot and some code is not really mine. I didn't copy-paste of course, though. I rewrote it myself to understand it.
Some code was made with the help of MS Scriptomatic V2, which I found really handy. You should use it as well.
Use, change, and improve at your will.
Created by dnlsrl (https://github.com/dnlsrl)
dnlsrl dot kaiser at gmail dot com
'''
# To-dos:
# Add confusing help command
# Add command-line usability (parameters)
import os
import sys
import platform
import win32com.client
import csv
overall = {'OS':'', 'usr':'', 'pc':'', 'internal': [{'RAM':[[], []], 'Storage':[[], []], 'HDDStat':[], 'Platform':'', 'Phys':[[], [], [], []]}], 'phys': []}
forExportation = [{}]
heads = []
name = ''
def isvalidname(string):
other = "#%&\{\}<>*?/$!¡\"«»:\@;+`|='() "
error = 0
erlen = 0
if len(string) > 0:
for n in string:
if n.isspace():
error += 1
elif n in other:
error += 1
if len(string) <= 30 and error == 0:
return True
elif len(string) > 30:
erlen = -1
return erlen
else:
return str(error)
else:
return False
def main():
'''Start here'''
# To-dos:
# Add some menu for the user to interact with
# Agh
# What a hassle
print('=== Welcome to Specschecker v1.9 ===')
print('This program checks for the basic local PC technical specifications\n')
# usrMenu()
start()
def start():
'''This is where the magic happens'''
getOS()
getUSR()
getPCNAME()
getINTERNAL()
getPHYSICAL()
print('== Showing details for %s ==' % (platform.node()))
print('System name: %s' % (overall['pc']))
forExportation[0]['System Name'] = overall['pc']
heads.append('System Name')
print('Manufacturer/Vendor: %s' % (overall['phys'][2]))
forExportation[0]['Vendor'] = overall['phys'][2]
heads.append('Vendor')
print("Model: %s" % (overall['phys'][1]))
forExportation[0]['Model'] = overall['phys'][1]
heads.append('Model')
print("Serial Number: %s" % (overall['phys'][0]))
forExportation[0]['SN'] = overall['phys'][0]
heads.append('SN')
print('Part Number: %s' % (overall['phys'][3]))
forExportation[0]['PN'] = overall['phys'][3]
heads.append('PN')
print('OS: %s' % (overall['OS']))
forExportation[0]['OS'] = overall['OS']
heads.append('OS')
forExportation[0]['Platform'] = overall['internal'][0]['Platform']
heads.append('Platform')
print('RAM: %iGB' % (overall['internal'][0]['RAM'][0]))
forExportation[0]['RAM'] = overall['internal'][0]['RAM'][0]
heads.append('RAM')
if type(overall['internal'][0]['RAM'][1]) == list:
for x in range(0, len(overall['internal'][0]['RAM'][1])):
head = 'Module%i' % (x+1)
print('Module%i Size: %i' % (x+1, overall['internal'][0]['RAM'][1][x]))
print('Module%i PN: %s' % (x+1, overall['internal'][0]['Phys'][2][x]))
print('Module%i SN: %s' % (x+1, overall['internal'][0]['Phys'][3][x]))
forExportation[0]['Module%i' % (x+1)] = overall['internal'][0]['RAM'][1][x]
forExportation[0]['Module%i' % (x+1)] = overall['internal'][0]['Phys'][2][x]
forExportation[0]['Module%i' % (x+1)] = overall['internal'][0]['Phys'][3][x]
heads.append(head)
heads.append('Module%i_Size' % (x+1))
heads.append('Module%i_PN' % (x+1))
heads.append('Module%i_SN' % (x+1))
else:
print('Module PN: %s' % (overall['internal'][0]['Phys'][2][0]))
print('Module SN: %s' % (overall['internal'][0]['Phys'][3][0]))
forExportation[0]['Module_PN'] = overall['internal'][0]['Phys'][2][0]
forExportation[0]['Module_SN'] = overall['internal'][0]['Phys'][3][0]
heads.append('Module_PN')
heads.append('Module_SN')
if len(overall['internal'][0]['Storage'][0]) > 1:
for x in range(0, len(overall['internal'][0]['Storage'][0])):
head = 'Disk%i' % (x+1)
forExportation[0]['Disk%i' % (x+1)] = 0
heads.append(head)
if overall['internal'][0]['Storage'][1][x] != 'USB':
print('Disk %i: %.2fGB / Status: %s' % (x+1, overall['internal'][0]['Storage'][0][x], overall['internal'][0]['HDDStat'][x]))
print('HDD Model: %s' % (overall['internal'][0]['Phys'][0][x]))
print('HDD SN: %s' % (overall['internal'][0]['Phys'][1][x]))
forExportation[0]['Disk%i' % (x+1)] = overall['internal'][0]['Storage'][0][x]
forExportation[0]['HDDStat'] = overall['internal'][0]['HDDStat'][x]
forExportation[0]['HDD_Model'] = overall['internal'][0]['Phys'][0][x]
forExportation[0]['HDD_SN'] = overall['internal'][0]['Phys'][1][x]
heads.append('HDDStat')
heads.append('HDD_Model')
heads.append('HDD_SN')
else:
print('Disk %i: %.2fGB (USB)' % (x+1, overall['internal'][0]['Storage'][0][x]))
forExportation[0]['Disk%i' % (x+1)] = overall['internal'][0]['Storage'][0][x]
else:
print('Disk: %.2fGB / Status: %s' % (overall['internal'][0]['Storage'][0][0], overall['internal'][0]['HDDStat'][0]))
print('HDD Model: %s' % (overall['internal'][0]['Phys'][0][0]))
print('HDD SN: %s' % (overall['internal'][0]['Phys'][1][0]))
forExportation[0]['Disk'] = max(overall['internal'][0]['Storage'][0])
forExportation[0]['HDDStat'] = overall['internal'][0]['HDDStat'][0]
forExportation[0]['HDD_Model'] = overall['internal'][0]['Phys'][0][0]
forExportation[0]['HDD_SN'] = overall['internal'][0]['Phys'][1][0]
heads.append('HDDStat')
heads.append('Disk')
heads.append('HDD_Model')
heads.append('HDD_SN')
print('Current user: %s\n' % (overall['usr']))
forExportation[0]['User'] = overall['usr']
heads.append('User')
toFile()
def getOS():
# It works with Windows 8, 8.1, 10 for now, add other operative systems
sysm = sys.platform
pltform = ''
if sysm == 'win32':
# I don't really know if there are other platforms aside i386 and x86_64 / AMD64
# Probably need to dig into that
strComputer = "."
objWMIService = win32com.client.Dispatch("WbemScripting.SWbemLocator")
objSWbemServices = objWMIService.ConnectServer(strComputer,"root\cimv2")
colItems = objSWbemServices.ExecQuery("SELECT * FROM Win32_OperatingSystem")
for objItem in colItems:
if objItem.Caption != None:
overall['OS'] = objItem.Caption
#Machine platform overall[internal][0]
if platform.machine() == 'i386':
pltform = 'x86'
overall['internal'][0]['Platform'] = pltform
else:
pltform = 'x64'
overall['internal'][0]['Platform'] = pltform
def getUSR():
usr = os.environ['USERNAME']
overall['usr'] = usr
def getPCNAME():
pc = platform.node()
overall['pc'] = pc
def getINTERNAL():
# I don't know how to do this, halp
# Code taken form Scriptomatic V2, I'M SORRY
strComputer = "."
objWMIService = win32com.client.Dispatch("WbemScripting.SWbemLocator")
objSWbemServices = objWMIService.ConnectServer(strComputer,"root\cimv2")
colItems = objSWbemServices.ExecQuery("SELECT * FROM Win32_DiskDrive")
for objItem in colItems:
# Disk size [1]
if objItem.Size != None:
overall['internal'][0]['Storage'][0].append(int(objItem.Size) / (1024 ** 3))
if objItem.InterfaceType != None:
overall['internal'][0]['Storage'][1].append(objItem.InterfaceType)
if objItem.Status != None:
overall['internal'][0]['HDDStat'].append(objItem.Status)
if objItem.Model != None:
overall['internal'][0]['Phys'][0].append(objItem.Model)
if objItem.SerialNumber != None:
overall['internal'][0]['Phys'][1].append(objItem.SerialNumber)
# RAM capacity [3]
colItems1 = objSWbemServices.ExecQuery("SELECT * FROM Win32_ComputerSystem")
for objItem in colItems1:
if objItem.TotalPhysicalMemory != None:
overall['internal'][0]['RAM'][0] = round(int(objItem.TotalPhysicalMemory) / (1024 ** 3))
colItems2 = objSWbemServices.ExecQuery("SELECT * FROM Win32_PhysicalMemory")
for objItem in colItems2:
if objItem.Capacity != None:
overall['internal'][0]['RAM'][1] = round(int(objItem.Capacity) / (1024 ** 3))
if objItem.PartNumber != None:
overall['internal'][0]['Phys'][2].append(objItem.PartNumber)
if objItem.SerialNumber != None:
overall['internal'][0]['Phys'][3].append(objItem.SerialNumber)
def getPHYSICAL():
# Code taken from Scriptomatic V2
ver = ''
strComputer = '.'
objWMIService = win32com.client.Dispatch('WbemScripting.SWbemLocator')
objSWbemServices = objWMIService.ConnectServer(strComputer,'root\cimv2')
colItems0 = objSWbemServices.ExecQuery('SELECT * FROM Win32_ComputerSystemProduct')
colItems1 = objSWbemServices.ExecQuery("SELECT * FROM Win32_ComputerSystem")
colItems2 = objSWbemServices.ExecQuery("SELECT * FROM Win32_OperatingSystem")
for objItem in colItems0:
# Serial Number [0]
if objItem.IdentifyingNumber != None:
overall['phys'].append(objItem.IdentifyingNumber)
# Model [1] / Doesn't get *real* model, FIX!
if objItem.Name != None and objItem.Vendor != 'LENOVO':
overall['phys'].append(objItem.Name)
else:
overall['phys'].append(objItem.Version + ' Machine Type ' + objItem.Name)
# Vendor/Manufacturer[2]
if objItem.Vendor != None:
overall['phys'].append(objItem.Vendor)
# UUID, might be useful someday, maybe?
#if objItem.UUID != None:
# print ("UUID:" + str(objItem.UUID))
for objItem in colItems2:
if objItem.Version != None:
ver = objItem.Version[0:2]
if ver == '10':
for objItem in colItems1:
# Part Number [3]
if objItem.SystemSKUNumber != None:
overall['phys'].append(objItem.SystemSKUNumber)
else:
overall['phys'].append('N/A')
def nameFile():
global name
x = ''
choice = input('Do you wish to name your file? (Y/n) ')
if choice.lower() == 'y':
x = input('Input a name: ')
y = isvalidname(x)
if y == True:
name = x
elif y == -1:
print('The name you inputted is too long, please make it shorter than 31 characters')
nameFile()
elif y == False:
print('There was no input, try again')
nameFile()
else:
print('There were %s invalid characters in your input, remember to only use alphanumerical values, dashes and underscores. Try again.' % (y))
nameFile()
elif choice.lower() == 'n':
name = overall['pc']
else:
print('You didn\'t select a choice. Try again.')
nameFile()
def toFile():
'''Prompt the user to indicate whether to save collected data to a file'''
# I don't know what I'm doing (http://i3.kym-cdn.com/photos/images/original/000/234/765/b7e.jpg)
ask = input('Do you want to save this information to a file? (Y/n) ')
if ask.lower() == '' or ask.lower() == 'y':
print('\nSelect a format:')
print('1) CSV')
print('2) Plain Text')
again = input('> ')
if again == '1':
nameFile()
createCSV(name)
kill()
elif again == '2':
nameFile()
createTEXT(name)
kill()
# Add more file formats
else:
print('Sorry, try again')
toFile()
elif ask.lower() == 'n':
kill()
else:
print('Sorry, try again')
toFile()
def cleanup():
#Sigh, this is stupid
while len(forExportation[0]) != 0:
for x in heads:
if x in forExportation[0]:
forExportation[0].pop(x)
overall['internal'][0]['Storage'][0].clear()
overall['internal'][0]['Storage'][1].clear()
overall['internal'][0]['HDDStat'].clear()
overall['internal'][0]['Phys'][0].clear()
overall['internal'][0]['Phys'][1].clear()
overall['internal'][0]['Phys'][2].clear()
overall['internal'][0]['Phys'][3].clear()
overall['phys'].clear()
heads.clear()
def kill():
'''Terminates de program'''
# Is this even necessary?
global heads
ask = input('Exit the program? (Y/n) ')
if ask.lower() == '' or ask.lower() == 'y':
print('Closing...')
return 0
elif ask.lower() == 'n':
print('\n')
cleanup()
start()
else:
kill()
def createCSV(filename):
'''Creates a csv file with the collected data'''
# Here goes nothing
# EDIT: Success!!!
with open('%s.csv' % (filename), 'w', newline = '') as specsfile:
spec = csv.DictWriter(specsfile, delimiter = ',', fieldnames = heads)
spec.writeheader()
for row in forExportation:
spec.writerow(row)
print('File created and saved as "%s.csv"' % filename)
def createTEXT(filename):
'''Creates a plain text file with the collected data'''
# Here goes nothing
# EDIT: IT WORKS!! YAY!
with open('%s.txt' % (filename), 'w') as specstxt:
specstxt.write('== Showing details for %s ==\n' % (platform.node()))
specstxt.write('System name: %s\n' % (overall['pc']))
specstxt.write('Vendor: %s\n' % (overall['phys'][2]))
specstxt.write('Model: %s\n' % (overall['phys'][1]))
specstxt.write('Serial Number: %s\n' % (overall['phys'][0]))
specstxt.write('Part Number: %s\n' % (overall['phys'][3]))
specstxt.write('OS: %s\n' % (overall['OS']))
specstxt.write('RAM: %iGB\n' % (overall['internal'][0]['RAM'][0]))
if type(overall['internal'][0]['RAM'][1]) == list:
for x in range(0, len(overall['internal'][0]['RAM'][1])):
index = x + 1
specstxt.write('Module%i Size: %iGB\n' % (index, overall['internal'][0]['RAM'][1][x]))
specstxt.write('Module%i PN: %s\n' % (index, overall['internal'][0]['Phys'][2][x]))
specstxt.write('Module%i SN: %s\n' % (index, overall['internal'][0]['Phys'][3][x]))
else:
specstxt.write('Module PN: %s\n' % (overall['internal'][0]['Phys'][2][0]))
specstxt.write('Module SN: %s\n' % (overall['internal'][0]['Phys'][3][0]))
if len(overall['internal'][0]['Storage'][0]) > 1:
for x in range(0, len(overall['internal'][0]['Storage'][0])):
if overall['internal'][0]['Storage'][1][x] != 'USB':
specstxt.write('Disk %i: %.2fGB / Status: %s\n' % (x+1, overall['internal'][0]['Storage'][0][x], overall['internal'][0]['HDDStat'][x]))
specstxt.write('HDD Model: %s' % (overall['internal'][0]['Phys'][0][x]))
specstxt.write('HDD SN: %s' % (overall['internal'][0]['Phys'][0][x]))
else:
specstxt.write('Disk %i: %.2fGB (USB)\n' % (x+1, overall['internal'][0]['Storage'][0][x]))
else:
specstxt.write('Disk: %.2fGB / Status: %s\n' % (overall['internal'][0]['Storage'][0][0], overall['internal'][0]['HDDStat'][0]))
specstxt.write('HDD Model: %s\n' % (overall['internal'][0]['Phys'][0][0]))
specstxt.write('HDD SN: %s\n' % (overall['internal'][0]['Phys'][0][0]))
specstxt.write('Current user: %s\n' % (overall['usr']))
print('File created and saved as "%s.txt"' % (filename))
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment