fspecs/fspecs.py

228 lines
5.1 KiB
Python

# init
print("LOADING...",end="\r")
import sys
oldexcepthook = sys.excepthook
def newexcepthook(type,value,traceback):
oldexcepthook(type,value,traceback)
input("Press ENTER to quit.")
sys.excepthook = newexcepthook
import os
import subprocess
import colorama
import shutil
import configparser
p = os.path.join
s = False
if getattr(sys, 'frozen', False) and hasattr(sys, '_MEIPASS'):
s = os.path.realpath(sys.executable)
else:
s = os.path.realpath(__file__)
sp = os.path.dirname(s)
# script
colorama.init()
x,y = shutil.get_terminal_size((80, 20))
x = x - 1
pathConfig = p(sp,os.path.splitext(os.path.basename(s))[0] + ".ini")
pathAsciiLuma = p(sp,os.path.splitext(os.path.basename(s))[0] + ".ascii-luma.txt")
pathAsciiChroma = p(sp,os.path.splitext(os.path.basename(s))[0] + ".ascii-chroma.txt")
config = configparser.ConfigParser()
config["default"] = {
"msg": "???"
}
config.read(pathConfig,encoding="utf-8")
asciiLuma = open(pathAsciiLuma,"r",encoding="utf-8").read()
asciiChroma = open(pathAsciiChroma,"r",encoding="utf-8").read()
colors = {
"a":colorama.Fore.BLACK,
"b":colorama.Fore.RED,
"c":colorama.Fore.GREEN,
"d":colorama.Fore.YELLOW,
"e":colorama.Fore.BLUE,
"f":colorama.Fore.MAGENTA,
"g":colorama.Fore.CYAN,
"h":colorama.Fore.WHITE,
"i":colorama.Fore.RESET
}
def getInfo(part,defn,index = 0):
try:
part = part.split(" ")
out = subprocess.check_output(["wmic"] +part+ ["get",defn],stderr=subprocess.DEVNULL).decode("utf-8").split("\n")[1 + index]
except:
return False
out = out.replace("\r","").replace(" "," ")
while " " in out:
out = out.replace(" "," ")
try:
while out[0] == " " or out[0] == " ":
out = out[1:]
while out[-1] == " " or out[-1] == " ":
out = out[:-1]
except:
return False
return out
def qi(part,defn,index = 0):
info = ""
try:
info = getInfo(part,defn,index)
except:
info = "???"
if info == False: info = "???"
return info
def getSpecs():
info = []
#OPERATING SYSTEM
info.append("OPS")
try:
info.append(subprocess.check_output(["ver"],shell=True).decode("utf-8").replace("\n","").replace("\r",""))
except:
info.append("???")
#HOST
info.append("HST")
try:
info.append(os.environ["USERNAME"] +"@"+ os.environ["USERDOMAIN"])
except:
info.append("???")
info.append("");info.append("")
#BOARD
info.append("BRD")
info.append(qi("baseboard","manufacturer") + " " + qi("baseboard","product"))
#CPU
info.append("CPU")
info.append(qi("cpu","name"))
#MEMORY
info.append("MEM")
memCap = 0
index = 0
while True:
minfo = qi("memorychip","capacity",index)
if minfo == "???": break
memCap = memCap + (int(minfo) / 1024 / 1024)
index = index + 1
if memCap == 0: memCap = "???"
memInfo = str(memCap) + " MB @ " +qi("memorychip","speed")+ "MHz"
info.append(memInfo)
#GPU
info.append("GPU")
info.append(qi("path win32_VideoController","name"))
return info
information = getSpecs()
information.append("");information.append("")
information.append("MSG")
information.append(config["default"]["msg"])
asciiLuma = asciiLuma.split("\n")
asciiChroma = asciiChroma.split("\n")
asciiMaxLength = 0
for line in asciiLuma:
line = line.replace("\n","")
length = len(line)
if (length > asciiMaxLength): asciiMaxLength = length
asciiEmpty = ""
while len(asciiEmpty) < asciiMaxLength:
asciiEmpty = asciiEmpty + " "
index = 0
asciiIndex = 0
length = len(information)
asciiLength = len(asciiLuma)
asciiChromaLength = len(asciiChroma)
colorIndex = 0
specColors = ["r","g","c","y"]
uncoloredOut = []
while index < length:
curLine = ""
infon = information[index]
infod = information[index + 1]
if asciiIndex < len(asciiLuma):
curLine = asciiLuma[asciiIndex]
else:
curLine = asciiEmpty
while len(curLine) < asciiMaxLength:
curLine = curLine + " "
if infon != "":
if infon != "RAW":
curLine = curLine + infon + ": " + infod
else:
curLine = curLine + infod
while len(curLine) > x:
curLine = curLine[:-1]
uncoloredOut.append(curLine)
index = index + 2
asciiIndex = asciiIndex + 1
while asciiIndex < asciiLength:
curLine = asciiLuma[asciiIndex]
while len(curLine) > x:
curLine = curLine[:-1]
uncoloredOut.append(curLine)
asciiIndex = asciiIndex + 1
outLength = len(uncoloredOut)
coloredOut = []
asciiIndex = 0
lastColor = "i"
while asciiIndex < outLength:
line = uncoloredOut[asciiIndex]
chromaLine = asciiChroma[asciiIndex]
newLine = ""
lineIndex = 0
lineLength = len(line)
while lineIndex < lineLength:
curColor = "i"
symbol = line[lineIndex]
if lineIndex < len(chromaLine):
curColor = chromaLine[lineIndex]
else:
curColor = "i"
if not curColor.lower() in colors:
curColor = "i"
if curColor != lastColor:
if curColor != "i":
colorDef = colorama.Style.RESET_ALL + colors[curColor.lower()]
if curColor.lower() != curColor: colorDef = colorDef + colorama.Style.BRIGHT
symbol = colorDef + symbol
else:
symbol = colorama.Style.RESET_ALL + symbol
lastColor = curColor
newLine = newLine + symbol
lineIndex = lineIndex + 1
coloredOut.append(newLine)
asciiIndex = asciiIndex + 1
coloredOut[-1] = coloredOut[-1] + colorama.Style.RESET_ALL
for line in coloredOut:
print(line)