improved aerofs gui

This commit is contained in:
ville rantanen
2013-11-05 13:22:11 +02:00
parent bd811f4022
commit e83ead218f

View File

@@ -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,15 +91,40 @@ 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)<maxL:
return s
spl=s.split('/')
sNew=spl[0]+'/...'+'/'.join(spl[1:])[-(maxL-len(spl[0])-5):]
return sNew
def print_stats(stats):
@@ -102,16 +133,20 @@ def print_stats(stats):
for e in range(2):
sys.stdout.write(pos(e+1,0)+CLRLN)
sys.stdout.write(pos(e+1,0)+"="*20+" "+human_time()+CLRLN)
sys.stdout.write(pos(e+1,0)+"="*10+"AeroFS Transfers"+"="*10+" "+human_time()+CLRLN)
if (stats['running']):
sys.stdout.write(pos(e+2,0)+"Last update: "+stats['running'][0][0]+CLRLN)
else:
return
for ex in enumerate(stats['running']):
sys.stdout.write(pos(e+3+ex[0],0)+'('+str(ex[0]+1)+') '+' '.join([(ex[1][1]),colorize(ex[1][2]),ex[1][3]])+CLRLN)
for i in range(3):
sys.stdout.write(pos(e+4+ex[0],0)+CLRLN)
sys.stdout.write(pos(e+3+ex[0],0)+'('+str(ex[0]+1).rjust(2)+') '+
' '.join([ex[1][1],
colorize(ex[1][2].ljust(6)),
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(DOWN+CLRBLN+CLRLN)
sys.stdout.write(LOAD)
@@ -128,15 +163,21 @@ def readinput(lf):
except:
return "CleanerTimeout"
def termsize():
rows, columns = os.popen('stty size', 'r').read().split()
return (int(rows),int(columns))
options=setup_options()
stats={'time':datetime.now(),
'running':[],
'files':[]}
'files':[],
'size': termsize()}
sys.stdout.write(CLR+pos(0,0)+"Launching...")
proc = subprocess.Popen(['aerofs-sh','transfers'],stdout=subprocess.PIPE)
sys.stdout.write(CLR)
while 1:
try:
@@ -152,12 +193,13 @@ while 1:
print_stats(stats)
continue
stats=count_running(line,stats)
stats=remove_running(stats)
# store only maximum number of error lines
# if line empty, read next
if line.strip()=="":
continue
print_stats(stats)
stats=remove_running(stats)
except EndProgram,KeyboardInterrupt:
sys.stdout.flush()
sys.exit(0)