-#!/usr/bin/python\r
-\r
-import sys\r
-import curses\r
-import os\r
-import time\r
-\r
-log_dirs = [sys.argv[1]]\r
-refresh_interval = 2\r
-\r
-class AppInfo:\r
- def __init__(self, name, user, machine, status, progress):\r
- self.name = name\r
- self.user = user\r
- self.machine = machine\r
- self.status = status\r
- self.progress = progress\r
-\r
-\r
-def get_app_info(filename):\r
- f = file(filename,"r")\r
- try:\r
- f.seek(-200, 2)\r
- except IOError:\r
- f.seek(0)\r
- \r
- lines = f.read().split("\n")\r
- for l in lines:\r
- if l[:2]=='!!' and l[-2:]=='!!':\r
- last_complete_line = l\r
- l = last_complete_line[2:-2].split("&")\r
- return AppInfo(l[0],l[1],l[2],l[3],int(l[4]))\r
-\r
-\r
-def get_apps_info():\r
- apps = []\r
- for dir in log_dirs:\r
- filenames = os.listdir(dir)\r
- for f in filenames:\r
- if f[-6:] == ".melon":\r
- apps.append(get_app_info(dir+os.sep+f))\r
- return apps\r
-\r
-\r
-\r
-# curses init\r
-stdscr = curses.initscr()\r
-rows, cols = stdscr.getmaxyx()\r
-if cols < 70:\r
- print "Terminal is too narrow"\r
- # curses cleanup\r
- stdscr.keypad(0)\r
- curses.nocbreak()\r
- curses.echo()\r
- curses.endwin()\r
- sys.exit(1)\r
-\r
-curses.noecho()\r
-#curses.cbreak()\r
-curses.halfdelay(100)\r
-stdscr.keypad(1)\r
-# app goes here\r
-\r
-numboxes = (rows-1)/3\r
-cur_pos = 0\r
-cur_x_pos = 0\r
-barsize = cols-63;\r
-last_refresh = 0\r
-\r
-\r
-exit = False\r
-while not exit:\r
- if time.time() - last_refresh > refresh_interval:\r
- last_refresh = time.time()\r
- apps = get_apps_info()\r
-\r
- stdscr.erase()\r
- for i in xrange(min(numboxes, len(apps)-cur_pos)):\r
- app = apps[cur_pos + i]\r
- attribs = curses.A_NORMAL\r
- stdscr.addstr(3*i+1, 2, app.name, attribs)\r
- stdscr.addstr(3*i+1, 60, app.user+"@"+app.machine, attribs)\r
- stdscr.addstr(3*i+2, 2, app.status[cur_x_pos:], attribs)\r
-\r
- stdscr.hline(3*i+2, 60, curses.ACS_BOARD, barsize)\r
- stdscr.hline(3*i+2, 60, curses.ACS_BLOCK, int((app.progress/100.0)*barsize))\r
-\r
- stdscr.hline(3*(i+1),1,curses.ACS_HLINE, cols-2)\r
-\r
- stdscr.box()\r
- try:\r
- cmd = stdscr.getch()\r
- except:\r
- pass\r
- if cmd == ord('q'):\r
- exit = True\r
- elif cmd == curses.KEY_DOWN:\r
- if cur_pos < len(apps)-numboxes:\r
- cur_pos += 1\r
- elif cmd == curses.KEY_UP:\r
- if cur_pos > 0:\r
- cur_pos -= 1\r
- elif cmd == curses.KEY_RIGHT:\r
- cur_x_pos += 10\r
- elif cmd == curses.KEY_LEFT:\r
- if cur_x_pos > 0:\r
- cur_x_pos -= 10\r
- stdscr.refresh()\r
-\r
-# curses cleanup\r
-stdscr.keypad(0)\r
-curses.nocbreak()\r
-curses.echo()\r
-curses.endwin()\r
-\r
-\r
-\r
+#!/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()
+
+
+