#!/usr/bin/env python
import os, sys, time
import curses,struct
states = ['STARTUP', 'BLOCKED', 'CONNECT', 'PREPROCESS', 'SEND', 'COMPILE', 'RECEIVE', 'DONE']
DISTCC_DIR = os.getenv('DISTCC_DIR') or '%s/.distcc' % os.getenv('HOME')
def getStats(scr):
curses.init_pair(10, curses.COLOR_YELLOW, curses.COLOR_BLACK)
curses.init_pair(11, curses.COLOR_RED, curses.COLOR_BLACK)
curses.init_pair(12, curses.COLOR_GREEN, curses.COLOR_BLACK)
(maxY, maxX) = scr.getmaxyx()
while 1:
try:
scr.addstr(0, 0, time.ctime())
scr.addstr(1, 0, 'System Load: %s' % (str(os.getloadavg())[1:][:-1]))
scr.addstr(3, 0, '%-4s %-20s %-15s %-40s%s' % ('Slot', 'Remote Host', 'State', 'Filename', ' '*(maxX-83)), curses.A_BOLD|curses.A_REVERSE)
cnt = 5
try:
for i in os.listdir(DISTCC_DIR+'/state'):
data = struct.unpack('@iLL128s128siiP', open(DISTCC_DIR+'/state/'+i).readline().strip())
file = data[3].split('\x00')[0] or 'None'
host = data[4].split('\x00')[0] or 'None'
slot = int(data[5])
stte = states[int(data[6])]
if 'None' not in (file, host):
scr.addstr(cnt, 0, '%4d %-20s ' % (slot, host))
if int(data[6]) in (2,3):
scr.addstr(cnt, 26, '%-15s ' % (stte), curses.color_pair(10))
elif int(data[6]) in (0,1):
scr.addstr(cnt, 26, '%-15s ' % (stte), curses.color_pair(11))
elif int(data[6]) in (4,5):
scr.addstr(cnt, 26, '%-15s ' % (stte), curses.color_pair(12))
elif int(data[6]) in (6,7):
scr.addstr(cnt, 26, '%-15s ' % (stte), curses.color_pair(12)|curses.A_BOLD)
else: scr.addstr(cnt, 26, '%-15s ' % (stte))
scr.addstr(cnt, 42, '%-40s%s' % (file, ' '*(maxX-83)))
cnt += 1
except struct.error: pass
except IOError: pass
scr.refresh()
time.sleep(0.75)
scr.erase()
scr.move(0,0)
except KeyboardInterrupt:
sys.exit(-1)
if __name__ == '__main__':
curses.wrapper(getStats)
Diff to Previous Revision
--- revision 1 2011-10-31 18:26:44
+++ revision 2 2011-11-01 01:20:44
@@ -1,37 +1,45 @@
#!/usr/bin/env python
-import os
-import sys
-import time
-import struct
-import curses
+import os, sys, time
+import curses,struct
states = ['STARTUP', 'BLOCKED', 'CONNECT', 'PREPROCESS', 'SEND', 'COMPILE', 'RECEIVE', 'DONE']
-
DISTCC_DIR = os.getenv('DISTCC_DIR') or '%s/.distcc' % os.getenv('HOME')
def getStats(scr):
+ curses.init_pair(10, curses.COLOR_YELLOW, curses.COLOR_BLACK)
+ curses.init_pair(11, curses.COLOR_RED, curses.COLOR_BLACK)
+ curses.init_pair(12, curses.COLOR_GREEN, curses.COLOR_BLACK)
+ (maxY, maxX) = scr.getmaxyx()
while 1:
try:
- scr.addstr(0, 0, 'System Load: %s' % (str(os.getloadavg())[1:][:-1]))
- scr.addstr(1, 0, time.ctime())
- scr.addstr(3, 0, '%-4s %-20s %-15s %-40s' % ('Slot', 'Remote Host', 'State', 'Filename'), curses.A_BOLD|curses.A_REVERSE)
+ scr.addstr(0, 0, time.ctime())
+ scr.addstr(1, 0, 'System Load: %s' % (str(os.getloadavg())[1:][:-1]))
+ scr.addstr(3, 0, '%-4s %-20s %-15s %-40s%s' % ('Slot', 'Remote Host', 'State', 'Filename', ' '*(maxX-83)), curses.A_BOLD|curses.A_REVERSE)
cnt = 5
- for i in os.listdir(DISTCC_DIR+'/state'):
- try:
+ try:
+ for i in os.listdir(DISTCC_DIR+'/state'):
data = struct.unpack('@iLL128s128siiP', open(DISTCC_DIR+'/state/'+i).readline().strip())
file = data[3].split('\x00')[0] or 'None'
host = data[4].split('\x00')[0] or 'None'
slot = int(data[5])
stte = states[int(data[6])]
if 'None' not in (file, host):
- scr.addstr(cnt, 0, '%4d %-20s %-15s %-40s' % (slot, host, stte, file))
+ scr.addstr(cnt, 0, '%4d %-20s ' % (slot, host))
+ if int(data[6]) in (2,3):
+ scr.addstr(cnt, 26, '%-15s ' % (stte), curses.color_pair(10))
+ elif int(data[6]) in (0,1):
+ scr.addstr(cnt, 26, '%-15s ' % (stte), curses.color_pair(11))
+ elif int(data[6]) in (4,5):
+ scr.addstr(cnt, 26, '%-15s ' % (stte), curses.color_pair(12))
+ elif int(data[6]) in (6,7):
+ scr.addstr(cnt, 26, '%-15s ' % (stte), curses.color_pair(12)|curses.A_BOLD)
+ else: scr.addstr(cnt, 26, '%-15s ' % (stte))
+ scr.addstr(cnt, 42, '%-40s%s' % (file, ' '*(maxX-83)))
cnt += 1
- except struct.error, msg:
- pass
- except IOError:
- pass
+ except struct.error: pass
+ except IOError: pass
scr.refresh()
- time.sleep(1)
+ time.sleep(0.75)
scr.erase()
scr.move(0,0)
except KeyboardInterrupt: