diff --git a/reporting/diskfree-tracker b/reporting/diskfree-tracker index bdf2a96..919a086 100755 --- a/reporting/diskfree-tracker +++ b/reporting/diskfree-tracker @@ -43,6 +43,8 @@ You can tap in to an existing log with: help="Disable colored output") parser.add_argument("-n",type=int,dest="delay",default=3, 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) options=parser.parse_args() @@ -131,7 +133,7 @@ def print_stats(stats): ''' Prints logged errors, and the status line ''' #sys.stdout.write(SAVE) 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) if (stats['running']): pass @@ -161,6 +163,34 @@ def print_stats(stats): sys.stdout.write(DOWN+CLRBLN+CLRLN) #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): ''' colorizes the usage string ''' if len(string)<3: @@ -230,7 +260,8 @@ stats={'time':datetime.now(), '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: try: @@ -246,6 +277,9 @@ while 1: for line in stdout.split('\n')[1:]: stats=count_running(line,stats) + if options.once: + print_stats_once(stats) + sys.exit(0) print_stats(stats) sys.stdout.flush() time.sleep(options.delay)