diff --git a/aerofs/aerofs-transfers b/aerofs/aerofs-transfers index b0bb2c4..bc5728a 100755 --- a/aerofs/aerofs-transfers +++ b/aerofs/aerofs-transfers @@ -55,6 +55,7 @@ def pos(y,x): color_match={#'line_ends':(re.compile('$'),c.END), 'err':(re.compile('(Failed)'),c([R,S])+'\\1'+c([E])), 'done':(re.compile('(Done)'),c([G,S])+'\\1'+c([E])), + 'percent':(re.compile('([0-9]+%)'),c([Y,S])+'\\1'+c([E])), } @@ -66,17 +67,22 @@ 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 ''' spl=[i.strip() for i in string.split('|')] + if len(spl)!=4: + return stats if spl[3] in stats['files']: index=stats['files'].index(spl[3]) stats['running'][index]=spl else: stats['running'].append(spl) - stats['running'].sort(key=lambda x: x[3]) + stats['running'].sort(key=SORTKEY, reverse=True) + stats['files']=[i[3] for i in stats['running']] return stats @@ -85,16 +91,41 @@ class EndProgram( Exception ): pass def remove_running(stats): - ''' Remove list item matching to string ''' + ''' Remove Done files ''' if not stats['running']: return stats - if len(stats['running'])>10: + 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']): + if e[1][2]=='Failed': + stats['running'].pop(e[0]) + stats['files'].pop(e[0]) + return stats return stats +def is_number(s): + ''' Check if string is float ''' + try: + out=float(s) + return True + except: + return False + +def str_short(s,stats): + ''' shorten text to fit screen ''' + maxL=stats['size'][1] - 16 + if len(s)