refactor the memory functions

This commit is contained in:
MeaTLoTioN 2022-08-17 20:06:05 +01:00
parent 30ee0d4626
commit 6139ae1432

View File

@ -5,7 +5,6 @@ import os, subprocess
now = datetime.now() now = datetime.now()
TEXT = str(getcfg()['text']) TEXT = str(getcfg()['text'])
DATE = now.strftime("%a, %b %e %Y, %H:%M") DATE = now.strftime("%a, %b %e %Y, %H:%M")
CFG = str(getcfg()) CFG = str(getcfg())
USER = str(getuser()) USER = str(getuser())
HANDLE = str(getuser()['handle']) HANDLE = str(getuser()['handle'])
@ -33,17 +32,11 @@ def dispTotals():
gotoxy(64,12); write("|08|$l14.|15|TC") gotoxy(64,12); write("|08|$l14.|15|TC")
def dispSysInfo(): def dispSysInfo():
MEMFREEMB = 0 MEMTOTLKB = os.popen("free|grep Mem|awk '{print $2}'").read().strip('\n')
MEMTOTALMB = 0 MEMUSEDKB = os.popen("free|grep Mem|awk '{print $3}'").read().strip('\n')
with open('/proc/meminfo') as file: MEMTOTLMB = int(MEMTOTLKB) / 1024
for line in file: MEMUSEDMB = int(MEMUSEDKB) / 1024
if 'MemTotal' in line: gotoxy(11,13); write("|15"+str(MEMUSEDMB)+"MB|08/|15"+str(MEMTOTLMB)+"MB |03used")
MEMTOTALKB = line.split()[1]
MEMTOTALMB = int(MEMTOTALKB) / 1024
if 'MemFree' in line:
MEMFREEKB = line.split()[1]
MEMFREEMB = int(MEMFREEKB) / 1024
gotoxy(11,13); write("|15"+str(MEMFREEMB)+" MB |08/ |15"+str(MEMTOTALMB)+" MB")
NUMPROCS = os.popen('nproc').read().strip('\n') NUMPROCS = os.popen('nproc').read().strip('\n')
LOADAVG = os.popen('uptime|grep -oE "average:.*"').read().split(':')[1].strip('\n').split(',') LOADAVG = os.popen('uptime|grep -oE "average:.*"').read().split(':')[1].strip('\n').split(',')
@ -79,10 +72,13 @@ def dispQuickLog(log="mis"):
gotoxy(3,SY+OS); write("|17|15"+line.ljust(76)+"|16") gotoxy(3,SY+OS); write("|17|15"+line.ljust(76)+"|16")
OS = OS + 1 OS = OS + 1
def init():
writeln("|CL") writeln("|CL")
menucmd('GD','@0@NONE@'+TEXT+'wfc/main.ans') menucmd('GD','@0@NONE@'+TEXT+'wfc/main.ans')
dispHeader() dispHeader()
dispTotals() dispTotals()
dispSysInfo() dispSysInfo()
dispQuickLog('mis') dispQuickLog('mis')
init()
gotoxy(1,24); writeln("|PA") gotoxy(1,24); writeln("|PA")