diff --git a/aerofs/aerofs-transfers b/aerofs/aerofs-transfers index bc5728a..90c5ff0 100755 --- a/aerofs/aerofs-transfers +++ b/aerofs/aerofs-transfers @@ -2,6 +2,8 @@ import sys,os from datetime import datetime +from datetime import timedelta + import re,signal import subprocess @@ -24,6 +26,9 @@ CLRLN = '\033[K' CLRBLN = '\033[1K' DOWN = '\033[1B' +SORTCONVERT = lambda text: float(text) if is_number(text) else -1 +SORTKEY = lambda key: SORTCONVERT(key[2][:-1]) + def setup_options(): ''' Setup the command line options ''' from argparse import ArgumentParser @@ -34,12 +39,10 @@ Tool to clean up and colorize the output of Anduril. Example: anduril run yourscript.and | %(prog)s You can tap in to an existing log with: tail -f -n +0 log/_global | %(prog)s''',formatter_class=argparse.RawTextHelpFormatter) - parser.add_argument("--time-stamp",'-t',action="store_true",dest="timestamp",default=False, - help="Print a timestamp on each line") + parser.add_argument("--no-colors",'--nc',action="store_false",dest="colors",default=True, help="Disable colored output") - parser.add_argument("logfile",type=str,action="store",default="",nargs="?", - help="Log file to read, uses stdin automatically") + parser.add_argument("--version",action='version', version=VERSION) options=parser.parse_args() @@ -67,8 +70,7 @@ def colorize(string): string=color_match[c][0].sub(color_match[c][1],string) return string -SORTCONVERT = lambda text: float(text) if is_number(text) else -1 -SORTKEY = lambda key: SORTCONVERT(key[2][:-1]) + def count_running(string, stats): ''' Counts the running executions ''' @@ -76,6 +78,7 @@ def count_running(string, stats): spl=[i.strip() for i in string.split('|')] if len(spl)!=4: return stats + spl.append(datetime.now()) if spl[3] in stats['files']: index=stats['files'].index(spl[3]) stats['running'][index]=spl @@ -94,18 +97,24 @@ def remove_running(stats): ''' Remove Done files ''' if not stats['running']: return stats + # Remove Done/Fail older than 60sec + for e in enumerate(stats['running']): + if (datetime.now() - e[1][4] > timedelta(seconds=60)): + if e[1][2]=='Done' or e[1][2]=='Failed': + stats['running'].pop(e[0]) + stats['files'].pop(e[0]) + # Remove Done/Fail if there are too many: if len(stats['running'])>(stats['size'][0]-3): for e in enumerate(stats['running']): if e[1][2]=='Done': stats['running'].pop(e[0]) stats['files'].pop(e[0]) - #remove just one failed - if len(stats['running'])>(stats['size'][0]-3): - for e in enumerate(stats['running']): + return stats if e[1][2]=='Failed': stats['running'].pop(e[0]) stats['files'].pop(e[0]) - return stats + return stats + return stats def is_number(s): @@ -114,7 +123,7 @@ def is_number(s): out=float(s) return True except: - return False + return False def str_short(s,stats): ''' shorten text to fit screen ''' @@ -125,11 +134,10 @@ def str_short(s,stats): sNew=spl[0]+'/...'+'/'.join(spl[1:])[-(maxL-len(spl[0])-5):] return sNew - def print_stats(stats): ''' Prints logged errors, and the status line ''' - sys.stdout.write(SAVE) + #sys.stdout.write(SAVE) for e in range(2): sys.stdout.write(pos(e+1,0)+CLRLN) @@ -146,10 +154,10 @@ def print_stats(stats): str_short(ex[1][3],stats)])+ CLRLN) for i in range(stats['size'][0]-3-len(stats['running'])): - sys.stdout.write(pos(e+4+ex[0]+i,0)+"( )"+CLRLN) + sys.stdout.write(pos(e+4+ex[0]+i,0)+" "+CLRLN) sys.stdout.write(DOWN+CLRBLN+CLRLN) - sys.stdout.write(LOAD) + #sys.stdout.write(LOAD) def human_time(): t=datetime.now().strftime("%I:%M:%S %p")