import os
import time
-log_dirs = [sys.argv[1]]
+log_dirs = sys.argv[1:]
refresh_interval = 2
class AppInfo:
- def __init__(self, name, user, machine, status, progress):
- self.name = name
- self.user = user
- self.machine = machine
- self.status = status
- self.progress = progress
+ def __init__(self, name, user, machine, status, progress):
+ self.name = name
+ self.user = user
+ self.machine = machine
+ self.status = status
+ self.progress = progress
def get_app_info(filename):
- f = file(filename,"r")
- try:
- f.seek(-2000, 2)
- except IOError:
- f.seek(0)
-
- lines = f.read().split("\n")
- for l in lines:
- if l[:2]=='!!' and l[-2:]=='!!':
- last_complete_line = l
- l = last_complete_line[2:-2].split("&")
- return AppInfo(l[0],l[1],l[2],l[3],int(float(l[4])))
+ f = file(filename,"r")
+ try:
+ f.seek(-2000, 2)
+ except IOError:
+ f.seek(0)
+
+ lines = f.read().split("\n")
+ for l in lines:
+ if l[:2]=='!!' and l[-2:]=='!!':
+ last_complete_line = l
+ l = last_complete_line[2:-2].split("&")
+ return AppInfo(l[0],l[1],l[2],l[3],int(float(l[4])))
def get_apps_info():
- apps = []
- for dir in log_dirs:
- filenames = os.listdir(dir)
- for f in filenames:
- if f[:6] == "melon-":
- apps.append(get_app_info(dir+os.sep+f))
- return apps
+ apps = []
+ for dir in log_dirs:
+ filenames = os.listdir(dir)
+ for f in filenames:
+ if f[:6] == "melon-":
+ apps.append(get_app_info(dir+os.sep+f))
+ return apps
def main(stdscr):
curses.use_default_colors()
rows, cols = stdscr.getmaxyx()
if cols < 80:
- print "Terminal is too narrow"
- return
+ print "Terminal is too narrow"
+ return
numboxes = (rows-1)/3
cur_pos = 0
exit = False
while not exit:
- if time.time() - last_refresh > refresh_interval:
- last_refresh = time.time()
- apps = get_apps_info()
+ if time.time() - last_refresh > refresh_interval:
+ last_refresh = time.time()
+ apps = get_apps_info()
stdscr.erase()
- for i in xrange(min(numboxes, len(apps)-cur_pos)):
+ if len(apps) > 0:
+ for i in xrange(min(numboxes, len(apps)-cur_pos)):
app = apps[cur_pos + i]
stdscr.attrset(curses.color_pair(1) | curses.A_NORMAL)
stdscr.addstr(3*i+1, 2, "..."+app.name[-57:], curses.A_BOLD)
stdscr.box()
try:
- cmd = stdscr.getch()
+ cmd = stdscr.getch()
except:
- pass
+ pass
if cmd == ord('q'):
- exit = True
+ exit = True
elif cmd == curses.KEY_DOWN:
- if cur_pos < len(apps)-numboxes:
- cur_pos += 1
+ if cur_pos < len(apps)-numboxes:
+ cur_pos += 1
elif cmd == curses.KEY_UP:
- if cur_pos > 0:
- cur_pos -= 1
+ if cur_pos > 0:
+ cur_pos -= 1
elif cmd == curses.KEY_RIGHT:
- cur_x_pos += 10
+ cur_x_pos += 10
elif cmd == curses.KEY_LEFT:
- if cur_x_pos > 0:
- cur_x_pos -= 10
+ if cur_x_pos > 0:
+ cur_x_pos -= 10
stdscr.refresh()
curses.wrapper(main)