83 lines
2.0 KiB
Python
83 lines
2.0 KiB
Python
import sys
|
|
import subprocess
|
|
import re
|
|
|
|
|
|
def draw(perc):
|
|
print("-", end="")
|
|
for i in range(100):
|
|
print("-", end="")
|
|
|
|
print("-")
|
|
|
|
print("|", end="")
|
|
for i in range(100):
|
|
if i < perc:
|
|
print("*", end="")
|
|
else:
|
|
print(" ", end="")
|
|
|
|
print("|")
|
|
|
|
print("-", end="")
|
|
for i in range(100):
|
|
print("-", end="")
|
|
|
|
print("-")
|
|
|
|
|
|
def get_flash(f):
|
|
rom = 0
|
|
l = re.search("FLASH.*LENGTH.*", f)
|
|
if l is not None:
|
|
l = re.search("LENGTH.=.[0-9]*.K", l.group())
|
|
if l is not None:
|
|
l = re.search("[0-9].*", l.group())
|
|
if l is not None:
|
|
rom = l.group().replace("K", "")
|
|
return int(rom)
|
|
|
|
|
|
def get_ram(f):
|
|
ram = 0
|
|
l = re.search("RAM.*LENGTH.*", f)
|
|
if l is not None:
|
|
l = re.search("LENGTH.=.[0-9]*K", l.group())
|
|
if l is not None:
|
|
l = re.search("[0-9].*", l.group())
|
|
if l is not None:
|
|
ram = l.group().replace("K", "")
|
|
l = re.search("CCMRAM.*LENGTH.*", f)
|
|
if l is not None:
|
|
l = re.search("LENGTH.=.[0-9]*.K", l.group())
|
|
if l is not None:
|
|
l = re.search("[0-9].*", l.group())
|
|
if l is not None:
|
|
ram = int(ram) + int(l.group().replace("K", ""))
|
|
return ram
|
|
|
|
|
|
def main():
|
|
argc = len(sys.argv)
|
|
if argc == 4:
|
|
var = subprocess.check_output([sys.argv[1], str(sys.argv[2])], universal_newlines=True)
|
|
f = open(sys.argv[3]).read()
|
|
mrom = get_flash(f)
|
|
mram = get_ram(f)
|
|
mrom = int(mrom) * 1024
|
|
mram = int(mram) * 1024
|
|
var = str(var).replace("\t", " ").splitlines()[1].split()
|
|
romp = 100.0 / float(mrom) * float(int(var[0]))
|
|
ramp = 100.0 / float(mram) * float(int(var[1]) + int(var[2]))
|
|
print("RAM: {:.1f}%:".format(ramp))
|
|
draw(ramp)
|
|
print("FLASH: {:.1f}%".format(romp))
|
|
draw(romp)
|
|
else:
|
|
print("Invalid number of arguments!")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
# execute only if run as a script
|
|
main()
|