improved aerofs gui
This commit is contained in:
@@ -55,6 +55,7 @@ def pos(y,x):
|
|||||||
color_match={#'line_ends':(re.compile('$'),c.END),
|
color_match={#'line_ends':(re.compile('$'),c.END),
|
||||||
'err':(re.compile('(Failed)'),c([R,S])+'\\1'+c([E])),
|
'err':(re.compile('(Failed)'),c([R,S])+'\\1'+c([E])),
|
||||||
'done':(re.compile('(Done)'),c([G,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)
|
string=color_match[c][0].sub(color_match[c][1],string)
|
||||||
return 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):
|
def count_running(string, stats):
|
||||||
''' Counts the running executions '''
|
''' Counts the running executions '''
|
||||||
|
|
||||||
spl=[i.strip() for i in string.split('|')]
|
spl=[i.strip() for i in string.split('|')]
|
||||||
|
if len(spl)!=4:
|
||||||
|
return stats
|
||||||
if spl[3] in stats['files']:
|
if spl[3] in stats['files']:
|
||||||
index=stats['files'].index(spl[3])
|
index=stats['files'].index(spl[3])
|
||||||
stats['running'][index]=spl
|
stats['running'][index]=spl
|
||||||
else:
|
else:
|
||||||
stats['running'].append(spl)
|
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']]
|
stats['files']=[i[3] for i in stats['running']]
|
||||||
return stats
|
return stats
|
||||||
|
|
||||||
@@ -85,16 +91,41 @@ class EndProgram( Exception ):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def remove_running(stats):
|
def remove_running(stats):
|
||||||
''' Remove list item matching to string '''
|
''' Remove Done files '''
|
||||||
if not stats['running']:
|
if not stats['running']:
|
||||||
return stats
|
return stats
|
||||||
if len(stats['running'])>10:
|
if len(stats['running'])>(stats['size'][0]-3):
|
||||||
for e in enumerate(stats['running']):
|
for e in enumerate(stats['running']):
|
||||||
if e[1][2]=='Done':
|
if e[1][2]=='Done':
|
||||||
stats['running'].pop(e[0])
|
stats['running'].pop(e[0])
|
||||||
stats['files'].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
|
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):
|
def print_stats(stats):
|
||||||
''' Prints logged errors, and the status line '''
|
''' Prints logged errors, and the status line '''
|
||||||
@@ -102,16 +133,20 @@ def print_stats(stats):
|
|||||||
|
|
||||||
for e in range(2):
|
for e in range(2):
|
||||||
sys.stdout.write(pos(e+1,0)+CLRLN)
|
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']):
|
if (stats['running']):
|
||||||
sys.stdout.write(pos(e+2,0)+"Last update: "+stats['running'][0][0]+CLRLN)
|
sys.stdout.write(pos(e+2,0)+"Last update: "+stats['running'][0][0]+CLRLN)
|
||||||
else:
|
else:
|
||||||
return
|
return
|
||||||
|
|
||||||
for ex in enumerate(stats['running']):
|
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)
|
sys.stdout.write(pos(e+3+ex[0],0)+'('+str(ex[0]+1).rjust(2)+') '+
|
||||||
for i in range(3):
|
' '.join([ex[1][1],
|
||||||
sys.stdout.write(pos(e+4+ex[0],0)+CLRLN)
|
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(DOWN+CLRBLN+CLRLN)
|
||||||
sys.stdout.write(LOAD)
|
sys.stdout.write(LOAD)
|
||||||
@@ -128,15 +163,21 @@ def readinput(lf):
|
|||||||
except:
|
except:
|
||||||
return "CleanerTimeout"
|
return "CleanerTimeout"
|
||||||
|
|
||||||
|
def termsize():
|
||||||
|
rows, columns = os.popen('stty size', 'r').read().split()
|
||||||
|
return (int(rows),int(columns))
|
||||||
|
|
||||||
|
|
||||||
options=setup_options()
|
options=setup_options()
|
||||||
|
|
||||||
stats={'time':datetime.now(),
|
stats={'time':datetime.now(),
|
||||||
'running':[],
|
'running':[],
|
||||||
'files':[]}
|
'files':[],
|
||||||
|
'size': termsize()}
|
||||||
|
|
||||||
|
sys.stdout.write(CLR+pos(0,0)+"Launching...")
|
||||||
proc = subprocess.Popen(['aerofs-sh','transfers'],stdout=subprocess.PIPE)
|
proc = subprocess.Popen(['aerofs-sh','transfers'],stdout=subprocess.PIPE)
|
||||||
|
|
||||||
sys.stdout.write(CLR)
|
|
||||||
while 1:
|
while 1:
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -152,12 +193,13 @@ while 1:
|
|||||||
print_stats(stats)
|
print_stats(stats)
|
||||||
continue
|
continue
|
||||||
stats=count_running(line,stats)
|
stats=count_running(line,stats)
|
||||||
|
stats=remove_running(stats)
|
||||||
# store only maximum number of error lines
|
# store only maximum number of error lines
|
||||||
# if line empty, read next
|
# if line empty, read next
|
||||||
if line.strip()=="":
|
if line.strip()=="":
|
||||||
continue
|
continue
|
||||||
print_stats(stats)
|
print_stats(stats)
|
||||||
stats=remove_running(stats)
|
|
||||||
except EndProgram,KeyboardInterrupt:
|
except EndProgram,KeyboardInterrupt:
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|||||||
Reference in New Issue
Block a user