From c787eb4118dada5759b66a87c10744522647bf35 Mon Sep 17 00:00:00 2001 From: "U-Blackbird\\slack" Date: Fri, 27 Jun 2008 03:12:52 +0200 Subject: [PATCH] Initial commit --- melon-view.py | 117 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100755 melon-view.py diff --git a/melon-view.py b/melon-view.py new file mode 100755 index 0000000..fb429ae --- /dev/null +++ b/melon-view.py @@ -0,0 +1,117 @@ +#!/usr/bin/python + +import sys +import curses +import os +import time + +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 get_app_info(filename): + f = file(filename,"r") + try: + f.seek(-200, 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(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 + + + +# curses init +stdscr = curses.initscr() +rows, cols = stdscr.getmaxyx() +if cols < 70: + print "Terminal is too narrow" + # curses cleanup + stdscr.keypad(0) + curses.nocbreak() + curses.echo() + curses.endwin() + sys.exit(1) + +curses.noecho() +#curses.cbreak() +curses.halfdelay(100) +stdscr.keypad(1) +# app goes here + +numboxes = (rows-1)/3 +cur_pos = 0 +cur_x_pos = 0 +barsize = cols-63; +last_refresh = 0 + + +exit = False +while not exit: + 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)): + app = apps[cur_pos + i] + attribs = curses.A_NORMAL + stdscr.addstr(3*i+1, 2, app.name, attribs) + stdscr.addstr(3*i+1, 60, app.user+"@"+app.machine, attribs) + stdscr.addstr(3*i+2, 2, app.status[cur_x_pos:], attribs) + + stdscr.hline(3*i+2, 60, curses.ACS_BOARD, barsize) + stdscr.hline(3*i+2, 60, curses.ACS_BLOCK, int((app.progress/100.0)*barsize)) + + stdscr.hline(3*(i+1),1,curses.ACS_HLINE, cols-2) + + stdscr.box() + try: + cmd = stdscr.getch() + except: + pass + if cmd == ord('q'): + exit = True + elif cmd == curses.KEY_DOWN: + if cur_pos < len(apps)-numboxes: + cur_pos += 1 + elif cmd == curses.KEY_UP: + if cur_pos > 0: + cur_pos -= 1 + elif cmd == curses.KEY_RIGHT: + cur_x_pos += 10 + elif cmd == curses.KEY_LEFT: + if cur_x_pos > 0: + cur_x_pos -= 10 + stdscr.refresh() + +# curses cleanup +stdscr.keypad(0) +curses.nocbreak() +curses.echo() +curses.endwin() + + + -- 2.34.1