From bc6ecf12c5b3c1383b3a5b9ef9c7c227c7c37f0b Mon Sep 17 00:00:00 2001 From: Jorge Gorbe Moya Date: Fri, 27 Jun 2008 16:59:58 +0200 Subject: [PATCH] CR/LF to LF conversion --- melon-view.py | 234 +++++++++++++++++++++++++------------------------- 1 file changed, 117 insertions(+), 117 deletions(-) diff --git a/melon-view.py b/melon-view.py index fb429ae..16a0583 100755 --- a/melon-view.py +++ b/melon-view.py @@ -1,117 +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() - - - +#!/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 < 80: + 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-68; +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, 65, (app.user+"@"+app.machine)[:barsize], attribs) + stdscr.addstr(3*i+2, 2, app.status[cur_x_pos:], attribs) + + stdscr.hline(3*i+2, 65, "-", barsize) + stdscr.hline(3*i+2, 65, "+", int((app.progress/100.0)*barsize)) + stdscr.addstr(3*i+2, 60, str(app.progress)+"%", attribs) + 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