Welcome, guest | Sign In | My Account | Store | Cart
#!/usr/bin/env python
import os
import sys
import time
import struct
import curses

states = ['STARTUP', 'BLOCKED', 'CONNECT', 'PREPROCESS', 'SEND', 'COMPILE', 'RECEIVE', 'DONE']

DISTCC_DIR = os.getenv('DISTCC_DIR') or '%s/.distcc' % os.getenv('HOME')

def getStats(scr):
    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)
            cnt = 5
            for i in os.listdir(DISTCC_DIR+'/state'):
                try:
                    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))
                        cnt += 1
                except struct.error, msg:
                    pass
                except IOError:
                    pass
            scr.refresh()
            time.sleep(1)
            scr.erase()
            scr.move(0,0)
        except KeyboardInterrupt:
            sys.exit(-1)

if __name__ == '__main__':
    curses.wrapper(getStats)

History