one shot df colorize

This commit is contained in:
ville rantanen
2014-03-26 10:19:39 +02:00
parent 01fc9ecd2e
commit e16bb8659f

View File

@@ -43,6 +43,8 @@ You can tap in to an existing log with:
help="Disable colored output") help="Disable colored output")
parser.add_argument("-n",type=int,dest="delay",default=3, parser.add_argument("-n",type=int,dest="delay",default=3,
help="Refresh delay") help="Refresh delay")
parser.add_argument("-1",action="store_true",dest="once",default=False,
help="Run once and exit")
parser.add_argument("--version",action='version', version=VERSION) parser.add_argument("--version",action='version', version=VERSION)
options=parser.parse_args() options=parser.parse_args()
@@ -131,7 +133,7 @@ def print_stats(stats):
''' Prints logged errors, and the status line ''' ''' Prints logged errors, and the status line '''
#sys.stdout.write(SAVE) #sys.stdout.write(SAVE)
e=0 e=0
sys.stdout.write(pos(e+1,0)+c((S,C))+"= disk free = "+c((E))+ sys.stdout.write(pos(e+1,0)+c((S,C))+"= DISK FREE = "+c((E))+
human_time(stats['time'])+'=>'+c((S,G))+human_time()+c((E))+CLRLN) human_time(stats['time'])+'=>'+c((S,G))+human_time()+c((E))+CLRLN)
if (stats['running']): if (stats['running']):
pass pass
@@ -161,6 +163,34 @@ def print_stats(stats):
sys.stdout.write(DOWN+CLRBLN+CLRLN) sys.stdout.write(DOWN+CLRBLN+CLRLN)
#sys.stdout.write(LOAD) #sys.stdout.write(LOAD)
def print_stats_once(stats):
''' Prints logged errors, once '''
e=0
sys.stdout.write(c((S,C))+"= DISK FREE = "+c((E,))+CLRLN+'\n')
if (stats['running']):
pass
else:
return
sys.stdout.write(" Total Used Use% Free"+CLRLN+'\n')
for ex in enumerate(stats['running']):
sys.stdout.write('('+str(ex[0]+1).rjust(2)+') '+
' '.join([
human_size(ex[1][6]).rjust(8),
human_size(ex[1][6]-ex[1][0]).rjust(10),
colorize_usage(ex[1][4]),
human_size(ex[1][0]).rjust(10),
ex[1][2],
"("+ex[1][5]+")"])+
CLRLN+'\n')
sys.stdout.write('Tot: '+
' '.join([
human_size(stats['totals'][1]).rjust(8),
human_size(stats['totals'][1]-stats['totals'][0]).rjust(10), ' ',
human_size(stats['totals'][0]).rjust(10)
])+
CLRLN+'\n')
def colorize_usage(string): def colorize_usage(string):
''' colorizes the usage string ''' ''' colorizes the usage string '''
if len(string)<3: if len(string)<3:
@@ -230,7 +260,8 @@ stats={'time':datetime.now(),
'delay': options.delay 'delay': options.delay
} }
sys.stdout.write(CLR+pos(0,0)+"Launching...") if not options.once:
sys.stdout.write(CLR+pos(0,0)+"Launching...")
while 1: while 1:
try: try:
@@ -246,6 +277,9 @@ while 1:
for line in stdout.split('\n')[1:]: for line in stdout.split('\n')[1:]:
stats=count_running(line,stats) stats=count_running(line,stats)
if options.once:
print_stats_once(stats)
sys.exit(0)
print_stats(stats) print_stats(stats)
sys.stdout.flush() sys.stdout.flush()
time.sleep(options.delay) time.sleep(options.delay)